51 public static function init() {
67 self::$saveCacheFiles =
false;
69 $tmp = self::$searchFiles;
70 self::$searchFiles = array();
71 self::$cacheFiles->get(self::$searchFiles, array(
74 'request'=>array(
'uri'=>
false,
'meth'=>array()),
77 self::$searchFiles = array_merge($tmp, self::$searchFiles);
78 self::$saveCacheFiles =
true;
85 if (!self::$saveCacheFiles) {
86 self::$cacheFiles->save();
87 self::$saveCacheFiles =
true;
97 public static function exists($file) {
109 return file_exists($file);
118 public static function name($file) {
119 return basename($file);
146 throw new nException(
'File - nyroExists : name to search is empty.');
148 $cacheKey = implode(
':', array_filter($prm,
'is_string'));
149 if (!isset(self::$searchFiles[$cacheKey])) {
150 $dir = explode(
',', SEARCHROOT);
152 $nameTmp = $prm[
'realName'] ? $prm[
'name'] : str_replace(
'_',
DS, $prm[
'name']);
155 if ($prm[
'type'] ==
'cfg') {
158 $name[] = $nameTmp.
'.'.$ext.
'.'.EXTPHP;
159 $name[] = $nameTmp.
'.'.$out.
'.'.$ext.
'.'.EXTPHP;
160 $name[] = $nameTmp.
'.'.
request::get(
'lang').
'.'.$ext.
'.'.EXTPHP;
161 $name[] = $nameTmp.
'.'.
request::get(
'lang').
'.'.$out.
'.'.$ext.
'.'.EXTPHP;
162 $name[] = $nameTmp.
'.'.
NYROENV.
'.'.$ext.
'.'.EXTPHP;
163 $name[] = $nameTmp.
'.'.
NYROENV.
'.'.$out.
'.'.$ext.
'.'.EXTPHP;
166 }
else if ($prm[
'type'] ==
'tpl') {
167 $ext = $prm[
'tplExt'] ? $prm[
'tplExt'] :
request::get(
'out');
171 $name[] = $nameTmp.
'.'.
request::get(
'lang').
'.'.$ext.
'.'.EXTPHP;
174 $name[] = $nameTmp.
'.'.
NYROENV.
'.'.$ext.
'.'.EXTPHP;
175 $name[] = $nameTmp.
'.'.
NYROENV.
'.'.$ext;
176 $name[] = $nameTmp.
'.'.
NYROENV.
'.'.EXTPHP;
177 $name[] = $nameTmp.
'.'.$ext.
'.'.EXTPHP;
178 $name[] = $nameTmp.
'.'.$ext;
179 $name[] = $nameTmp.
'.'.EXTPHP;
180 }
else if ($prm[
'type'] ==
'other')
183 $name[] = $nameTmp.
'.'.$prm[
'type'].
'.'.EXTPHP;
186 $dir = array_reverse($dir);
204 foreach($dir as &$d) {
205 foreach($name as &$n) {
206 if (self::exists($file = $d.$n)) {
209 else if (!isset(self::$searchFiles[$cacheKey]))
210 self::$searchFiles[$cacheKey] = $file;
218 self::$searchFiles[$cacheKey] = $ret;
219 else if (!isset(self::$searchFiles[$cacheKey]))
220 self::$searchFiles[$cacheKey] =
false;
221 self::$saveCacheFiles =
false;
223 return self::$searchFiles[$cacheKey];
233 return self::exists(WEBROOT.DS.$file);
242 public static function read($file) {
243 if (self::exists($file))
244 return file_get_contents($file);
256 public static function write($file, $content) {
257 self::createDir(pathinfo($file, PATHINFO_DIRNAME));
258 return (file_put_contents($file, $content) === self::size($file));
268 public static function copy($oldName, $newName) {
269 return copy($oldName, $newName);
279 public static function move($oldName, $newName) {
280 return rename($oldName, $newName);
293 return is_dir($path) || mkdir($path, $chmod,
true);
302 public static function date($file) {
304 return filemtime($file);
314 public static function isLater($file1, $file2) {
316 return (filemtime($file1) > filemtime($file2));
325 public static function size($file) {
327 if (self::exists($file))
328 return filesize($file);
339 public static function humanSize($file, $sizeGiven =
false) {
340 $size = $sizeGiven ? $file : self::size($file);
342 $units = explode(
' ',
'B KB MB GB TB PB');
343 for ($i = 0; $size > $mod; $i++) {
346 return round($size, 2).
' '.$units[$i];
355 public static function delete($file) {
356 if (self::exists($file)) {
358 self::multipleDelete($file.
'/*');
363 if (self::exists($file)) {
364 $filesys = str_replace(
"/",
"\\", $file);
365 @system(
"del $filesys");
367 if (self::exists($file)) {
370 @system(
"del $filesys");
376 return !self::exists($file);
388 foreach(self::search($pattern, $matchPattern) as
$f)
389 if (self::delete($f))
401 $ext = pathinfo($file, PATHINFO_EXTENSION);
403 $ext = substr($file, strrpos($file,
'.') + 1);
415 $ret = self::$cfg->getInArray(
'mimes', strtolower(self::getExt($file)));
417 $ret = self::$cfg->getInArray(
'mimes',
'unknown');
422 if (self::exists($file)) {
423 $finfo =
new finfo(FILEINFO_MIME);
425 $ret = $finfo->file($filename);
428 $ret = mime_content_type($file);
441 public static function fetch($file, array $vars = array()) {
442 extract($vars, EXTR_REFS OR EXTR_OVERWRITE);
445 $contents = ob_get_contents();
457 public static function search($pattern, $matchPattern = null) {
458 $ret = glob($pattern);
459 if (!is_null($matchPattern)) {
461 foreach($ret as $r) {
462 if (preg_match($matchPattern, $r))
static getInstance(array $cfg=array())
if(!defined('NYROROOT')) define('NYROROOT' ROOT DS
static move($oldName, $newName)
static humanSize($file, $sizeGiven=false)
static initTab(array &$vars, array $init)
static copy($oldName, $newName)
static loadCfg($className, $searchParent=true)
static fetch($file, array $vars=array())
static createDir($path, $chmod=0777)
static write($file, $content)
static multipleDelete($pattern, $matchPattern=null)
static isLater($file1, $file2)
static search($pattern, $matchPattern=null)