/** * Updates bundle keywords fetched from composer.json * * @param Bundle $bundle * @param object $repository */ private function updateKeywords(Bundle $bundle, $repository) { $keywords = $this->githubRepoApi->fetchComposerKeywords($bundle); foreach ($keywords as $value) { $keyword = $repository->findOneBy(array('value' => $value)); if (!$keyword) { $keyword = new Keyword(); $keyword->setValue($value); } $bundle->addKeyword($keyword); } }
/** * @param string $name * @param string $ownerName * * @return boolean|Bundle return false if the bundle is not valid */ private function createFullBundle($name, $ownerName) { $bundle = $this->createEmptyBundle($name); $bundle->setOwnerName($ownerName); if (!$this->repoApi->validate($bundle)) { return false; } if (!$this->repoApi->updateInfos($bundle)) { return false; } $owner = $this->ownerManager->createOwner($ownerName, 'unknown', false); if (!$owner) { return false; } $owner->addBundle($bundle); return $bundle; }
public function removeNonSymfonyBundles() { $counter = 0; $page = 1; $pager = $this->paginateExistingBundles($page); $this->output->writeln(sprintf('[%s] Will now check <comment>%d</comment> bundles', date('d-m-y H:i:s'), $pager->getNbResults())); do { /** @var $bundle Bundle */ foreach ($pager->getCurrentPageResults() as $bundle) { if (!$this->githubRepoApi->validate($bundle)) { $this->notifyInvalid($bundle->getFullName(), sprintf('File "%sBundle.php" with base class was not found.', ucfirst($bundle->getFullName()))); if (!$this->removeRepo($bundle)) { $bundle->getOwner()->removeBundle($bundle); $this->em->remove($bundle); } ++$counter; } } ++$page; } while ($pager->hasNextPage() && $pager->setCurrentPage($page, false, true)); $this->output->writeln(sprintf('[%s] <comment>%s</comment> invalid bundles have been found and removed', date('d-m-y H:i:s'), $counter)); $this->em->flush(); }
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()); } } }