Development

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

You must first sign up to be able to contribute.

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

Revision 10527, 3.2 kB (checked in by dwhittle, 6 years ago)

sfPropelPlugin: merged fixed for propel tasks

  • 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) 2004-2006 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  * Initializes a Propel admin module.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelInitAdminTask 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('module', sfCommandArgument::REQUIRED, 'The module name'),
31       new sfCommandArgument('model', sfCommandArgument::REQUIRED, 'The model class name'),
32     ));
33
34     $this->addOptions(array(
35       new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'default'),
36     ));
37
38     $this->aliases = array('propel-init-admin');
39     $this->namespace = 'propel';
40     $this->name = 'init-admin';
41     $this->briefDescription = 'Initializes a Propel admin module';
42
43     $this->detailedDescription = <<<EOF
44 The [propel:init-admin|INFO] task generates a Propel admin module:
45
46   [./symfony propel:init-admin frontend article Article|INFO]
47
48 The task creates a [%module%|COMMENT] module in the [%application%|COMMENT] application
49 for the model class [%model%|COMMENT].
50
51 The created module is an empty one that inherit its actions and templates from
52 a runtime generated module in [%sf_app_cache_dir%/modules/auto%module%|COMMENT].
53
54 The generator can use a customized theme by using the [--theme|COMMENT] option:
55
56   [./symfony propel:init-admin --theme="custom" frontend article Article|INFO]
57 EOF;
58   }
59
60   /**
61    * @see sfTask
62    */
63   protected function execute($arguments = array(), $options = array())
64   {
65     $databaseManager = new sfDatabaseManager($this->configuration);
66     
67     $properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true);
68
69     $constants = array(
70       'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony',
71       'APP_NAME'     => $arguments['application'],
72       'MODULE_NAME'  => $arguments['module'],
73       'MODEL_CLASS'  => $arguments['model'],
74       'AUTHOR_NAME'  => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here',
75       'THEME'        => $options['theme'],
76     );
77
78     $moduleDir = sfConfig::get('sf_app_module_dir').'/'.$arguments['module'];
79
80     // create module structure
81     $finder = sfFinder::type('any')->discard('.sf');
82     $dirs = $this->configuration->getGeneratorSkeletonDirs('sfPropelAdmin', $options['theme']);
83     foreach ($dirs as $dir)
84     {
85       if (is_dir($dir))
86       {
87         $this->getFilesystem()->mirror($dir, $moduleDir, $finder);
88         break;
89       }
90     }
91
92     // customize php and yml files
93     $finder = sfFinder::type('file')->name('*.php', '*.yml');
94     $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $constants);
95   }
96 }
97
Note: See TracBrowser for help on using the browser.