| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfGeneratorConfigHandler extends sfYamlConfigHandler |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Executes this configuration handler. |
|---|
| 23 |
* |
|---|
| 24 |
* @param array $configFiles An array of absolute filesystem path to a configuration file |
|---|
| 25 |
* |
|---|
| 26 |
* @return string Data to be written to a cache file |
|---|
| 27 |
* |
|---|
| 28 |
* @throws sfConfigurationException If a requested configuration file does not exist or is not readable |
|---|
| 29 |
* @throws sfParseException If a requested configuration file is improperly formatted |
|---|
| 30 |
* @throws sfInitializationException If a generator.yml key check fails |
|---|
| 31 |
*/ |
|---|
| 32 |
public function execute($configFiles) |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
$config = self::getConfiguration($configFiles); |
|---|
| 36 |
if (!$config) |
|---|
| 37 |
{ |
|---|
| 38 |
return ''; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
if (!isset($config['generator'])) |
|---|
| 42 |
{ |
|---|
| 43 |
throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
$config = $config['generator']; |
|---|
| 47 |
|
|---|
| 48 |
if (!isset($config['class'])) |
|---|
| 49 |
{ |
|---|
| 50 |
throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
foreach (array('fields', 'list', 'edit') as $section) |
|---|
| 54 |
{ |
|---|
| 55 |
if (isset($config[$section])) |
|---|
| 56 |
{ |
|---|
| 57 |
throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0], $section)); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
$generatorManager = new sfGeneratorManager(sfContext::getInstance()->getConfiguration()); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
$generatorParam = (isset($config['param']) ? $config['param'] : array()); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
preg_match('#.*/modules/([^/]+)/#', $configFiles[0], $match); |
|---|
| 69 |
$generatorParam['moduleName'] = $match[1]; |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
$retval = "<?php\n". |
|---|
| 73 |
"// auto-generated by sfGeneratorConfigHandler\n". |
|---|
| 74 |
"// date: %s\n%s\n"; |
|---|
| 75 |
$retval = sprintf($retval, date('Y/m/d H:i:s'), self::getContent($generatorManager, $config['class'], $generatorParam)); |
|---|
| 76 |
|
|---|
| 77 |
return $retval; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
static public function getContent(sfGeneratorManager $generatorManager, $class, $parameters) |
|---|
| 81 |
{ |
|---|
| 82 |
$data = ''; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$r = new ReflectionClass($class); |
|---|
| 86 |
if ( |
|---|
| 87 |
(class_exists('sfPropelAdminGenerator') && ('sfPropelAdminGenerator' == $class || $r->isSubclassOf(new ReflectionClass('sfPropelAdminGenerator')))) |
|---|
| 88 |
|| |
|---|
| 89 |
(class_exists('sfDoctrineAdminGenerator') && ('sfDoctrineAdminGenerator' == $class || $r->isSubclassOf(new ReflectionClass('sfDoctrineAdminGenerator')))) |
|---|
| 90 |
) |
|---|
| 91 |
{ |
|---|
| 92 |
$data .= "require sfConfig::get('sf_symfony_lib_dir').'/plugins/sfCompat10Plugin/config/config.php';\n"; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
$data .= $generatorManager->generate($class, $parameters); |
|---|
| 96 |
|
|---|
| 97 |
return $data; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* @see sfConfigHandler |
|---|
| 102 |
*/ |
|---|
| 103 |
static public function getConfiguration(array $configFiles) |
|---|
| 104 |
{ |
|---|
| 105 |
return self::parseYamls($configFiles); |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|