Bolt\Translation\TranslationFile::scanPhpFiles PHP 메소드

scanPhpFiles() 개인적인 메소드

..' and __("..." and add the strings found to the list of translatable strings. All translatables strings have to be called with: __("text", $params=[], $domain='messages', locale=null) // $app['translator']->trans() __("text", count, $params=[], $domain='messages', locale=null) // $app['translator']->transChoice()
private scanPhpFiles ( )
    private function scanPhpFiles()
    {
        $finder = new Finder();
        $finder->files()->ignoreVCS(true)->name('*.php')->notName('*~')->exclude(['cache', 'config', 'database', 'resources', 'tests'])->in($this->app['resources']->getPath('apppath'))->in(__DIR__ . DIRECTORY_SEPARATOR . '..');
        foreach ($finder as $file) {
            /** @var \Symfony\Component\Finder\SplFileInfo $file */
            $tokens = token_get_all($file->getContents());
            $numTokens = count($tokens);
            // Skip whitespace and comments
            $next = function () use(&$x, $tokens, $numTokens) {
                $token = $tokens[++$x];
                while ($x < $numTokens && is_array($token) && ($token[0] == T_WHITESPACE || $token[0] == T_COMMENT)) {
                    $token = $tokens[++$x];
                }
                return $token;
            };
            // Test if token is string, whitespace or comment
            $isArg = function ($token) {
                if (is_array($token)) {
                    if ($token[0] == T_CONSTANT_ENCAPSED_STRING || $token[0] == T_WHITESPACE || $token[0] == T_COMMENT) {
                        return true;
                    }
                } elseif (is_string($token) && $token == '.') {
                    return true;
                }
                return false;
            };
            for ($x = 0; $x < $numTokens; $x++) {
                $token = $tokens[$x];
                // Found function __()
                if (is_array($token) && $token[0] == T_STRING && $token[1] == '__') {
                    // Skip whitespace and comments between "__" and "("
                    $token = $next();
                    // Found "("?
                    if ($x < $numTokens && !is_array($token) && $token == '(') {
                        // Skip whitespace and comments between "__()" and first function argument
                        $token = $next();
                        // Found String?
                        if (is_array($token) && $token[0] == T_CONSTANT_ENCAPSED_STRING) {
                            $string = '';
                            // Get string, also if concatenated
                            while ($x < $numTokens && $isArg($token)) {
                                if (is_array($token) && $token[0] == T_CONSTANT_ENCAPSED_STRING) {
                                    $raw = substr($token[1], 1, strlen($token[1]) - 2);
                                    if (substr($token[1], 0, 1) == '"') {
                                        // Double quoted string
                                        $string .= str_replace('\\"', '"', $raw);
                                    } else {
                                        // Single quoted string
                                        $string .= str_replace('\\\'', '\'', $raw);
                                    }
                                }
                                $token = $tokens[++$x];
                            }
                            $this->addTranslatable($string);
                            //
                            // TODO: retrieve domain?
                        }
                    }
                }
            }
        }
    }