/**
  * {@inheritdoc}
  */
 protected function doExecute()
 {
     $this->assistant->writeSection('Site generation');
     $this->assistant->writeLine(array("This command helps you to generate a default site setup.\n"));
     /**
      * Ask for which bundle we need to create the layout
      */
     $bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null);
     $this->bundle = $this->askForBundleName('layout', $bundleNamespace);
     /**
      * Ask the database table prefix
      */
     $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
     /**
      * If we need to generate a full site, or only the basic structure
      */
     $this->demosite = $this->assistant->getOption('demosite');
     // First we generate the layout if it is not yet generated
     if (!is_file($this->bundle->getPath() . '/Resources/views/Layout/layout.html.twig')) {
         $command = $this->getApplication()->find('kuma:generate:layout');
         $arguments = array('command' => 'kuma:generate:layout', '--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()), '--subcommand' => true);
         $input = new ArrayInput($arguments);
         $command->run($input, $this->assistant->getOutput());
     }
     $rootDir = $this->getApplication()->getKernel()->getRootDir() . '/../';
     $this->createGenerator()->generate($this->bundle, $this->prefix, $rootDir, $this->demosite);
     $this->assistant->writeSection('Site successfully created', 'bg=green;fg=black');
 }
 /**
  * {@inheritdoc}
  */
 protected function doExecute()
 {
     $this->assistant->writeSection('Site generation');
     $this->assistant->writeLine(array("This command helps you to generate a default site setup.\n"));
     /**
      * Ask for which bundle we need to create the layout
      */
     $bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null);
     $this->bundle = $this->askForBundleName('layout', $bundleNamespace);
     /**
      * Ask the database table prefix
      */
     $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
     /**
      * If we need to generate a full site, or only the basic structure
      */
     $this->demosite = $this->assistant->getOption('demosite');
     // First we generate the layout if it is not yet generated
     $command = $this->getApplication()->find('kuma:generate:layout');
     $arguments = array('command' => 'kuma:generate:layout', '--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()), '--demosite' => $this->demosite, '--subcommand' => true);
     $input = new ArrayInput($arguments);
     $command->run($input, $this->assistant->getOutput());
     $rootDir = $this->getApplication()->getKernel()->getRootDir() . '/../';
     $this->createGenerator()->generate($this->bundle, $this->prefix, $rootDir, $this->demosite);
     // Generate the default pageparts
     $command = $this->getApplication()->find('kuma:generate:default-pageparts');
     $arguments = array('command' => 'kuma:generate:default-pageparts', '--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()), '--prefix' => $this->prefix, '--contexts' => 'main', '--quiet' => true);
     $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET);
     $input = new ArrayInput($arguments);
     $command->run($input, $output);
     $this->assistant->writeLine('Generating default pageparts : <info>OK</info>');
     if ($this->demosite) {
         // Generate a blog
         $command = $this->getApplication()->find('kuma:generate:article');
         $arguments = array('command' => 'kuma:generate:article', '--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()), '--prefix' => $this->prefix, '--entity' => 'Blog', '--dummydata' => true, '--quiet' => true);
         $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET);
         $input = new ArrayInput($arguments);
         $command->run($input, $output);
         $this->assistant->writeLine('Generating blog : <info>OK</info>');
     }
     $this->assistant->writeSection('Site successfully created', 'bg=green;fg=black');
 }
 /**
  * {@inheritdoc}
  */
 protected function doInteract()
 {
     if (!$this->isBundleAvailable('KunstmaanPagePartBundle')) {
         $this->assistant->writeError('KunstmaanPagePartBundle not found', true);
     }
     $this->assistant->writeLine(array("This command helps you to generate a new pagepart.\n"));
     /**
      * Ask for which bundle we need to create the pagepart
      */
     $bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null);
     $this->bundle = $this->askForBundleName('pagepart', $bundleNamespace);
     /**
      * Ask the database table prefix
      */
     $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
     /**
      * Ask for which page sections we should enable this pagepart
      */
     $contexts = $this->assistant->getOptionOrDefault('contexts', null);
     if ($contexts) {
         $contexts = explode(',', $contexts);
         array_walk($contexts, 'trim');
         $this->sections = array();
         $allSections = $this->getAvailableSections($this->bundle);
         foreach ($allSections as $section) {
             if (in_array($section['context'], $contexts)) {
                 $this->sections[] = $section['file'];
             }
         }
     } else {
         $question = 'In which page section configuration file(s) do you want to add the pageparts (multiple possible, separated by comma)';
         $this->sections = $this->askForSections($question, $this->bundle, true);
     }
     /**
      * Check that we can create behat tests for the default pagepart
      */
     $this->behatTest = count($this->sections) > 0 && $this->canGenerateBehatTests($this->bundle);
 }
 /**
  * @param QuestionHelper $question
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param BundleInterface $bundle
  * @param $metadata
  * @param $entity
  * @param $filename
  */
 protected function generateAdmin(QuestionHelper $question, InputInterface $input, OutputInterface $output, BundleInterface $bundle, $metadata, $entity, $filename)
 {
     $auto = true;
     if ($input->isInteractive()) {
         $auto = $question->ask($input, $output, new ConfirmationQuestion('Confirm automatic generation of the Admin service?', false));
     }
     if ($auto) {
         $group = ucfirst(str_replace('_', ' ', Container::underscore(substr($bundle->getName(), 0, -6))));
         $label = $entity;
         $translationDomain = 'Sonata';
         $groupQuestion = new Question('Group for the admin service: ', $group);
         $groupQuestion->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'));
         $groupQuestion->setAutocompleterValues([$group]);
         $group = $question->ask($input, $output, $groupQuestion);
         $labelQuestion = new Question('Label for the admin service: ', $label);
         $labelQuestion->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'));
         $labelQuestion->setAutocompleterValues([$label]);
         $label = $question->ask($input, $output, $labelQuestion);
         $translationDomainQuestion = new Question('Translation domain for the admin service: ', $translationDomain);
         $translationDomainQuestion->setAutocompleterValues([$translationDomain]);
         $translationDomain = $question->ask($input, $output, $labelQuestion);
         $output->write('Creating the service: ');
         $this->getContainer()->get('filesystem')->mkdir($bundle->getPath() . '/Resources/config/');
         $admin = new AdminManipulator($bundle->getPath() . '/Resources/config/' . $filename);
         try {
             $ret = $auto ? $admin->addResource($bundle, $entity, $group, $label, $translationDomain) : false;
         } catch (\RuntimeException $exc) {
             $ret = false;
         }
         if ($ret) {
             $output->write('Creating the Admin class: ');
             $generator = $this->getGenerator($bundle);
             $generator->generateAdminClass($metadata[0], $input->getOption('overwrite'));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doInteract()
 {
     if (!$this->isBundleAvailable('KunstmaanPagePartBundle')) {
         $this->assistant->writeError('KunstmaanPagePartBundle not found', true);
     }
     $this->assistant->writeLine(array("This command helps you to generate a new pagepart.\n"));
     /**
      * Ask for which bundle we need to create the pagepart
      */
     $this->bundle = $this->askForBundleName('pagepart');
     /**
      * Ask the database table prefix
      */
     $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
     /**
      * Ask the name of the pagepart
      */
     $this->assistant->writeLine(array('', 'The name of your PagePart: For example: <comment>ContentBoxPagePart</comment>', ''));
     $self = $this;
     $generator = $this->getGenerator();
     $bundlePath = $self->bundle->getPath();
     $name = $this->assistant->askAndValidate('PagePart name', function ($name) use($self, $generator, $bundlePath) {
         // Check reserved words
         if ($generator->isReservedKeyword($name)) {
             throw new \InvalidArgumentException(sprintf('"%s" is a reserved word', $name));
         }
         // Name should end on PagePart
         if (!preg_match('/PagePart$/', $name)) {
             throw new \InvalidArgumentException('The pagepart name must end with PagePart');
         }
         // Name should contain more characters than PagePart
         if (strlen($name) <= strlen('PagePart') || !preg_match('/^[a-zA-Z]+$/', $name)) {
             throw new \InvalidArgumentException('Invalid pagepart name');
         }
         // Check that entity does not already exist
         if (file_exists($bundlePath . '/Entity/PageParts/' . $name . '.php')) {
             throw new \InvalidArgumentException(sprintf('PagePart or entity "%s" already exists', $name));
         }
         return $name;
     });
     $this->pagepartName = $name;
     /**
      * Ask which fields need to be present
      */
     $this->assistant->writeLine(array("\nInstead of starting with a blank pagepart, you can add some fields now.\n"));
     $fields = $this->askEntityFields($this->bundle);
     $this->fields = array();
     foreach ($fields as $fieldInfo) {
         if ($fieldInfo['type'] == 'image') {
             $this->fields[] = $this->getEntityFields($this->bundle, $this->pagepartName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'], $fieldInfo['extra'], true, $fieldInfo['minHeight'], $fieldInfo['maxHeight'], $fieldInfo['minWidth'], $fieldInfo['maxWidth'], $fieldInfo['mimeTypes']);
         } elseif ($fieldInfo['type'] == 'media') {
             $this->fields[] = $this->getEntityFields($this->bundle, $this->pagepartName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'], $fieldInfo['extra'], true, null, null, null, null, $fieldInfo['mimeTypes']);
         } else {
             $this->fields[] = $this->getEntityFields($this->bundle, $this->pagepartName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'], $fieldInfo['extra'], true);
         }
     }
     /**
      * Ask for which page sections we should enable this pagepart
      */
     $question = 'In which page section configuration file(s) do you want to add the pagepart (multiple possible, separated by comma)';
     $this->sections = $this->askForSections($question, $this->bundle, true);
     /**
      * Ask that you want to create behat tests for the new pagepart, if possible
      */
     if (count($this->sections) > 0 && $this->canGenerateBehatTests($this->bundle)) {
         $this->behatTest = $this->assistant->askConfirmation('Do you want to generate behat tests for this pagepart? (y/n)', 'y');
     } else {
         $this->behatTest = false;
     }
 }
Ejemplo n.º 6
0
Archivo: Di.php Proyecto: mattferris/di
 /**
  * @param BundleInterface $bundle
  */
 public function register(BundleInterface $bundle)
 {
     $bundle->register($this);
 }
 /**
  * {@inheritdoc}
  */
 protected function doInteract()
 {
     if (!$this->isBundleAvailable('KunstmaanPagePartBundle')) {
         $this->assistant->writeError('KunstmaanPagePartBundle not found', true);
     }
     $this->assistant->writeLine(array("This command helps you to generate a new page.\n"));
     /**
      * Ask for which bundle we need to create the pagepart
      */
     $this->bundle = $this->askForBundleName('page');
     /**
      * Ask the database table prefix
      */
     $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
     /**
      * Ask the name of the pagepart
      */
     $this->assistant->writeLine(array('', 'The name of your Page: For example: <comment>SponsorPage</comment>, <comment>NewsOverviewPage</comment>', ''));
     $self = $this;
     $generator = $this->getGenerator();
     $bundlePath = $self->bundle->getPath();
     $name = $this->assistant->askAndValidate('Page name', function ($name) use($self, $generator, $bundlePath) {
         // Check reserved words
         if ($generator->isReservedKeyword($name)) {
             throw new \InvalidArgumentException(sprintf('"%s" is a reserved word', $name));
         }
         // Name should end on Page
         if (!preg_match('/Page$/', $name)) {
             throw new \InvalidArgumentException('The page name must end with Page');
         }
         // Name should contain more characters than Page
         if (strlen($name) <= strlen('Page') || !preg_match('/^[a-zA-Z]+$/', $name)) {
             throw new \InvalidArgumentException('Invalid page name');
         }
         // Check that entity does not already exist
         if (file_exists($bundlePath . '/Entity/Pages/' . $name . '.php')) {
             throw new \InvalidArgumentException(sprintf('Page or entity "%s" already exists', $name));
         }
         return $name;
     });
     $this->pageName = $name;
     /**
      * Ask which fields need to be present
      */
     $this->assistant->writeLine(array("\nInstead of starting with a blank page, you can add some fields now.\n"));
     $fields = $this->askEntityFields($this->bundle, array('title', 'pageTitle', 'parent', 'id'));
     $this->fields = array();
     foreach ($fields as $fieldInfo) {
         $this->fields[] = $this->getEntityFields($this->bundle, $this->pageName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'], $fieldInfo['extra'], true);
     }
     /**
      * Ask which default page template we need to use
      */
     $templateSelect = $this->getDefaultTemplateList();
     $this->assistant->writeLine('');
     $templateId = $this->assistant->askSelect('Which page template do you want to use', $templateSelect);
     $templateConfigs = $this->getDefaultTemplateConfigurations();
     $templateConfig = $templateConfigs[$templateId];
     $this->template = $templateConfig['file'];
     /**
      * Ask for which sections pagepart configuration the end user wants to use for the different sections
      */
     $this->assistant->writeLine(array("\nThe select page template consists of these contexts: " . implode(', ', $templateConfig['contexts'])));
     $this->section = array();
     $defaultSectionConfiguration = $this->getDefaultSectionConfigurations();
     foreach ($templateConfig['contexts'] as $context) {
         $question = "Which pagepart configuration would you like to use for the '{$context}' context";
         $section = $this->askForSections($question, $this->bundle, false, $context, $defaultSectionConfiguration);
         if (is_null($section)) {
             $this->assistant->writeError(sprintf('No section pagepart configuration found for context "%s"', $context), true);
         }
         $this->sections[] = $section;
     }
     /**
      * Ask the parent pages
      */
     $counter = 1;
     $pagesSelect = $parentPages = array();
     $this->parentPages = array();
     // Get the available pages from disc
     $dir = $this->bundle->getPath() . '/Entity/Pages/';
     if (file_exists($dir) && is_dir($dir)) {
         $finder = new Finder();
         $finder->files()->in($dir)->depth('== 0');
         foreach ($finder as $file) {
             $temp = $counter++;
             $pagesSelect[$temp] = substr($file->getFileName(), 0, strlen($file->getFileName()) - 4);
             $parentPages[$temp] = array('path' => $file->getPathName());
         }
     }
     if (count($pagesSelect) > 0) {
         $this->assistant->writeLine('');
         $parentPageIds = $this->assistant->askSelect('Which existing page(s) can have the new page as sub-page (multiple possible, separated by comma)', $pagesSelect, null, true);
         foreach ($parentPageIds as $id) {
             $this->parentPages[] = $parentPages[$id]['path'];
         }
     }
 }