|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
-
-
- class FSTools
- {
-
- private static $singleton;
-
-
-
- public static function singleton()
- {
- if (empty(FSTools::$singleton)) FSTools::$singleton = new FSTools();
- return FSTools::$singleton;
- }
-
-
-
- public static function setSingleton($singleton)
- {
- FSTools::$singleton = $singleton;
- }
-
-
-
- public function mkdirr($folder)
- {
- $folders = preg_split("#[\\\\/]#", $folder);
- $base = '';
- for($i = 0, $c = count($folders); $i < $c; $i++) {
- if(empty($folders[$i])) {
- if (!$i) {
-
- $base .= DIRECTORY_SEPARATOR;
- }
- continue;
- }
- $base .= $folders[$i];
- if(!is_dir($base)){
- $this->mkdir($base);
- }
- $base .= DIRECTORY_SEPARATOR;
- }
- }
-
-
-
- public function copyr($source, $dest)
- {
-
- if (is_file($source)) {
- return $this->copy($source, $dest);
- }
-
- if (!is_dir($dest)) {
- $this->mkdir($dest);
- }
-
- $dir = $this->dir($source);
- while ( false !== ($entry = $dir->read()) ) {
-
- if ($entry == '.' || $entry == '..') {
- continue;
- }
- if (!$this->copyable($entry)) {
- continue;
- }
-
- if ($dest !== "$source/$entry") {
- $this->copyr("$source/$entry", "$dest/$entry");
- }
- }
-
- $dir->close();
- return true;
- }
-
-
-
- public function copyable($file)
- {
- return true;
- }
-
-
-
- public function rmdirr($dirname)
- {
-
- if (!$this->file_exists($dirname)) {
- return false;
- }
-
-
- if ($this->is_file($dirname) || $this->is_link($dirname)) {
- return $this->unlink($dirname);
- }
-
-
- $dir = $this->dir($dirname);
- while (false !== $entry = $dir->read()) {
-
- if ($entry == '.' || $entry == '..') {
- continue;
- }
-
- $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
- }
-
-
- $dir->close();
- return $this->rmdir($dirname);
- }
-
-
-
- public function globr($dir, $pattern, $flags = NULL)
- {
- $files = $this->glob("$dir/$pattern", $flags);
- if ($files === false) $files = array();
- $sub_dirs = $this->glob("$dir/*", GLOB_ONLYDIR);
- if ($sub_dirs === false) $sub_dirs = array();
- foreach ($sub_dirs as $sub_dir) {
- $sub_files = $this->globr($sub_dir, $pattern, $flags);
- $files = array_merge($files, $sub_files);
- }
- return $files;
- }
-
-
-
- public function __call($name, $args)
- {
- return call_user_func_array($name, $args);
- }
-
- }
-
-
|