Development

/branches/1.2/lib/plugins/sfPropelPlugin/lib/task/sfPropelGenerateModuleForRouteTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfPropelPlugin/lib/task/sfPropelGenerateModuleForRouteTask.class.php

Revision 12161, 3.7 kB (checked in by fabien, 6 years ago)

[1.2] fixed typo

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 require_once(dirname(__FILE__).'/sfPropelBaseTask.class.php');
12
13 /**
14  * Generates a Propel module for a route definition.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelGenerateModuleForRouteTask extends sfPropelBaseTask
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 = 'propel';
42     $this->name = 'generate-module-for-route';
43     $this->briefDescription = 'Generates a Propel module for a route definition';
44
45     $this->detailedDescription = <<<EOF
46 The [propel:generate-module-for-route|INFO] task generates a Propel module for a route definition:
47
48   [./symfony propel: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     // get configuration for the given route
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 sfPropelRouteCollection)
72     {
73       throw new sfCommandException(sprintf('The route "%s" is not a Propel collection route.', $arguments['route']));
74     }
75
76     $module = $routeOptions['module'];
77     $model = $routeOptions['model'];
78
79     // execute the propel:generate-module task
80     $task = new sfPropelGenerateModuleTask($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-propel-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 }
115
Note: See TracBrowser for help on using the browser.