| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class sfCompileConfigHandler extends sfYamlConfigHandler |
|---|
| 23 |
{ |
|---|
| 24 |
|
|---|
| 25 |
* Executes this configuration handler. |
|---|
| 26 |
* |
|---|
| 27 |
* @param array $configFiles An array of absolute filesystem path to a configuration file |
|---|
| 28 |
* |
|---|
| 29 |
* @return string Data to be written to a cache file |
|---|
| 30 |
* |
|---|
| 31 |
* @throws sfConfigurationException If a requested configuration file does not exist or is not readable |
|---|
| 32 |
* @throws sfParseException If a requested configuration file is improperly formatted |
|---|
| 33 |
*/ |
|---|
| 34 |
public function execute($configFiles) |
|---|
| 35 |
{ |
|---|
| 36 |
|
|---|
| 37 |
$config = self::getConfiguration($configFiles); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$data = ''; |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
foreach ($config as $file) |
|---|
| 44 |
{ |
|---|
| 45 |
if (!is_readable($file)) |
|---|
| 46 |
{ |
|---|
| 47 |
|
|---|
| 48 |
throw new sfParseException(sprintf('Configuration file "%s" specifies nonexistent or unreadable file "%s".', $configFiles[0], $file)); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
$contents = file_get_contents($file); |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
if (!sfConfig::get('sf_debug')) |
|---|
| 55 |
{ |
|---|
| 56 |
$contents = sfToolkit::stripComments($contents); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
/* $contents = preg_replace_callback(array('#(require|include)(_once)?\((sfContext::getInstance\(\)\->getConfigCache\(\)|\$configCache)->checkConfig\(\'config/([^\']+)\'\)\);#m', |
|---|
| 61 |
'#()()(sfContext::getInstance\(\)\->getConfigCache\(\)|\$configCache)->import\(\'config/([^\']+)\'(, false)?\);#m'), |
|---|
| 62 |
array($this, 'insertConfigFileCallback'), $contents); |
|---|
| 63 |
*/ |
|---|
| 64 |
// strip php tags |
|---|
| 65 |
$contents = sfToolkit::pregtr($contents, array('/^\s*<\?(php)?/m' => '', |
|---|
| 66 |
'/^\s*\?>/m' => '')); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
$contents = str_replace("\r", "\n", $contents); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
$contents = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $contents); |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
$data .= "\n".$contents; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
$retval = sprintf("<?php\n". |
|---|
| 80 |
"// auto-generated by sfCompileConfigHandler\n". |
|---|
| 81 |
"// date: %s\n%s\n", |
|---|
| 82 |
date('Y/m/d H:i:s'), $data); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
file_put_contents(sfConfig::get('sf_config_cache_dir').'/VERSION', SYMFONY_VERSION); |
|---|
| 86 |
|
|---|
| 87 |
return $retval; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
* Callback for configuration file insertion in the cache. |
|---|
| 92 |
* |
|---|
| 93 |
*/ |
|---|
| 94 |
protected function insertConfigFileCallback($matches) |
|---|
| 95 |
{ |
|---|
| 96 |
$configFile = 'config/'.$matches[4]; |
|---|
| 97 |
|
|---|
| 98 |
$configCache = sfContext::getInstance()->getConfigCache(); |
|---|
| 99 |
$configCache->checkConfig($configFile); |
|---|
| 100 |
|
|---|
| 101 |
$config = "// '$configFile' config file\n".file_get_contents($configCache->getCacheName($configFile)); |
|---|
| 102 |
|
|---|
| 103 |
return $config; |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
* @see sfConfigHandler |
|---|
| 108 |
*/ |
|---|
| 109 |
static public function getConfiguration(array $configFiles) |
|---|
| 110 |
{ |
|---|
| 111 |
$config = array(); |
|---|
| 112 |
foreach ($configFiles as $configFile) |
|---|
| 113 |
{ |
|---|
| 114 |
$config = array_merge($config, self::parseYaml($configFile)); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
return self::replacePath(self::replaceConstants($config)); |
|---|
| 118 |
} |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|