Development

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

You must first sign up to be able to contribute.

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

Revision 23194, 3.7 kB (checked in by fabien, 5 years ago)

[1.3] added a --actions-base-class options to tasks that generate modules (closes #5995)

  • 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       new sfCommandOption('actions-base-class', null, sfCommandOption::PARAMETER_REQUIRED, 'The base class for the actions', 'sfActions'),
40     ));
41
42     $this->namespace = 'propel';
43     $this->name = 'generate-module-for-route';
44     $this->briefDescription = 'Generates a Propel module for a route definition';
45
46     $this->detailedDescription = <<<EOF
47 The [propel:generate-module-for-route|INFO] task generates a Propel module for a route definition:
48
49   [./symfony propel:generate-module-for-route frontend article|INFO]
50
51 The task creates a module in the [%frontend%|COMMENT] application for the
52 [%article%|COMMENT] route definition found in [routing.yml|COMMENT].
53 EOF;
54   }
55
56   /**
57    * @see sfTask
58    */
59   protected function execute($arguments = array(), $options = array())
60   {
61     // get configuration for the given route
62     $config = new sfRoutingConfigHandler();
63     $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml'));
64
65     if (!isset($routes[$arguments['route']]))
66     {
67       throw new sfCommandException(sprintf('The route "%s" does not exist.', $arguments['route']));
68     }
69
70     $routeOptions = $routes[$arguments['route']]->getOptions();
71
72     if (!$routes[$arguments['route']] instanceof sfPropelRouteCollection)
73     {
74       throw new sfCommandException(sprintf('The route "%s" is not a Propel collection route.', $arguments['route']));
75     }
76
77     $module = $routeOptions['module'];
78     $model = $routeOptions['model'];
79
80     // execute the propel:generate-module task
81     $task = new sfPropelGenerateModuleTask($this->dispatcher, $this->formatter);
82     $task->setCommandApplication($this->commandApplication);
83     $task->setConfiguration($this->configuration);
84
85     $this->logSection('app', sprintf('Generating module "%s" for model "%s"', $module, $model));
86
87     return $task->run(array($arguments['application'], $module, $model), array(
88       'theme'                 => $options['theme'],
89       'route-prefix'          => $routeOptions['name'],
90       'with-propel-route'     => true,
91       'with-show'             => $routeOptions['with_show'],
92       'non-verbose-templates' => $options['non-verbose-templates'],
93       'singular'              => $options['singular'],
94       'plural'                => $options['plural'],
95       'actions-base-class'    => $options['actions-base-class'],
96     ));
97   }
98 }
99
Note: See TracBrowser for help on using the browser.