Knp\Bundle\KnpBundlesBundle\Updater\Updater::createMissingBundles PHP Method

createMissingBundles() public method

public createMissingBundles ( array $foundBundles )
$foundBundles array
    public function createMissingBundles(array $foundBundles)
    {
        $added = 0;
        /* @var $bundle Bundle */
        foreach ($foundBundles as $fullName) {
            $bundle = $this->bundleManager->createBundle($fullName);
            // It's not a valid Symfony2 Bundle or failed with our requirements (i.e: is a fork with less then 10 watchers)
            if (!$bundle) {
                $this->notifyInvalid($fullName, 'Bundle is not an valid Symfony2 Bundle or failed with our requirements, or we were not able to get such via API.');
                continue;
            }
            $this->output->write(sprintf('[%s] Discover bundle <comment>%s</comment>: ', date('d-m-y H:i:s'), $bundle->getFullName()));
            try {
                $this->githubRepoApi->updateFiles($bundle);
            } catch (\RuntimeException $e) {
                $this->output->writeln(sprintf(' <error>%s</error>', $e->getMessage()));
                continue;
            }
            $this->em->persist($bundle);
            $this->updateRepo($bundle);
            $this->output->writeln(' ADDED');
            ++$added;
        }
        $this->em->flush();
        if ($added) {
            $this->output->writeln(sprintf('[%s] Created <comment>%d</comment> new bundles', date('d-m-y H:i:s'), $added));
        }
    }

Usage Example

 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $gitRepoDir = $this->getContainer()->getParameter('knp_bundles.bundles_dir');
     $gitBin = $this->getContainer()->getParameter('knp_bundles.git_bin');
     $em = $this->getContainer()->get('knp_bundles.entity_manager');
     $updater = new Updater($em, $gitRepoDir, $gitBin, $output);
     $updater->setUp();
     $bundles = $updater->searchNewBundles((int) $input->getOption('limit'));
     $updater->createMissingBundles($bundles);
     $em->flush();
 }