| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
require_once(dirname(__FILE__).'/sfPropelBaseTask.class.php'); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfPropelInitAdminTask extends sfPropelBaseTask |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* @see sfTask |
|---|
| 25 |
*/ |
|---|
| 26 |
protected function configure() |
|---|
| 27 |
{ |
|---|
| 28 |
$this->addArguments(array( |
|---|
| 29 |
new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), |
|---|
| 30 |
new sfCommandArgument('module', sfCommandArgument::REQUIRED, 'The module name'), |
|---|
| 31 |
new sfCommandArgument('model', sfCommandArgument::REQUIRED, 'The model class name'), |
|---|
| 32 |
)); |
|---|
| 33 |
|
|---|
| 34 |
$this->addOptions(array( |
|---|
| 35 |
new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'default'), |
|---|
| 36 |
)); |
|---|
| 37 |
|
|---|
| 38 |
$this->aliases = array('propel-init-admin'); |
|---|
| 39 |
$this->namespace = 'propel'; |
|---|
| 40 |
$this->name = 'init-admin'; |
|---|
| 41 |
$this->briefDescription = 'Initializes a Propel admin module'; |
|---|
| 42 |
|
|---|
| 43 |
$this->detailedDescription = <<<EOF |
|---|
| 44 |
The [propel:init-admin|INFO] task generates a Propel admin module: |
|---|
| 45 |
|
|---|
| 46 |
[./symfony propel:init-admin frontend article Article|INFO] |
|---|
| 47 |
|
|---|
| 48 |
The task creates a [%module%|COMMENT] module in the [%application%|COMMENT] application |
|---|
| 49 |
for the model class [%model%|COMMENT]. |
|---|
| 50 |
|
|---|
| 51 |
The created module is an empty one that inherit its actions and templates from |
|---|
| 52 |
a runtime generated module in [%sf_app_cache_dir%/modules/auto%module%|COMMENT]. |
|---|
| 53 |
|
|---|
| 54 |
The generator can use a customized theme by using the [--theme|COMMENT] option: |
|---|
| 55 |
|
|---|
| 56 |
[./symfony propel:init-admin --theme="custom" frontend article Article|INFO] |
|---|
| 57 |
EOF; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
* @see sfTask |
|---|
| 62 |
*/ |
|---|
| 63 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 64 |
{ |
|---|
| 65 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 66 |
|
|---|
| 67 |
$properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true); |
|---|
| 68 |
|
|---|
| 69 |
$constants = array( |
|---|
| 70 |
'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', |
|---|
| 71 |
'APP_NAME' => $arguments['application'], |
|---|
| 72 |
'MODULE_NAME' => $arguments['module'], |
|---|
| 73 |
'MODEL_CLASS' => $arguments['model'], |
|---|
| 74 |
'AUTHOR_NAME' => isset($properties['symfony']['author']) ? $properties['symfony']['author'] : 'Your name here', |
|---|
| 75 |
'THEME' => $options['theme'], |
|---|
| 76 |
); |
|---|
| 77 |
|
|---|
| 78 |
$moduleDir = sfConfig::get('sf_app_module_dir').'/'.$arguments['module']; |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
$finder = sfFinder::type('any')->discard('.sf'); |
|---|
| 82 |
$dirs = $this->configuration->getGeneratorSkeletonDirs('sfPropelAdmin', $options['theme']); |
|---|
| 83 |
foreach ($dirs as $dir) |
|---|
| 84 |
{ |
|---|
| 85 |
if (is_dir($dir)) |
|---|
| 86 |
{ |
|---|
| 87 |
$this->getFilesystem()->mirror($dir, $moduleDir, $finder); |
|---|
| 88 |
break; |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
$finder = sfFinder::type('file')->name('*.php', '*.yml'); |
|---|
| 94 |
$this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $constants); |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|