protected function collectInfo($name, $extension, array &$info) { parent::collectInfo($name, $extension, $info); if (null !== $this->itemDir) { if (is_dir($this->itemDir)) { DirScanner::create()->scanDir($this->itemDir, function ($path, $rPath, $level) use($extension, &$info) { $ext = strtolower(FileSystemTool::getFileExtension($path)); if ($extension === $ext) { // info[src] is an url if (null !== $this->webRoot) { $info['src'] = str_replace($this->webRoot, '', $path); } else { $info['src'] = $path; } $this->onCollectInfoAfter($path, $rPath, $extension, $level, $info); } }); } else { // if the dir doesn't exist yet, it's not a problem: we collect nothing } } else { throw new ColisException("itemDir is not set"); } }
/** * @return array of use statements' class names inside the given directory */ public static function getUseDependenciesByFolder($dir) { $ret = []; DirScanner::create()->scanDir($dir, function ($path, $rPath, $level) use(&$ret) { if (is_file($path) && 'php' === strtolower(FileSystemTool::getFileExtension($path))) { $tokens = token_get_all(file_get_contents($path)); $ret = array_merge($ret, TokenFinderTool::getUseDependencies($tokens)); } }); $ret = array_unique($ret); sort($ret); return $ret; }