23 private $fileResults = [];
28 private $generationDirectory;
37 if ($directoryList ===
null) {
38 $directoryList = ObjectManager::getInstance()->get(DirectoryList::class);
40 $this->generationDirectory = $directoryList->getPath(DirectoryList::GENERATION);
51 $this->excludePatterns = array_merge($this->excludePatterns,
$excludePatterns);
65 $realPath = realpath(
$path);
66 $isGeneration = strpos($realPath, $this->generationDirectory) === 0;
69 if (!$isGeneration && isset($this->fileResults[$realPath])) {
70 return $this->fileResults[$realPath];
72 if (!(
bool)$realPath) {
74 new \
Magento\Framework\Phrase(
'The "%1" path is invalid. Verify the path and try again.', [
$path])
77 $recursiveIterator = new \RecursiveIteratorIterator(
78 new \RecursiveDirectoryIterator($realPath, \FilesystemIterator::FOLLOW_SYMLINKS),
79 \RecursiveIteratorIterator::SELF_FIRST
82 $classes = $this->extract($recursiveIterator);
84 $this->fileResults[$realPath] = $classes;
95 private function extract(\RecursiveIteratorIterator $recursiveIterator)
98 foreach ($recursiveIterator as $fileItem) {
100 if ($fileItem->isDir() || $fileItem->getExtension() !==
'php' || $fileItem->getBasename()[0] ==
'.') {
103 $fileItemPath = $fileItem->getRealPath();
109 $fileScanner =
new FileClassScanner($fileItemPath);
110 $classNames = $fileScanner->getClassNames();
111 $this->includeClasses($classNames, $fileItemPath);
112 $classes = array_merge($classes, $classNames);
122 private function includeClasses(array $classNames, $fileItemPath)
126 require_once $fileItemPath;
140 private function isExclude($fileItemPath, $patterns)
142 if (!is_array($patterns)) {
143 $patterns = (array)$patterns;
146 if (preg_match(
$pattern, str_replace(
'\\',
'/', $fileItemPath))) {
__construct(array $excludePatterns=[], DirectoryList $directoryList=null)
addExcludePatterns(array $excludePatterns)