| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php'); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 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 |
|
|---|
| 74 |
$finder = sfFinder::type('file')->name('*.php'); |
|---|
| 75 |
$this->getFilesystem()->replaceTokens($finder->in(sfConfig::get('sf_lib_dir').'/form/'), '##', '##', $constants); |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 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 |
} |
|---|