2009-10-15 00:18:36 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\ORM\Tools\Cli\Tasks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Task to (re)generate the proxy classes used by doctrine.
|
|
|
|
*
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision: 3938 $
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
*/
|
|
|
|
class GenerateProxiesTask extends AbstractTask
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function extendedHelp()
|
|
|
|
{
|
|
|
|
$printer = $this->getPrinter();
|
|
|
|
|
|
|
|
$printer->write('Task: ')->writeln('generate-proxies', 'KEYWORD')
|
|
|
|
->write('Synopsis: ');
|
|
|
|
$this->_writeSynopsis($printer);
|
|
|
|
|
|
|
|
$printer->writeln('Description: Generates proxy classes for entity classes.')
|
|
|
|
->writeln('Options:')
|
|
|
|
->write('--to-dir', 'OPT_ARG')
|
|
|
|
->writeln("\t\tGenerates the classes in the specified directory.")
|
|
|
|
->write(PHP_EOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function basicHelp()
|
|
|
|
{
|
|
|
|
$this->_writeSynopsis($this->getPrinter());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _writeSynopsis($printer)
|
|
|
|
{
|
|
|
|
$printer->write('generate-proxies', 'KEYWORD')
|
|
|
|
->writeln(' [--to-dir=<PATH>]', 'OPT_ARG');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function validate()
|
|
|
|
{
|
|
|
|
$args = $this->getArguments();
|
|
|
|
$printer = $this->getPrinter();
|
|
|
|
|
2009-10-30 03:15:53 +03:00
|
|
|
$metadataDriver = $this->getEntityManager()->getConfiguration()->getMetadataDriverImpl();
|
2009-10-15 00:18:36 +04:00
|
|
|
|
|
|
|
if ($metadataDriver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) {
|
|
|
|
if ( ! isset($args['class-dir'])) {
|
|
|
|
$printer->writeln("The supplied configuration uses the annotation metadata driver."
|
|
|
|
. " The 'class-dir' argument is required for this driver.", 'ERROR');
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$metadataDriver->setClassDirectory($args['class-dir']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the task.
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$args = $this->getArguments();
|
|
|
|
|
2009-10-30 03:15:53 +03:00
|
|
|
$em = $this->getEntityManager();
|
|
|
|
$cmf = $em->getMetadataFactory();
|
|
|
|
$driver = $em->getConfiguration()->getMetadataDriverImpl();
|
2009-10-15 00:18:36 +04:00
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
$preloadedClasses = $driver->preload(true);
|
2009-10-30 03:15:53 +03:00
|
|
|
|
2009-10-15 00:18:36 +04:00
|
|
|
foreach ($preloadedClasses as $className) {
|
|
|
|
$classes[] = $cmf->getMetadataFor($className);
|
|
|
|
}
|
|
|
|
|
|
|
|
$printer = $this->getPrinter();
|
2009-10-30 03:15:53 +03:00
|
|
|
$factory = $em->getProxyFactory();
|
2009-10-15 00:18:36 +04:00
|
|
|
|
|
|
|
if (empty($classes)) {
|
|
|
|
$printer->writeln('No classes to process.', 'INFO');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$factory->generateProxyClasses($classes, isset($args['to-dir']) ? $args['to-dir'] : null);
|
|
|
|
|
2009-10-30 03:15:53 +03:00
|
|
|
$printer->writeln(
|
|
|
|
'Proxy classes generated to: ' .
|
|
|
|
(isset($args['to-dir']) ? $args['to-dir'] : $em->getConfiguration()->getProxyDir())
|
|
|
|
);
|
2009-10-15 00:18:36 +04:00
|
|
|
}
|
|
|
|
}
|