/**
  * {@inheritdoc}
  */
 public function addGenerator(GeneratorInterface $generator, $priority = 1)
 {
     if ($generator instanceof ContainerAwareInterface) {
         $generator->setContainer($this->container);
     }
     parent::addGenerator($generator, $priority);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function addGenerator(GeneratorInterface $generator, $priority = 1)
 {
     $name = $generator->getName();
     if (!$this->hasGenerator($name) || $this->priorities[$name] < $priority) {
         $this->generators[$name] = $generator;
         $this->priorities[$name] = $priority;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function locate($resource, GeneratorInterface $generator)
 {
     $location = $this->location;
     if ($location[-1] !== '/' && $location[-1] !== '\\') {
         $location .= '/';
     }
     if (strpos($location, '%generator%') !== false) {
         $directory = str_replace('%generator%', $generator->getName(), $location);
     } else {
         $directory = $location . $generator->getName() . '/';
     }
     return $directory . $resource;
 }
 public static function format(ConstraintViolationList $problems, GeneratorInterface $generator, FormatterHelper $formatter)
 {
     $messages = [];
     // add header message
     $problemCount = count($problems);
     $name = $generator->getName();
     $messages[] = "While trying to call the generator '{$name}', {$problemCount} problems were found:";
     $messages[] = "";
     /** @var ConstraintViolation $problem */
     foreach ($problems as $problem) {
         $messages[] = "In \$arguments{$problem->getPropertyPath()}: {$problem->getMessage()}";
     }
     return $formatter->formatBlock($messages, 'error', true);
 }
Ejemplo n.º 5
0
 /**
  * Grab the input arguments for the given generator from the input, or ask interactively.
  * @param InputInterface        $input              Input from which the arguments should be resolved.
  * @param GeneratorInterface    $generator          The generator for which input arguments should be grabbed.
  * @param bool                  $forceInteractive   Try to run the interactive versions of asking for input.
  * @throws \RuntimeException
  * @return Arguments
  */
 public function resolve(InputInterface $input, GeneratorInterface $generator, $forceInteractive = false)
 {
     $definition = $generator->getDefinition();
     $definition = $this->mergeApplicationDefinition($definition);
     $definition = new InputDefinition($definition);
     $input = clone $input;
     try {
         $input->bind($definition);
         $input->validate();
     } catch (\Exception $ex) {
         $forceInteractive = true;
     }
     $arguments = array_merge($input->getArguments(), $input->getOptions());
     $arguments = new Arguments($arguments, $forceInteractive || $generator->requiresInteraction());
     return $arguments;
     if ($forceInteractive || $generator->requiresInteraction()) {
         if (!$input->isInteractive()) {
             throw new \RuntimeException("Cannot interact with user.");
         }
         $constraints = $generator->getConstraints();
         $questioner = new Questioner($inputTypeRegistry, $this->output, $this->helperSet, $constraints);
         $arguments = $generator->interact($arguments, $questioner);
     }
     return $arguments;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function did($what, $on = null, array $arguments = array())
 {
     if (null === $this->generator) {
         throw new \BadMethodCallException("Must first bind generator before running actions");
     }
     $path = $this->path;
     if ($path[strlen($path) - 1] === '/' || $path[strlen($path - 1)] === '\\') {
         $path = substr($path, 0, -1);
     }
     if ($path === $on) {
         $on = '.';
     } else {
         if (strpos($on, $path) === 0 && ($on[strlen($path)] === '/' || $on[strlen($path)] === '\\')) {
             $on = substr($on, strlen($path) + 1);
         }
     }
     $this->generator->did($what, $on, $arguments, $this->depth);
 }
Ejemplo n.º 7
0
 /**
  * Show the help for a single generator.
  * @param GeneratorInterface $generator
  * @param OutputInterface    $output
  */
 protected function showGeneratorHelp(GeneratorInterface $generator, OutputInterface $output)
 {
     $definition = new InputDefinition($generator->getDefinition());
     $output->writeln("<comment>Generator:</comment> <info>{$generator->getName()}</info>");
     $output->writeln(" {$generator->getDescription()}");
     $output->writeln("");
     $output->writeln("<comment>Usage:</comment>");
     $output->writeln(" {$this->getName()} {$generator->getName()} {$definition->getSynopsis()}");
     $output->writeln("");
     $descriptor = new DescriptorHelper();
     $descriptor->describe($output, $definition);
 }