123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace Doctrine\ORM\Tools\Console\Command;
- use Symfony\Component\Console\Input\InputArgument,
- Symfony\Component\Console\Input\InputOption,
- Symfony\Component\Console,
- Doctrine\ORM\Tools\Console\MetadataFilter;
- class GenerateProxiesCommand extends Console\Command\Command
- {
-
- protected function configure()
- {
- $this
- ->setName('orm:generate-proxies')
- ->setDescription('Generates proxy classes for entity classes.')
- ->setDefinition(array(
- new InputOption(
- 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
- 'A string pattern used to match entities that should be processed.'
- ),
- new InputArgument(
- 'dest-path', InputArgument::OPTIONAL,
- 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.'
- ),
- ))
- ->setHelp(<<<EOT
- Generates proxy classes for entity classes.
- EOT
- );
- }
-
- protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
- {
- $em = $this->getHelper('em')->getEntityManager();
- $metadatas = $em->getMetadataFactory()->getAllMetadata();
- $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
-
- if (($destPath = $input->getArgument('dest-path')) === null) {
- $destPath = $em->getConfiguration()->getProxyDir();
- }
- if ( ! is_dir($destPath)) {
- mkdir($destPath, 0777, true);
- }
- $destPath = realpath($destPath);
- if ( ! file_exists($destPath)) {
- throw new \InvalidArgumentException(
- sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir())
- );
- } else if ( ! is_writable($destPath)) {
- throw new \InvalidArgumentException(
- sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath)
- );
- }
- if ( count($metadatas)) {
- foreach ($metadatas as $metadata) {
- $output->write(
- sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL
- );
- }
-
- $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
-
- $output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
- } else {
- $output->write('No Metadata Classes to process.' . PHP_EOL);
- }
- }
- }
|