. */ namespace Doctrine\ORM\Tools\Console\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Doctrine\ORM\Tools\Console\MetadataFilter; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Command\Command; /** * Command to (re)generate the proxy classes used by doctrine. * * @link www.doctrine-project.org * @since 2.0 * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel */ class GenerateProxiesCommand extends Command { /** * {@inheritdoc} */ 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(<<getHelper('em')->getEntityManager(); $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); // Process destination directory 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 '%s' does not exist.", $em->getConfiguration()->getProxyDir()) ); } if ( ! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Proxies destination directory '%s' does not have write permissions.", $destPath) ); } if ( count($metadatas)) { foreach ($metadatas as $metadata) { $output->writeln( sprintf('Processing entity "%s"', $metadata->name) ); } // Generating Proxies $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); // Outputting information message $output->writeln(PHP_EOL . sprintf('Proxy classes generated to "%s"', $destPath)); } else { $output->writeln('No Metadata Classes to process.'); } } }