| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php'); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfDoctrineGenerateModuleForRouteTask extends sfDoctrineBaseTask |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* @see sfTask |
|---|
| 25 |
*/ |
|---|
| 26 |
protected function configure() |
|---|
| 27 |
{ |
|---|
| 28 |
$this->addArguments(array( |
|---|
| 29 |
new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), |
|---|
| 30 |
new sfCommandArgument('route', sfCommandArgument::REQUIRED, 'The route name'), |
|---|
| 31 |
)); |
|---|
| 32 |
|
|---|
| 33 |
$this->addOptions(array( |
|---|
| 34 |
new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'default'), |
|---|
| 35 |
new sfCommandOption('non-verbose-templates', null, sfCommandOption::PARAMETER_NONE, 'Generate non verbose templates'), |
|---|
| 36 |
new sfCommandOption('singular', null, sfCommandOption::PARAMETER_REQUIRED, 'The singular name', null), |
|---|
| 37 |
new sfCommandOption('plural', null, sfCommandOption::PARAMETER_REQUIRED, 'The plural name', null), |
|---|
| 38 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), |
|---|
| 39 |
)); |
|---|
| 40 |
|
|---|
| 41 |
$this->namespace = 'doctrine'; |
|---|
| 42 |
$this->name = 'generate-module-for-route'; |
|---|
| 43 |
$this->briefDescription = 'Generates a Doctrine module for a route definition'; |
|---|
| 44 |
|
|---|
| 45 |
$this->detailedDescription = <<<EOF |
|---|
| 46 |
The [doctrine:generate-module-for-route|INFO] task generates a Doctrine module for a route definition: |
|---|
| 47 |
|
|---|
| 48 |
[./symfony doctrine:generate-module-for-route frontend article|INFO] |
|---|
| 49 |
|
|---|
| 50 |
The task creates a module in the [%frontend%|COMMENT] application for the |
|---|
| 51 |
[%article%|COMMENT] route definition found in [routing.yml|COMMENT]. |
|---|
| 52 |
EOF; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
* @see sfTask |
|---|
| 57 |
*/ |
|---|
| 58 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 59 |
{ |
|---|
| 60 |
|
|---|
| 61 |
$config = new sfRoutingConfigHandler(); |
|---|
| 62 |
$routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); |
|---|
| 63 |
|
|---|
| 64 |
if (!isset($routes[$arguments['route']])) |
|---|
| 65 |
{ |
|---|
| 66 |
throw new sfCommandException(sprintf('The route "%s" does not exist.', $arguments['route'])); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$routeOptions = $routes[$arguments['route']]->getOptions(); |
|---|
| 70 |
|
|---|
| 71 |
if (!$routes[$arguments['route']] instanceof sfDoctrineRouteCollection) |
|---|
| 72 |
{ |
|---|
| 73 |
throw new sfCommandException(sprintf('The route "%s" is not a Doctrine collection route.', $arguments['route'])); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
$module = $routeOptions['module']; |
|---|
| 77 |
$model = $routeOptions['model']; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
$task = new sfDoctrineGenerateModuleTask($this->dispatcher, $this->formatter); |
|---|
| 81 |
$task->setCommandApplication($this->commandApplication); |
|---|
| 82 |
|
|---|
| 83 |
$taskOptions = array( |
|---|
| 84 |
'--theme='.$options['theme'], |
|---|
| 85 |
'--env='.$options['env'], |
|---|
| 86 |
'--route-prefix='.$routeOptions['name'], |
|---|
| 87 |
'--with-doctrine-route', |
|---|
| 88 |
); |
|---|
| 89 |
|
|---|
| 90 |
if ($routeOptions['with_show']) |
|---|
| 91 |
{ |
|---|
| 92 |
$taskOptions[] = '--with-show'; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
if ($options['non-verbose-templates']) |
|---|
| 96 |
{ |
|---|
| 97 |
$taskOptions[] = '--non-verbose-templates'; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
if (!is_null($options['singular'])) |
|---|
| 101 |
{ |
|---|
| 102 |
$taskOptions[] = '--singular='.$options['singular']; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
if (!is_null($options['plural'])) |
|---|
| 106 |
{ |
|---|
| 107 |
$taskOptions[] = '--plural='.$options['plural']; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
$this->logSection('app', sprintf('Generating module "%s" for model "%s"', $module, $model)); |
|---|
| 111 |
|
|---|
| 112 |
return $task->run(array($arguments['application'], $module, $model), $taskOptions); |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|