Пример #1
0
 public static function build($directory)
 {
     $list = array();
     $unique = array();
     // Build
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::KEY_AS_PATHNAME), RecursiveIteratorIterator::SELF_FIRST);
     while ($it->valid()) {
         $key = $it->key();
         // Make sure it's unique, Skip .svn files
         if (isset($unique[$key]) || stripos($key, '.svn') !== false) {
             $it->next();
             continue;
         }
         $unique[$key] = true;
         // Add
         $subpath = $it->getSubPathName();
         // Skip dot files, package files and .svn or CVS folders
         if (!$it->isDot() && substr(basename($subpath), 0, strrpos(basename($subpath), '.')) != 'package' && basename($subpath) != '.svn' && basename($subpath) != 'CVS') {
             $key = $it->key();
             //$list[$it->getSubPathName()] = array(
             $list[] = array('path' => self::fix_path($it->getSubPathName()), 'dir' => $it->isDir(), 'file' => $it->isFile(), 'perms' => substr(sprintf('%o', $it->getPerms()), -4), 'size' => $it->getSize(), 'sha1' => $it->isFile() ? sha1_file($key) : null);
         }
         $it->next();
     }
     ksort($list);
     return $list;
 }
 /**
  * Copy directory
  *
  * @param string $source            
  * @param string $dest            
  */
 private function copyDir(string $source, string $dest)
 {
     $dir_iterator = new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS);
     $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $item) {
         if ($item->isDir()) {
             mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), octdec(str_pad($iterator->getPerms(), 4, 0, STR_PAD_LEFT)));
         } else {
             $this->copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
         }
     }
     return true;
 }