/** * Asks an entity class name in shortcut notation. * * @param InputInterface $input * @param OutputInterface $output * * @return Remg\Bundle\GeneratorBundle\Mapping\Entity */ public function askShortcut(GeneratorStyle $io, $shortcut = null) { // Store entity factory in a variable to use it in a Closure $manager = $this->manager; // Get default shortcut answer $default = $shortcut ?: static::DEFAULT_SHORTCUT; // Create new question return $io->ask('Please enter the entity shortcut', $default, function ($answer) use($manager) { /* @throws \InvalidArgumentException if the answer is not a valid entity shortcut */ $manager->parseShortcut($answer); return $answer; }); }
/** * Asks the name of the field that completes the bidirectional association on the inverse side. * The key 'inversedBy' must be specified on the owning side of a bidirectional association. * * @param InputInterface $input * @param OutputInterface $output * @param ClassMetadata $metadata * @param string $associationName * * @return string */ private function askAssociationInversedBy(GeneratorStyle $io, ClassMetadata $metadata, $associationName = null) { // Get actual field inversedBy based on field name // or default value if not set. $inversedBy = $metadata->getAssociationInversedBy($associationName) ?: static::DEFAULT_INVERSED_BY; // Create new question return $io->ask('Inversed by', $inversedBy, function ($answer) { // return $answer; }); }
/** * Asks the database length of the column. * Optional. * Default value taken from the type. * * @param InputInterface $input * @param OutputInterface $output * @param ClassMetadata $metadata * @param string $fieldName * * @return string */ private function askFieldLength(GeneratorStyle $io, ClassMetadata $metadata, $fieldName = null) { // Get actual field length based on field name // or default value if not set. $length = $metadata->getFieldLength($fieldName) ?: static::DEFAULT_LENGTH; // Create new question return $io->ask('Length', $length, function ($answer) { $result = filter_var($answer, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); if (false === $result) { throw new \InvalidArgumentException(sprintf('Invalid length "%s".', $answer)); } return $answer; }); }