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__).'/sfDoctrineBaseTask.class.php');
12
 
13
/**
14
 * Create 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: sfDoctrineBuildFormsTask.class.php 23927 2009-11-14 16:10:57Z fabien $
20
 */
21
class sfDoctrineBuildFormsTask 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('form-dir-name', null, sfCommandOption::PARAMETER_REQUIRED, 'The form dir name', 'form'),
33
      new sfCommandOption('generator-class', null, sfCommandOption::PARAMETER_REQUIRED, 'The generator class', 'sfDoctrineFormGenerator'),
34
    ));
35
 
36
    $this->namespace = 'doctrine';
37
    $this->name = 'build-forms';
38
    $this->briefDescription = 'Creates form classes for the current model';
39
 
40
    $this->detailedDescription = <<<EOF
41
The [doctrine:build-forms|INFO] task creates form classes from the schema:
42
 
43
  [./symfony doctrine:build-forms|INFO]
44
 
45
This task creates form classes based on the model. The classes are created
46
in [lib/doctrine/form|COMMENT].
47
 
48
This task never overrides custom classes in [lib/doctrine/form|COMMENT].
49
It only replaces base classes generated in [lib/doctrine/form/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 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
      'form_dir_name'  => $options['form-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').'/form/'), '##', '##', $constants);
76
 
77
    // check for base form class
78
    if (!class_exists('BaseForm'))
79
    {
80
      $file = sfConfig::get('sf_lib_dir').'/'.$options['form-dir-name'].'/BaseForm.class.php';
81
      $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir').'/task/generator/skeleton/project/lib/form/BaseForm.class.php', $file);
82
      $this->getFilesystem()->replaceTokens($file, '##', '##', $constants);
83
    }
84
 
85
    $this->reloadAutoload();
86
  }
87
}