setName('orm:generate-repositories') ->setAliases(['orm:generate:repositories']) ->setDescription('Generate repository classes from your mapping information') ->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.') ->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on') ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') ->setHelp('Generate repository classes from your mapping information.'); } /** * {@inheritdoc} * * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); $em = $this->getEntityManager($input); $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); $repositoryName = $em->getConfiguration()->getDefaultRepositoryClassName(); // Process destination directory $destPath = realpath($input->getArgument('dest-path')); if (! file_exists($destPath)) { throw new InvalidArgumentException( sprintf("Entities destination directory '%s' does not exist.", $input->getArgument('dest-path')) ); } if (! is_writable($destPath)) { throw new InvalidArgumentException( sprintf("Entities destination directory '%s' does not have write permissions.", $destPath) ); } if (empty($metadatas)) { $ui->success('No Metadata Classes to process.'); return 0; } $numRepositories = 0; $generator = new EntityRepositoryGenerator(); $generator->setDefaultRepositoryName($repositoryName); foreach ($metadatas as $metadata) { if ($metadata->customRepositoryClassName) { $ui->text(sprintf('Processing repository "%s"', $metadata->customRepositoryClassName)); $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath); ++$numRepositories; } } if ($numRepositories === 0) { $ui->text('No Repository classes were found to be processed.'); return 0; } // Outputting information message $ui->newLine(); $ui->text(sprintf('Repository classes generated to "%s"', $destPath)); return 0; } }