/** * Compile class definitions * * @param string $path * @param bool $validate * @return void */ public function compile($path, $validate = true) { $rdi = new \RecursiveDirectoryIterator(realpath($path)); $recursiveIterator = new \RecursiveIteratorIterator($rdi, 1); /** @var $item \SplFileInfo */ foreach ($recursiveIterator as $item) { if ($item->isFile() && pathinfo($item->getRealPath(), PATHINFO_EXTENSION) == 'php') { $fileScanner = new FileScanner($item->getRealPath()); $classNames = $fileScanner->getClassNames(); foreach ($classNames as $className) { $this->_current = $className; if (!class_exists($className)) { require_once $item->getRealPath(); } try { if ($validate) { $this->_validator->validate($className); } $signatureReader = new \Magento\Framework\Code\Reader\ClassReader(); $this->_definitions[$className] = $signatureReader->getConstructor($className); $this->_relations[$className] = $signatureReader->getParents($className); } catch (\Magento\Framework\Code\ValidationException $exception) { $this->_log->add(Log::COMPILATION_ERROR, $className, $exception->getMessage()); } catch (\ReflectionException $e) { $this->_log->add(Log::COMPILATION_ERROR, $className, $e->getMessage()); } $this->_processedClasses[$className] = 1; } } } }
public function testValidate() { $className = 'Same\\Class\\Name'; $validator1 = $this->getMock('Magento\\Framework\\Code\\ValidatorInterface'); $validator1->expects($this->once())->method('validate')->with($className); $validator2 = $this->getMock('Magento\\Framework\\Code\\ValidatorInterface'); $validator2->expects($this->once())->method('validate')->with($className); $this->model->add($validator1); $this->model->add($validator2); $this->model->validate($className); }
/** * Retrieves list of classes for given path * * @param string $path path to dir with files * * @return array */ public function getList($path) { foreach ($this->classesScanner->getList($path) as $className) { $this->current = $className; // for errorHandler function try { if ($path != $this->generationDir) { // validate all classes except classes in generation dir $this->validator->validate($className); } $this->relations[$className] = $this->classReader->getParents($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()); } } return $this->relations; }
/** * Validate class * * @param string $className */ protected function _validateClass($className) { try { $this->_validator->validate($className); } catch (\Magento\Framework\Code\ValidationException $exceptions) { $this->fail($exceptions->getMessage()); } catch (\ReflectionException $exceptions) { $this->fail($exceptions->getMessage()); } }
/** * Retrieves list of classes for given path * * @param string $path path to dir with files * * @return array */ 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\Code\ValidationException $exception) { $this->log->add(Log::COMPILATION_ERROR, $className, $exception->getMessage()); } catch (\ReflectionException $e) { $this->log->add(Log::COMPILATION_ERROR, $className, $e->getMessage()); } } $this->log->report(); return $nameList; }