I. Magento from version 2.0.0 to 2.1.9
- Open & edit file: setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php
- Find function getList($path)
- Replace function by code follow:
public function getList($path) { $realPath = realpath($path); if (!(bool)$realPath) { throw new FileSystemException(new \Magento\Framework\Phrase('Invalid path: %1', [$path])); } $recursiveIterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($realPath, \FilesystemIterator::FOLLOW_SYMLINKS), \RecursiveIteratorIterator::SELF_FIRST ); $classes = []; foreach ($recursiveIterator as $fileItem) { /** @var $fileItem \SplFileInfo */ if ($fileItem->isDir() || $fileItem->getExtension() !== 'php') { continue; } foreach ($this->excludePatterns as $excludePatterns) { if ($this->isExclude($fileItem, $excludePatterns)) { continue 2; } } $fileScanner = new FileScanner($fileItem->getRealPath()); $classNames = $fileScanner->getClassNames(); // start $filePath = str_replace("/", "\\", $fileItem->getRealPath()); if(!count($classNames) && strpos($filePath, "app\code\Mlx") !== false && strpos($filePath, "registration.php") === false){ $classNames[] = str_replace(["app\code\\", ".php"], ["", ""], substr($filePath, strpos($filePath, "app\code\Mlx"))); } //end foreach ($classNames as $className) { if (!class_exists($className)) { require_once $fileItem->getRealPath(); } $classes[] = $className; } } return $classes; }
- Open & edit file: setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php
- Find function getList($path)
- Replace function by code follow:
public function getList($path) { $nameList = []; foreach ($this->classesScanner->getList($path) as $className) { try { if (!strpos($path, 'generation')) { // validate all classes except classes in var/generation dir $this->validator->validate($className); } $nameList[] = $className; } catch (\Magento\Framework\Exception\ValidatorException $exception) { $this->log->add(Log::COMPILATION_ERROR, $className, $exception->getMessage()); } catch (\ReflectionException $e) { $this->log->add(Log::COMPILATION_ERROR, $className, $e->getMessage()); }catch (\Exception $e){ } } $this->log->report(); return $nameList; }
- Run command: php bin/magento setup:di:compile
II. Magento from version 2.2.0 to lastest version
- Open & edit file: setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php
- Find function extract(\RecursiveIteratorIterator $recursiveIterator)
- Replace function by code follow:
private function extract(\RecursiveIteratorIterator $recursiveIterator) { $classes = []; foreach ($recursiveIterator as $fileItem) { /** @var $fileItem \SplFileInfo */ if ($fileItem->isDir() || $fileItem->getExtension() !== 'php' || $fileItem->getBasename()[0] == '.') { continue; } $fileItemPath = $fileItem->getRealPath(); foreach ($this->excludePatterns as $excludePatterns) { if ($this->isExclude($fileItemPath, $excludePatterns)) { continue 2; } } $fileScanner = new FileClassScanner($fileItemPath); $classNames = $fileScanner->getClassNames(); // start $filePath = str_replace("/", "\\", $fileItem->getRealPath()); if(!count($classNames) && strpos($filePath, "app\code\Mlx") !== false && strpos($filePath, "registration.php") === false){ $classNames[] = str_replace(["app\code\\", ".php"], ["", ""], substr($filePath, strpos($filePath, "app\code\Mlx"))); } //end $this->includeClasses($classNames, $fileItemPath); $classes = array_merge($classes, $classNames); } return $classes; }
- Open & edit file: setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php
- Find function getList($path)
- Replace function by code follow:
public function getList($path) { $nameList = []; foreach ($this->classesScanner->getList($path) as $className) { try { // validate all classes except classes in generated/code dir $generatedCodeDir = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_CODE]; if (!strpos($path, $generatedCodeDir[DirectoryList::PATH])) { $this->validator->validate($className); } $nameList[] = $className; } catch (\Magento\Framework\Exception\ValidatorException $exception) { $this->log->add(Log::COMPILATION_ERROR, $className, $exception->getMessage()); } catch (\ReflectionException $e) { $this->log->add(Log::COMPILATION_ERROR, $className, $e->getMessage()); }catch (\Exception $e){ } } //$this->log->report(); return $nameList; }
- Run command: php bin/magento setup:di:compile