| 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 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 = $this->parseYamls($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(); |
|---|
| 63 |
$generatorManager->initialize(); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
$generatorParam = (isset($config['param']) ? $config['param'] : array()); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
preg_match('#.*/'.sfConfig::get('sf_app_module_dir_name').'/([^/]+)/#', $configFiles[0], $match); |
|---|
| 70 |
if ( 0 < count($match) && (0 < strlen($match[1]))) |
|---|
| 71 |
{ |
|---|
| 72 |
$generatorParam['moduleName'] = $match[1]; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
$data = $generatorManager->generate($config['class'], $generatorParam); |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
$retval = "<?php\n". |
|---|
| 79 |
"// auto-generated by sfGeneratorConfigHandler\n". |
|---|
| 80 |
"// date: %s\n%s\n"; |
|---|
| 81 |
$retval = sprintf($retval, date('Y/m/d H:i:s'), $data); |
|---|
| 82 |
|
|---|
| 83 |
return $retval; |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|