Development

/branches/1.2/lib/task/generator/sfGenerateModuleTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/task/generator/sfGenerateModuleTask.class.php

Revision 13022, 3.8 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.1, 1.2] fixed generate:module description formatting

  • 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__).'/sfGeneratorBaseTask.class.php');
12
13 /**
14  * Generates a new module.
15  *
16  * @package    symfony
17  * @subpackage task
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfGenerateModuleTask extends sfGeneratorBaseTask
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     ));
32
33     $this->aliases = array('init-module');
34     $this->namespace = 'generate';
35     $this->name = 'module';
36
37     $this->briefDescription = 'Generates a new module';
38
39     $this->detailedDescription = <<<EOF
40 The [generate:module|INFO] task creates the basic directory structure
41 for a new module in an existing application:
42
43   [./symfony generate:module frontend article|INFO]
44
45 The task can also change the author name found in the [actions.class.php|COMMENT]
46 if you have configure it in [config/properties.ini|COMMENT]:
47
48   [[symfony]
49     name=blog
50     author=Fabien Potencier <fabien.potencier@sensio.com>|INFO]
51
52 You can customize the default skeleton used by the task by creating a
53 [%sf_data_dir%/skeleton/module|COMMENT] directory.
54
55 The task also creates a functional test stub named
56 [%sf_test_dir%/functional/%application%/%module%ActionsTest.class.php|COMMENT]
57 that does not pass by default.
58
59 If a module with the same name already exists in the application,
60 it throws a [sfCommandException|COMMENT].
61 EOF;
62   }
63
64   /**
65    * @see sfTask
66    */
67   protected function execute($arguments = array(), $options = array())
68   {
69     $app    = $arguments['application'];
70     $module = $arguments['module'];
71
72     // Validate the module name
73     if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $module))
74     {
75       throw new sfCommandException(sprintf('The module name "%s" is invalid.', $module));
76     }
77
78     $moduleDir = sfConfig::get('sf_app_module_dir').'/'.$module;
79
80     if (is_dir($moduleDir))
81     {
82       throw new sfCommandException(sprintf('The module "%s" already exists in the "%s" application.', $moduleDir, $app));
83     }
84
85     $properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true);
86
87     $constants = array(
88       'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony',
89       'APP_NAME'     => $app,
90       'MODULE_NAME'  => $module,
91       'AUTHOR_NAME'  => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here',
92     );
93
94     if (is_readable(sfConfig::get('sf_data_dir').'/skeleton/module'))
95     {
96       $skeletonDir = sfConfig::get('sf_data_dir').'/skeleton/module';
97     }
98     else
99     {
100       $skeletonDir = dirname(__FILE__).'/skeleton/module';
101     }
102
103     // create basic application structure
104     $finder = sfFinder::type('any')->discard('.sf');
105     $this->getFilesystem()->mirror($skeletonDir.'/module', $moduleDir, $finder);
106
107     // create basic test
108     $this->getFilesystem()->copy($skeletonDir.'/test/actionsTest.php', sfConfig::get('sf_test_dir').'/functional/'.$app.'/'.$module.'ActionsTest.php');
109
110     // customize test file
111     $this->getFilesystem()->replaceTokens(sfConfig::get('sf_test_dir').'/functional/'.$app.DIRECTORY_SEPARATOR.$module.'ActionsTest.php', '##', '##', $constants);
112
113     // customize php and yml files
114     $finder = sfFinder::type('file')->name('*.php', '*.yml');
115     $this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $constants);
116   }
117 }
118
Note: See TracBrowser for help on using the browser.