Development

/branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelBuildFiltersTask.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelBuildFiltersTask.class.php

Revision 23927, 3.2 kB (checked in by fabien, 4 years ago)

[1.3, 1.4] added a new option to change the generator class for forms and filters (closes #5014, patch from joostdj)

  • 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 informationation, 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  * Create filter form classes for the current model.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelBuildFiltersTask extends sfPropelBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addOptions(array(
29       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
30       new sfCommandOption('model-dir-name', null, sfCommandOption::PARAMETER_REQUIRED, 'The model dir name', 'model'),
31       new sfCommandOption('filter-dir-name', null, sfCommandOption::PARAMETER_REQUIRED, 'The filter form dir name', 'filter'),
32       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
33       new sfCommandOption('generator-class', null, sfCommandOption::PARAMETER_REQUIRED, 'The generator class', 'sfPropelFormFilterGenerator'),
34     ));
35
36     $this->namespace = 'propel';
37     $this->name = 'build-filters';
38     $this->briefDescription = 'Creates filter form classes for the current model';
39
40     $this->detailedDescription = <<<EOF
41 The [propel:build-filters|INFO] task creates filter form classes from the schema:
42
43   [./symfony propel:build-filters|INFO]
44
45 The task read the schema information in [config/*schema.xml|COMMENT] and/or
46 [config/*schema.yml|COMMENT] from the project and all installed plugins.
47
48 The task use the [propel|COMMENT] connection as defined in [config/databases.yml|COMMENT].
49 You can use another connection by using the [--connection|COMMENT] option:
50
51   [./symfony propel:build-filters --connection="name"|INFO]
52
53 The model filter form classes files are created in [lib/filter|COMMENT].
54
55 This task never overrides custom classes in [lib/filter|COMMENT].
56 It only replaces base classes generated in [lib/filter/base|COMMENT].
57 EOF;
58   }
59
60   /**
61    * @see sfTask
62    */
63   protected function execute($arguments = array(), $options = array())
64   {
65     $this->logSection('propel', 'generating filter form classes');
66
67     $generatorManager = new sfGeneratorManager($this->configuration);
68     $generatorManager->generate($options['generator-class'], array(
69       'connection'      => $options['connection'],
70       'model_dir_name'  => $options['model-dir-name'],
71       'filter_dir_name' => $options['filter-dir-name'],
72     ));
73
74     $properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true);
75
76     $constants = array(
77       'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony',
78       'AUTHOR_NAME'  => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'
79     );
80
81     // customize php and yml files
82     $finder = sfFinder::type('file')->name('*.php');
83     $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/filter/'), '##', '##', $constants);
84
85     $this->reloadAutoload();
86   }
87 }
88
Note: See TracBrowser for help on using the browser.