protected function execute(InputInterface $input, OutputInterface $output) { $bundleName = $input->getArgument('bundle'); $filterDocument = $input->getOption('document'); $foundBundle = $this->findBundle($bundleName); if ($metadatas = $this->getBundleMetadatas($foundBundle)) { $output->writeln(sprintf('Generating document repositories for "<info>%s</info>"', $foundBundle->getName())); $generator = new DocumentRepositoryGenerator(); foreach ($metadatas as $metadata) { if ($filterDocument && $filterDocument !== $metadata->reflClass->getShortname()) { continue; } if ($metadata->customRepositoryClassName) { if (strpos($metadata->customRepositoryClassName, $foundBundle->getNamespace()) === false) { throw new \RuntimeException("Repository " . $metadata->customRepositoryClassName . " and bundle don't have a common namespace, " . "generation failed because the target directory cannot be detected."); } $output->writeln(sprintf(' > <info>OK</info> generating <comment>%s</comment>', $metadata->customRepositoryClassName)); $generator->writeDocumentRepositoryClass($metadata->customRepositoryClassName, $this->findBasePathForBundle($foundBundle)); } else { $output->writeln(sprintf(' > <error>SKIP</error> no custom repository for <comment>%s</comment>', $metadata->name)); } } } else { throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped documents."); } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $dm = $this->getHelper('dm')->getDocumentManager(); $metadatas = $dm->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); // Process destination directory $destPath = realpath($input->getArgument('dest-path')); if (!file_exists($destPath)) { throw new \InvalidArgumentException(sprintf("Documents destination directory '<info>%s</info>' does not exist.", $destPath)); } else { if (!is_writable($destPath)) { throw new \InvalidArgumentException(sprintf("Documents destination directory '<info>%s</info>' does not have write permissions.", $destPath)); } } if (count($metadatas)) { $numRepositories = 0; $generator = new DocumentRepositoryGenerator(); foreach ($metadatas as $metadata) { if ($metadata->customRepositoryClassName) { $output->write(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL); $generator->writeDocumentRepositoryClass($metadata->customRepositoryClassName, $destPath); $numRepositories++; } } if ($numRepositories) { // Outputting information message $output->write(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL); } else { $output->write('No Repository classes were found to be processed.' . PHP_EOL); } } else { $output->write('No Metadata Classes to process.' . PHP_EOL); } }
public function testPersistedDocumentRepositoryClassWithArbitraryNamespaceMapping() { $namespace = 'A\\B\\C\\D'; $this->generator->writeDocumentRepositoryClass($namespace . '\\TestDocumentRepository', $this->testBucketPath, $namespace); $this->tryLoadingRepositoryClass($namespace . '\\TestDocumentRepository'); }