Exemple #1
0
 protected function getRepo($repoFullName = 'KnpLabs/KnpGaufretteBundle')
 {
     $dir = sys_get_temp_dir() . '/kb_git_repos';
     $manager = new RepoManager($dir, $_SERVER['GIT_BIN']);
     $repo = new Bundle($repoFullName);
     $gitRepo = $manager->getRepo($repo);
     return $gitRepo;
 }
Exemple #2
0
    public function updateCanonicalConfigFile(Bundle $bundle)
    {
        self::$canonicalConfiguration = '';
        $gitRepo = $this->gitRepoManager->getRepo($bundle);
        /**
         * Currently there is only support for bundles whose configuration is stored exactly under Configuration.php
         */
        $relativePath = 'DependencyInjection' . DIRECTORY_SEPARATOR . 'Configuration.php';
        if ($gitRepo->hasFile($relativePath)) {
            $absolutePath = $gitRepo->getDir() . DIRECTORY_SEPARATOR . $relativePath;
            $tokens = token_get_all(file_get_contents($absolutePath));
            $start = false;
            $namespace = '';
            foreach ($tokens as $token) {
                if ($token == ';') {
                    break;
                }
                $tokenName = is_array($token) ? $token[0] : null;
                if (T_NAMESPACE === $tokenName) {
                    $start = true;
                    continue;
                }
                // Still not found namespace, skip this part of code
                if ($start === false) {
                    continue;
                }
                $tokenData = is_array($token) ? $token[1] : $token;
                if ($tokenData == ' ') {
                    continue;
                }
                $namespace .= $tokenData;
            }
            unset($tokens);
            $autoloaderPath = __DIR__ . '/../../../../../vendor/autoload.php';
            $script = <<<EOF
<?php

include_once "{$autoloaderPath}";
include_once "{$absolutePath}";

use Knp\\Bundle\\KnpBundlesBundle\\Github\\Repo;

\$configuration = new \\ReflectionClass("{$namespace}\\Configuration");
// only dumps if it implements interface ConfigurationInterface
if (in_array('Symfony\\Component\\Config\\Definition\\ConfigurationInterface', \$configuration->getInterfaceNames())) {
    \$configuration = \$configuration->newInstance();
    \$configuration = Repo::outputNode(\$configuration->getConfigTreeBuilder()->buildTree());

    echo Repo::\$canonicalConfiguration;
} else {
    echo '';
}

?>
EOF;
            // Workaround for bundles with external deps called in DI configuration, i.e. FOSRestBundle
            $process = new PhpProcess($script);
            $process->run();
            if ($process->isSuccessful()) {
                $bundle->setCanonicalConfig(Repo::$canonicalConfiguration = $process->getOutput());
            }
        }
    }