/**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dest = $input->getOption('dest');
     if ($dest) {
         $dest = realpath($dest);
     } else {
         $dest = $this->getContainer()->get('kernel')->getRootDir() . '/../src';
     }
     $configuration = array('application_dir' => sprintf("%s/Application", $dest));
     $bundleName = 'NetworkingInitCmsBundle';
     if ($bundleName == false) {
         $output->writeln('');
         $output->writeln('<error>You must provide a bundle name!</error>');
         $output->writeln('');
         $output->writeln('  Bundles availables :');
         foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
             $bundleMetadata = new BundleMetadata($bundle, $configuration);
             if (!$bundleMetadata->isExtendable()) {
                 continue;
             }
             $output->writeln(sprintf('     - %s', $bundle->getName()));
         }
         $output->writeln('');
         return 0;
     }
     $processed = false;
     foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
         if ($bundle->getName() != $bundleName) {
             continue;
         }
         $processed = true;
         $bundleMetadata = new BundleMetadata($bundle, $configuration);
         // generate the bundle file
         if (!$bundleMetadata->isExtendable()) {
             $output->writeln(sprintf('Ignoring bundle : "<comment>%s</comment>"', $bundleMetadata->getClass()));
             continue;
         }
         // generate the bundle file
         if (!$bundleMetadata->isValid()) {
             $output->writeln(sprintf('%s : <comment>wrong folder structure</comment>', $bundleMetadata->getClass()));
             continue;
         }
         $output->writeln(sprintf('Processing bundle : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.bundle')->generate($output, $bundleMetadata);
         $dir = sprintf('%s/%s', $bundleMetadata->getExtendedDirectory(), 'Resources/config/serializer');
         if (!is_dir($dir)) {
             $output->writeln(sprintf('  > generating bundle directory <comment>%s</comment>', $dir));
             mkdir($dir, 0755, true);
         }
         $output->writeln(sprintf('Processing Doctrine ORM : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.orm')->generate($output, $bundleMetadata);
         $output->writeln(sprintf('Processing Doctrine ODM : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.odm')->generate($output, $bundleMetadata);
         $this->setConfigFolders($bundleMetadata);
         $output->writeln(sprintf('Processing Config files : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->generateConfigFiles($output, $bundleMetadata);
         $output->writeln(sprintf('Processing Serializer files : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->generateSerializerFiles($output, $bundleMetadata);
         $output->writeln('');
     }
     if ($processed) {
         $output->writeln('done!');
         return 0;
     }
     $output->writeln(sprintf('<error>The bundle \'%s\' does not exist or not defined in the kernel file!</error>', $bundleName));
     return -1;
 }
Esempio n. 2
0
 /**
  * Generates a bundle entities from a bundle name.
  *
  * @param string          $bundleName
  * @param array           $configuration
  * @param OutputInterface $output
  *
  * @return bool
  */
 protected function generate($bundleName, array $configuration, $output)
 {
     $processed = false;
     foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
         if ($bundle->getName() != $bundleName) {
             continue;
         }
         $processed = true;
         $bundleMetadata = new BundleMetadata($bundle, $configuration);
         // generate the bundle file
         if (!$bundleMetadata->isExtendable()) {
             $output->writeln(sprintf('Ignoring bundle : "<comment>%s</comment>"', $bundleMetadata->getClass()));
             continue;
         }
         // generate the bundle file
         if (!$bundleMetadata->isValid()) {
             $output->writeln(sprintf('%s : <comment>wrong folder structure</comment>', $bundleMetadata->getClass()));
             continue;
         }
         $output->writeln(sprintf('Processing bundle : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.bundle')->generate($output, $bundleMetadata);
         $output->writeln(sprintf('Processing Doctrine ORM : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.orm')->generate($output, $bundleMetadata);
         $output->writeln(sprintf('Processing Doctrine ODM : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.odm')->generate($output, $bundleMetadata);
         $output->writeln(sprintf('Processing Doctrine PHPCR : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.phpcr')->generate($output, $bundleMetadata);
         $output->writeln(sprintf('Processing Serializer config : "<info>%s</info>"', $bundleMetadata->getName()));
         $this->getContainer()->get('sonata.easy_extends.generator.serializer')->generate($output, $bundleMetadata);
         $output->writeln('');
     }
     return $processed;
 }