Exemplo n.º 1
0
 /**
  * Scans a dir and return the content
  * in it
  *
  * @param  string  $dir
  * @param  boolean $recursive
  * @return array
  */
 public static function scanDir($dir, $recursive = false)
 {
     $tree = array();
     foreach (scandir($dir) as $result) {
         if ($result == '.' || $result == '..') {
             continue;
         }
         $resultPath = PathHelper::getRealPath($dir) . $result;
         if (true == $recursive && is_dir($resultPath)) {
             $tree[] = array('type' => 'dir', 'name' => $result, 'path' => $resultPath, 'content' => self::scanDir($resultPath));
             continue;
         }
         $tree[] = array('type' => is_dir($resultPath) ? 'dir' : 'file', 'name' => $result, 'path' => $resultPath);
     }
     return $tree;
 }