| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
require_once(dirname(__FILE__).'/ysfConfigDimension.class.php'); |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
class ysfProjectConfiguration extends sfProjectConfiguration |
|---|
| 27 |
{ |
|---|
| 28 |
protected $dimension = null; |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
* Sets the project dimension. |
|---|
| 32 |
* |
|---|
| 33 |
* @param array The configuration dimension as an array |
|---|
| 34 |
*/ |
|---|
| 35 |
public function setDimension($dimension) |
|---|
| 36 |
{ |
|---|
| 37 |
if ($dimension === null || $dimension === false) |
|---|
| 38 |
{ |
|---|
| 39 |
$this->dimension = null; |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
$this->setCacheDir($this->getRootDir().'/cache'); |
|---|
| 43 |
} |
|---|
| 44 |
else |
|---|
| 45 |
{ |
|---|
| 46 |
try |
|---|
| 47 |
{ |
|---|
| 48 |
if(!$this->hasDimension()) |
|---|
| 49 |
{ |
|---|
| 50 |
$this->dimension = new ysfConfigDimension($this->getEventDispatcher(), (!isset($this->debug) || (isset($this->debug) && $this->debug === true)) ? new sfNoCache() : new sfAPCCache(array('prefix' => 'symfony.dimensions.config.default:'.$this->application.':'.$this->environment, 'automatic_cleaning_factor' => 0, 'lifetime' => 86400))); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
$this->dimension->set($dimension); |
|---|
| 55 |
|
|---|
| 56 |
sfConfig::set('sf_dimension', $this->dimension->getName()); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
$this->setCacheDir($this->getRootDir().'/cache/'.$this->dimension->getName()); |
|---|
| 60 |
} |
|---|
| 61 |
catch (sfException $e) |
|---|
| 62 |
{ |
|---|
| 63 |
if(method_exists($e, 'asResponse')) |
|---|
| 64 |
{ |
|---|
| 65 |
|
|---|
| 66 |
$e->asResponse()->send(); exit; |
|---|
| 67 |
} |
|---|
| 68 |
else |
|---|
| 69 |
{ |
|---|
| 70 |
echo $e->getMessage(); exit; |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
* Returns the project dimension. |
|---|
| 78 |
* |
|---|
| 79 |
* @return ysfConfigDimension The configuration dimension |
|---|
| 80 |
*/ |
|---|
| 81 |
public function getDimension() |
|---|
| 82 |
{ |
|---|
| 83 |
return $this->dimension; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
* Has a dimension been set? |
|---|
| 88 |
* |
|---|
| 89 |
* @return boolean Returns true or false depending on whether a dimension has been set or not. |
|---|
| 90 |
*/ |
|---|
| 91 |
public function hasDimension() |
|---|
| 92 |
{ |
|---|
| 93 |
return !is_null($this->dimension); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
* Gets directories where model classes are stored. |
|---|
| 98 |
* |
|---|
| 99 |
* @return array An array of directories |
|---|
| 100 |
*/ |
|---|
| 101 |
public function getModelDirs() |
|---|
| 102 |
{ |
|---|
| 103 |
|
|---|
| 104 |
if ($this->hasDimension()) |
|---|
| 105 |
{ |
|---|
| 106 |
|
|---|
| 107 |
if($this->dimension->getCache()->has('sf_model_dirs')) |
|---|
| 108 |
{ |
|---|
| 109 |
return $this->dimension->getCache()->get('sf_model_dirs'); |
|---|
| 110 |
} |
|---|
| 111 |
else |
|---|
| 112 |
{ |
|---|
| 113 |
$dimensions = array_reverse($this->dimension->getCascade()); |
|---|
| 114 |
|
|---|
| 115 |
$dirs = array(sfConfig::get('sf_lib_dir').'/model'); |
|---|
| 116 |
|
|---|
| 117 |
// extend base dirs and add dimension cascade, checking dir exists |
|---|
| 118 |
foreach ($dimensions as $dimension) |
|---|
| 119 |
{ |
|---|
| 120 |
if(is_readable($dirs[0].'/'.$dimension)) |
|---|
| 121 |
{ |
|---|
| 122 |
array_unshift($dirs, $dirs[0].'/'.$dimension); |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/model')) |
|---|
| 127 |
{ |
|---|
| 128 |
foreach ($pluginDirs as $dir) |
|---|
| 129 |
{ |
|---|
| 130 |
|
|---|
| 131 |
foreach ($dimensions as $dimension) |
|---|
| 132 |
{ |
|---|
| 133 |
if(is_readable($dir.'/'.$dimension)) |
|---|
| 134 |
{ |
|---|
| 135 |
array_unshift($pluginDirs, $dir.'/'.$dimension); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
$this->dimension->getCache()->set('sf_model_dirs', $dirs); |
|---|
| 144 |
} |
|---|
| 145 |
} |
|---|
| 146 |
else |
|---|
| 147 |
{ |
|---|
| 148 |
$dirs = parent::getModelDirs(); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
return $dirs; |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
* Gets directories where template files are stored for a generator class and a specific theme. |
|---|
| 156 |
* |
|---|
| 157 |
* @param string The generator class name |
|---|
| 158 |
* @param string The theme name |
|---|
| 159 |
* |
|---|
| 160 |
* @return array An array of directories |
|---|
| 161 |
*/ |
|---|
| 162 |
public function getGeneratorTemplateDirs($class, $theme) |
|---|
| 163 |
{ |
|---|
| 164 |
|
|---|
| 165 |
if ($this->hasDimension()) |
|---|
| 166 |
{ |
|---|
| 167 |
$cacheKey = sprintf('sf_generator_template_dirs_%s_%s', $class, $theme); |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
if($this->dimension->getCache()->has($cacheKey)) |
|---|
| 171 |
{ |
|---|
| 172 |
$dirs = $this->dimension->getCache()->get($cacheKey); |
|---|
| 173 |
} |
|---|
| 174 |
else |
|---|
| 175 |
{ |
|---|
| 176 |
$dimensions = $this->dimension->getCascade(); |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
$dirs = array(); |
|---|
| 180 |
|
|---|
| 181 |
if (is_readable(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template')) |
|---|
| 182 |
{ |
|---|
| 183 |
$dir = sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template'; |
|---|
| 184 |
|
|---|
| 185 |
// extend base dirs and add dimension cascade + checking dir exists |
|---|
| 186 |
foreach ($dimensions as $dimension) |
|---|
| 187 |
{ |
|---|
| 188 |
if(is_readable($dir.'/'.$dimension)) |
|---|
| 189 |
{ |
|---|
| 190 |
array_push($dirs, $dir.'/'.$dimension); |
|---|
| 191 |
} |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
array_push($dirs, $dir); |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/data/generator/'.$class.'/'.$theme.'/template')) |
|---|
| 198 |
{ |
|---|
| 199 |
foreach ($pluginDirs as $dir) |
|---|
| 200 |
{ |
|---|
| 201 |
foreach ($dimensions as $dimension) |
|---|
| 202 |
{ |
|---|
| 203 |
if(is_readable($dir.'/'.$dimension)) |
|---|
| 204 |
{ |
|---|
| 205 |
array_push($dirs, $dir.'/'.$dimension); |
|---|
| 206 |
} |
|---|
| 207 |
} |
|---|
| 208 |
array_push($dirs, $dir); |
|---|
| 209 |
} |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
if ($bundledPluginDirs = glob(sfConfig::get('sf_symfony_lib_dir').'/plugins/*/data/generator/'.$class.'/'.$theme.'/template')) |
|---|
| 213 |
{ |
|---|
| 214 |
$dirs = array_merge($dirs, $bundledPluginDirs); |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
$this->dimension->getCache()->set($cacheKey, $dirs); |
|---|
| 219 |
} |
|---|
| 220 |
} |
|---|
| 221 |
else |
|---|
| 222 |
{ |
|---|
| 223 |
$dirs = parent::getGeneratorTemplateDirs($class, $theme); |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
return $dirs; |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
* Gets directories where the skeleton is stored for a generator class and a specific theme. |
|---|
| 231 |
* |
|---|
| 232 |
* @param string The generator class name |
|---|
| 233 |
* @param string The theme name |
|---|
| 234 |
* |
|---|
| 235 |
* @return array An array of directories |
|---|
| 236 |
*/ |
|---|
| 237 |
public function getGeneratorSkeletonDirs($class, $theme) |
|---|
| 238 |
{ |
|---|
| 239 |
|
|---|
| 240 |
if ($this->hasDimension()) |
|---|
| 241 |
{ |
|---|
| 242 |
$cacheKey = sprintf('sf_generator_skeleton_dirs_%s_%s', $class, $theme); |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
if($this->dimension->getCache()->has($cacheKey)) |
|---|
| 246 |
{ |
|---|
| 247 |
$dirs = $this->dimension->getCache()->get($cacheKey); |
|---|
| 248 |
} |
|---|
| 249 |
else |
|---|
| 250 |
{ |
|---|
| 251 |
$dimensions = $this->dimension->getCascade(); |
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
$dirs = array(); |
|---|
| 255 |
|
|---|
| 256 |
if(is_readable(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton')) |
|---|
| 257 |
{ |
|---|
| 258 |
$dir = sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton'; |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
foreach ($dimensions as $dimension) |
|---|
| 262 |
{ |
|---|
| 263 |
if(is_readable($dir.'/'.$dimension)) |
|---|
| 264 |
{ |
|---|
| 265 |
array_push($dirs, $dir.'/'.$dimension); |
|---|
| 266 |
} |
|---|
| 267 |
} |
|---|
| 268 |
array_push($dirs, $dir); |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/data/generator/'.$class.'/'.$theme.'/skeleton')) |
|---|
| 272 |
{ |
|---|
| 273 |
foreach ($pluginDirs as $dir) |
|---|
| 274 |
{ |
|---|
| 275 |
foreach ($dimensions as $dimension) |
|---|
| 276 |
{ |
|---|
| 277 |
if(is_readable($dir.'/'.$dimension)) |
|---|
| 278 |
{ |
|---|
| 279 |
array_push($dirs, $dir.'/'.$dimension); |
|---|
| 280 |
} |
|---|
| 281 |
} |
|---|
| 282 |
array_push($dirs, $dir); |
|---|
| 283 |
} |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
if ($bundledPluginDirs = glob(sfConfig::get('sf_symfony_lib_dir').'/plugins/*/data/generator/'.$class.'/'.$theme.'/skeleton')) |
|---|
| 287 |
{ |
|---|
| 288 |
$dirs = array_merge($dirs, $bundledPluginDirs); |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
$this->dimension->getCache()->set($cacheKey, $dirs); |
|---|
| 293 |
} |
|---|
| 294 |
} |
|---|
| 295 |
else |
|---|
| 296 |
{ |
|---|
| 297 |
$dirs = parent::getGeneratorSkeletonDirs($class, $theme); |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
return $dirs; |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
* Gets the template to use for a generator class. |
|---|
| 305 |
* |
|---|
| 306 |
* @param string The generator class name |
|---|
| 307 |
* @param string The theme name |
|---|
| 308 |
* @param string The template path |
|---|
| 309 |
* |
|---|
| 310 |
* @return string A template path |
|---|
| 311 |
* |
|---|
| 312 |
* @throws sfException |
|---|
| 313 |
*/ |
|---|
| 314 |
public function getGeneratorTemplate($class, $theme, $path) |
|---|
| 315 |
{ |
|---|
| 316 |
|
|---|
| 317 |
if ($this->hasDimension()) |
|---|
| 318 |
{ |
|---|
| 319 |
$cacheKey = sprintf('sf_generator_templates_%s_%s_%s', $class, $theme, $path); |
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
if($this->dimension->getCache()->has($cacheKey)) |
|---|
| 323 |
{ |
|---|
| 324 |
$dirs = $this->dimension->getCache()->get($cacheKey); |
|---|
| 325 |
} |
|---|
| 326 |
else |
|---|
| 327 |
{ |
|---|
| 328 |
|
|---|
| 329 |
$dirs = $this->getGeneratorTemplateDirs($class, $theme); |
|---|
| 330 |
|
|---|
| 331 |
foreach ($dirs as $dir) |
|---|
| 332 |
{ |
|---|
| 333 |
if (is_readable($dir.'/'.$path)) |
|---|
| 334 |
{ |
|---|
| 335 |
|
|---|
| 336 |
$this->dimension->getCache()->set($cacheKey, $dir.'/'.$path); |
|---|
| 337 |
|
|---|
| 338 |
return $dir.'/'.$path; |
|---|
| 339 |
} |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
throw new sfException(sprintf('Unable to load "%s" generator template in: %s.', $path, implode(', ', $dirs))); |
|---|
| 343 |
} |
|---|
| 344 |
} |
|---|
| 345 |
else |
|---|
| 346 |
{ |
|---|
| 347 |
$dirs = parent::getGeneratorTemplate($class, $theme, $path); |
|---|
| 348 |
} |
|---|
| 349 |
|
|---|
| 350 |
return $dirs; |
|---|
| 351 |
} |
|---|
| 352 |
} |
|---|
| 353 |
|
|---|