public function generateRepository(GeneratorStyle $io, ClassMetadata $metadata)
 {
     /* Repository */
     $io->section('Repository generation');
     $io->text(sprintf('Target path: %s', $metadata->getRepositoryPath()));
     // Generate repository class file
     $this->repositoryGenerator->generateClass($metadata);
     $io->success('Entity repository generated successfully!');
     return $this;
 }
Пример #2
0
 /**
  * Executes the command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get metadata informations
     $metadata = $input->getOption('entity');
     $io = new GeneratorStyle($input, $output);
     $io->title('Files generation');
     $this->getContainer()->get('remg_entity_generator_helper')->generateEntity($io, $metadata);
     // Update the database schema
     $this->runSchemaUpdate($input, $output);
 }
Пример #3
0
 /**
  * Updates the database schema
  * by running the 'doctrine:schema:update' command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function runSchemaUpdate(InputInterface $input, OutputInterface $output)
 {
     // Dont update the schema if the option "no-schema-update" is provided.
     if ($input->getOption('no-schema-update')) {
         return;
     }
     $io = new GeneratorStyle($input, $output);
     $io->title('Database schema update');
     $io->text('Updating database schema..');
     // Get the doctrine schema update command.
     $command = $this->getApplication()->find('doctrine:schema:update');
     // Dont run the command if the command is not found.
     if (!$command) {
         $output->writeln('<error>Unable to update the database schema (command not found).</error>');
         return;
     }
     // Create new command input arguments.
     $commandInput = new ArrayInput(['command' => 'doctrine:schema:update', '--force' => true, '--quiet' => true]);
     // Execute the command.
     $command->run($commandInput, $output);
 }
 /**
  * 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;
     });
 }
Пример #5
0
 public function displaySummary(GeneratorStyle $io, ClassMetadata $metadata, $fieldName = null)
 {
     $headers = ['name', 'type', 'nullable', 'unique'];
     $rows = [];
     foreach ($metadata->fieldMappings as $field => $mapping) {
         if (null !== $fieldName && $fieldName !== $field) {
             continue;
         }
         $row = [];
         // name
         $row[] = $field;
         // type
         switch ($type = $metadata->getFieldType($field)) {
             case Type::STRING:
                 $row[] = sprintf('%s(%s)', $type, $metadata->getFieldLength($field));
                 break;
             case Type::DECIMAL:
                 $row[] = sprintf('%s (2,0)', $type);
                 break;
             default:
                 $row[] = $type;
                 break;
         }
         // nullable
         $row[] = $metadata->getFieldNullable($field) ? 'true' : 'false';
         // unique
         $row[] = $metadata->getFieldUnique($field) ? 'true' : 'false';
         $rows[] = $row;
     }
     $io->table($headers, $rows);
 }
Пример #6
0
 public function displayGeneralInformations(GeneratorStyle $io, ClassMetadata $metadata)
 {
     $io->table([], [['Name', $metadata->getEntityClassName()], ['Bundle', $metadata->getBundle()->getNamespace()], ['Namespace', $metadata->getName()], ['Repository', $metadata->customRepositoryClassName], ['Entity path', $metadata->getPath()], ['Repository path', $metadata->getRepositoryPath()]]);
     return $this;
 }