ClassFinder.php
public function find(): self
    {
        $preparedPaths = \array_unique(
            \array_merge(
                $this->getPreparedPaths((array) $this->paths['psr0']),
                $this->getPreparedPaths((array) $this->paths['psr4']),
                $this->getPreparedPaths((array) $this->paths['classmap'])
            ),
            \SORT_STRING
        );

        $finder = Finder::create()
            ->files()
            ->in($preparedPaths)
            ->exclude($this->excludes)
            ->name('*.php')
            ->sortByName();

        if ($this->filter !== null) {
            $finder->filter($this->filter);
        }

        /** @var \SplFileInfo $file */
        foreach ($finder as $file) {
            $realPath  = (string) $file->getRealPath();

            $namespace = null;
            $tokens    = \token_get_all((string) \file_get_contents($realPath));

            foreach ($tokens as $key => $token) {
                if (\is_array($token)) {
                    if ($token[0] === \T_NAMESPACE) {
                        $namespace = self::getNamespace($key + 2, $tokens);
                    } elseif ($token[0] === \T_INTERFACE) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->interfaces[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_TRAIT) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->traits[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_ABSTRACT) {
                        $name = self::getName($key + 4, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->abstractClasses[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;

                        continue 2;
                    } elseif ($token[0] === \T_CLASS) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->classes[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    }
                }
            }

            unset($tokens);
            // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
            \gc_mem_caches();
        }

        return $this;
    }
public function find(): self
    {
        $preparedPaths = \array_unique(
            \array_merge(
                $this->getPreparedPaths((array) $this->paths['psr0']),
                $this->getPreparedPaths((array) $this->paths['psr4']),
                $this->getPreparedPaths((array) $this->paths['classmap'])
            ),
            \SORT_STRING
        );

        $finder = Finder::create()
            ->files()
            ->in($preparedPaths)
            ->exclude($this->excludes)
            ->name('*.php')
            ->sortByName();

        if ($this->filter !== null) {
            $finder->filter($this->filter);
        }

        /** @var \SplFileInfo $file */
        foreach ($finder as $file) {
            $realPath  = (string) $file->getRealPath();

            $namespace = null;
            $tokens    = \token_get_all((string) \file_get_contents($realPath));

            foreach ($tokens as $key => $token) {
                if (\is_array($token)) {
                    if ($token[0] === \T_NAMESPACE) {
                        $namespace = self::getNamespace($key + 2, $tokens);
                    } elseif ($token[0] === \T_INTERFACE) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->interfaces[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_TRAIT) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->traits[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_ABSTRACT) {
                        $name = self::getName($key + 4, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->abstractClasses[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;

                        continue 2;
                    } elseif ($token[0] === \T_CLASS) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->classes[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    }
                }
            }

            unset($tokens);
            // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
            \gc_mem_caches();
        }

        return $this;
    }
public function find ( ) : self { $ preparedPaths = \ array_unique ( \ array_merge ( $ this -> getPreparedPaths ( ( array ) $ this -> paths [ 'psr0' ] ) , $ this -> getPreparedPaths ( ( array ) $ this -> paths [ 'psr4' ] ) , $ this -> getPreparedPaths ( ( array ) $ this -> paths [ 'classmap' ] ) ) , \ SORT_STRING ) ; $ finder = Finder :: create ( ) -> files ( ) -> in ( $ preparedPaths ) -> exclude ( $ this -> excludes ) -> name ( '*.php' ) -> sortByName ( ) ; if ( $ this -> filter !== null ) { $ finder -> filter ( $ this -> filter ) ; } /** @var \SplFileInfo $file */ foreach ( $ finder as $ file ) { $ realPath = ( string ) $ file -> getRealPath ( ) ; $ namespace = null ; $ tokens = \ token_get_all ( ( string ) \ file_get_contents ( $ realPath ) ) ; foreach ( $ tokens as $ key => $ token ) { if ( \ is_array ( $ token ) ) { if ( $ token [ 0 ] === \ T_NAMESPACE ) { $ namespace = self :: getNamespace ( $ key + 2 , $ tokens ) ; } elseif ( $ token [ 0 ] === \ T_INTERFACE ) { $ name = self :: getName ( $ key + 2 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> interfaces [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; } elseif ( $ token [ 0 ] === \ T_TRAIT ) { $ name = self :: getName ( $ key + 2 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> traits [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; } elseif ( $ token [ 0 ] === \ T_ABSTRACT ) { $ name = self :: getName ( $ key + 4 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> abstractClasses [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; continue 2 ; } elseif ( $ token [ 0 ] === \ T_CLASS ) { $ name = self :: getName ( $ key + 2 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> classes [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; } } } unset ( $ tokens ) ; // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 \ gc_mem_caches ( ) ; } return $ this ; }
Find all the class, traits and interface names in a given directory.

@return \Narrowspark\Automatic\Common\ClassFinder
Find all the class traits and interface names in a given directory .