Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
 * Create 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: sfPropelBuildFormsTask.class.php 23927 2009-11-14 16:10:57Z fabien $
20
 */
21
class sfPropelBuildFormsTask 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('form-dir-name', null, sfCommandOption::PARAMETER_REQUIRED, 'The form dir name', 'form'),
32
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
33
      new sfCommandOption('generator-class', null, sfCommandOption::PARAMETER_REQUIRED, 'The generator class', 'sfPropelFormGenerator'),
34
    ));
35
 
36
    $this->namespace = 'propel';
37
    $this->name = 'build-forms';
38
    $this->briefDescription = 'Creates form classes for the current model';
39
 
40
    $this->detailedDescription = <<<EOF
41
The [propel:build-forms|INFO] task creates form classes from the schema:
42
 
43
  [./symfony propel:build-forms|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-forms --connection="name"|INFO]
52
 
53
The model form classes files are created in [lib/form|COMMENT].
54
 
55
This task never overrides custom classes in [lib/form|COMMENT].
56
It only replaces base classes generated in [lib/form/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 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
      'form_dir_name'  => $options['form-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').'/form/'), '##', '##', $constants);
84
 
85
    // check for base form class
86
    if (!class_exists('BaseForm'))
87
    {
88
      $file = sfConfig::get('sf_lib_dir').'/'.$options['form-dir-name'].'/BaseForm.class.php';
89
      $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir').'/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file);
90
      $this->getFilesystem()->replaceTokens($file, '##', '##', $constants);
91
    }
92
 
93
    $this->reloadAutoload();
94
  }
95
}