| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
class sfRootConfigHandler extends sfYamlConfigHandler |
|---|
| 21 |
{ |
|---|
| 22 |
|
|---|
| 23 |
* Executes this configuration handler |
|---|
| 24 |
* |
|---|
| 25 |
* @param array An array of absolute filesystem path to a configuration file |
|---|
| 26 |
* |
|---|
| 27 |
* @return string Data to be written to a cache file |
|---|
| 28 |
* |
|---|
| 29 |
* @throws sfConfigurationException If a requested configuration file does not exist or is not readable |
|---|
| 30 |
* @throws sfParseException If a requested configuration file is improperly formatted |
|---|
| 31 |
*/ |
|---|
| 32 |
public function execute($configFiles) |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
$config = $this->parseYamls($configFiles); |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
$moduleLevel = ($this->getParameterHolder()->get('module_level') === true) ? true : false; |
|---|
| 39 |
|
|---|
| 40 |
if ($moduleLevel) |
|---|
| 41 |
{ |
|---|
| 42 |
|
|---|
| 43 |
$moduleName = $this->getParameterHolder()->get('module_name'); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
$data = array(); |
|---|
| 48 |
$includes = array(); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
foreach ($config as $category => $keys) |
|---|
| 52 |
{ |
|---|
| 53 |
if ($moduleLevel) |
|---|
| 54 |
{ |
|---|
| 55 |
|
|---|
| 56 |
// root to the category |
|---|
| 57 |
$category = 'modules/'.$moduleName.'/'.$category; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
if (!isset($keys['class'])) |
|---|
| 61 |
{ |
|---|
| 62 |
|
|---|
| 63 |
$error = sprintf('Configuration file "%s" specifies category "%s" with missing class key', $configFiles[0], $category); |
|---|
| 64 |
throw new sfParseException($error); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
$class = $keys['class']; |
|---|
| 68 |
|
|---|
| 69 |
if (isset($keys['file'])) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
$file = $this->replaceConstants($keys['file']); |
|---|
| 73 |
$file = $this->replacePath($file); |
|---|
| 74 |
|
|---|
| 75 |
if (!is_readable($file)) |
|---|
| 76 |
{ |
|---|
| 77 |
|
|---|
| 78 |
$error = sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s"', $configFiles[0], $class, $file); |
|---|
| 79 |
throw new sfParseException($error); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
$includes[] = sprintf("require_once('%s');", $file); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
$parameters = (isset($keys['param']) ? var_export($keys['param'], true) : null); |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
$data[] = sprintf("\$this->handlers['%s'] = new %s();", $category, $class); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
$data[] = sprintf("\$this->handlers['%s']->initialize(%s);", $category, $parameters); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
$retval = sprintf("<?php\n" . |
|---|
| 98 |
"// auto-generated by sfRootConfigHandler\n". |
|---|
| 99 |
"// date: %s\n%s\n%s\n", |
|---|
| 100 |
date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data)); |
|---|
| 101 |
|
|---|
| 102 |
return $retval; |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|