Development

/branches/1.3/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBuildFiltersTask.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBuildFiltersTask.class.php

Revision 23927, 3.0 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: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__).'/sfDoctrineBaseTask.class.php');
12
13 /**
14  * Create filter form classes for the current model.
15  *
16  * @package    symfony
17  * @subpackage doctrine
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfDoctrineBuildFiltersTask extends sfDoctrineBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addOptions(array(
29       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
30       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
31       new sfCommandOption('model-dir-name', null, sfCommandOption::PARAMETER_REQUIRED, 'The model dir name', 'model'),
32       new sfCommandOption('filter-dir-name', null, sfCommandOption::PARAMETER_REQUIRED, 'The filter form dir name', 'filter'),
33       new sfCommandOption('generator-class', null, sfCommandOption::PARAMETER_REQUIRED, 'The generator class', 'sfDoctrineFormFilterGenerator'),
34     ));
35
36     $this->namespace = 'doctrine';
37     $this->name = 'build-filters';
38     $this->briefDescription = 'Creates filter form classes for the current model';
39
40     $this->detailedDescription = <<<EOF
41 The [doctrine:build-filters|INFO] task creates form filter classes from the schema:
42
43   [./symfony doctrine:build-filters|INFO]
44
45 This task creates form filter classes based on the model. The classes are
46 created in [lib/doctrine/filter|COMMENT].
47
48 This task never overrides custom classes in [lib/doctrine/filter|COMMENT].
49 It only replaces base classes generated in [lib/doctrine/filter/base|COMMENT].
50 EOF;
51   }
52
53   /**
54    * @see sfTask
55    */
56   protected function execute($arguments = array(), $options = array())
57   {
58     $this->logSection('doctrine', 'generating filter form classes');
59     $databaseManager = new sfDatabaseManager($this->configuration);
60     $generatorManager = new sfGeneratorManager($this->configuration);
61     $generatorManager->generate($options['generator-class'], array(
62       'model_dir_name'  => $options['model-dir-name'],
63       'filter_dir_name' => $options['filter-dir-name'],
64     ));
65
66     $properties = parse_ini_file(sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'properties.ini', true);
67
68     $constants = array(
69       'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony',
70       'AUTHOR_NAME'  => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here'
71     );
72
73     // customize php and yml files
74     $finder = sfFinder::type('file')->name('*.php');
75     $this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/filter/'), '##', '##', $constants);
76
77     $this->reloadAutoload();
78   }
79 }
Note: See TracBrowser for help on using the browser.