Example #1
0
    /**
     * Retrieves list of classes for given path
     *
     * @param string $path
     * @return array
     * @throws FileSystemException
     */
    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->getExtension() !== 'php') {
                continue;
            }
            foreach ($this->excludePatterns as $excludePattern) {
                if (preg_match($excludePattern, $fileItem->getRealPath())) {
                    continue 2;
                }
            }
            $fileScanner = new FileScanner($fileItem->getRealPath());
            $classNames = $fileScanner->getClassNames();
            foreach ($classNames as $className) {
                if (!class_exists($className)) {
                    require_once $fileItem->getRealPath();
                }
                $classes[] = $className;
            }
        }
        return $classes;
    }
Example #2
0
 /**
  * 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;
             }
         }
     }
 }
Example #3
0
 public function getMapDataForFile($file)
 {
     $file = realpath($file);
     $datas = array();
     $fs = new FileScanner($file);
     // problem in TokenArrayScanner.php line #579, needs fix (notice undefined offset 1)
     @($classes = $fs->getClassNames());
     foreach ($classes as $class) {
         $newNamespace = str_replace('_', '\\', substr($class, 0, strrpos($class, '_')));
         if (strpos($class, '_') !== false) {
             $newClass = substr($class, strrpos($class, '_') + 1);
         } else {
             $newClass = $class;
         }
         $rootDir = $this->findRootDirectory($file, $class);
         if ($newNamespace) {
             $newFile = $rootDir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $newNamespace) . DIRECTORY_SEPARATOR . $newClass . '.php';
         } else {
             $newFile = $file;
         }
         //$root = substr($file, 0, strpos($file, str_replace('\\', DIRECTORY_SEPARATOR, $newNamespace)));
         $data = array('root_directory' => $rootDir, 'original_class' => $class, 'original_file' => $file, 'new_namespace' => $newNamespace, 'new_class' => $newClass, 'new_file' => $newFile);
         // per-file transformations
         $this->transformInterfaceName($data);
         $this->transformAbstractName($data);
         $this->transformReservedWords($data);
         $datas[] = $data;
         // per-set transformationss
     }
     return $datas;
 }
Example #4
0
 /**
  * Retrieves list of classes and arguments for given path
  * [CLASS NAME => ConstructorArgument[]]
  *
  * @param string $path
  * @return array
  * @throws FilesystemException
  */
 public function getList($path)
 {
     $realPath = realpath($path);
     if (!(bool) $realPath) {
         throw new FilesystemException();
     }
     $classes = [];
     $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($realPath, \FilesystemIterator::FOLLOW_SYMLINKS), \RecursiveIteratorIterator::SELF_FIRST);
     /** @var $fileItem \SplFileInfo */
     foreach ($recursiveIterator as $fileItem) {
         if (!$this->isPhpFile($fileItem)) {
             continue;
         }
         $fileScanner = new FileScanner($fileItem->getRealPath());
         $classNames = $fileScanner->getClassNames();
         foreach ($classNames as $className) {
             if (!class_exists($className)) {
                 require_once $fileItem->getRealPath();
             }
             $classes[$className] = $this->classReaderDecorator->getConstructor($className);
         }
     }
     return $classes;
 }
Example #5
0
 /**
  * Determine what classes are present in the cache
  *
  * @return void
  */
 protected function reflectClassCache()
 {
     $scanner = new FileScanner(ZF_CLASS_CACHE);
     $this->knownClasses = array_unique($scanner->getClassNames());
 }
 /**
  * @return array
  */
 public function getClassNames()
 {
     return $this->fileScanner->getClassNames();
 }
 /**
  * Determine what classes are present in the cache
  *
  * @param $classCacheFilename
  * @return void
  */
 protected function reflectClassCache($classCacheFilename)
 {
     $scanner = new FileScanner($classCacheFilename);
     $this->knownClasses = array_unique($scanner->getClassNames());
 }