| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfLoader |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Gets directories where model classes are stored. The order of returned paths is lowest precedence |
|---|
| 23 |
* to highest precedence. |
|---|
| 24 |
* |
|---|
| 25 |
* @return array An array of directories |
|---|
| 26 |
*/ |
|---|
| 27 |
static public function getModelDirs() |
|---|
| 28 |
{ |
|---|
| 29 |
$dirs = array(); |
|---|
| 30 |
|
|---|
| 31 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/model')) |
|---|
| 32 |
{ |
|---|
| 33 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
$dirs[] = sfConfig::get('sf_lib_dir') ? sfConfig::get('sf_lib_dir').'/model' : 'lib/model'; |
|---|
| 37 |
|
|---|
| 38 |
return $dirs; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
* Gets directories where controller classes are stored for a given module. |
|---|
| 43 |
* |
|---|
| 44 |
* @param string The module name |
|---|
| 45 |
* |
|---|
| 46 |
* @return array An array of directories |
|---|
| 47 |
*/ |
|---|
| 48 |
static public function getControllerDirs($moduleName) |
|---|
| 49 |
{ |
|---|
| 50 |
$suffix = $moduleName.'/'.sfConfig::get('sf_app_module_action_dir_name'); |
|---|
| 51 |
|
|---|
| 52 |
$dirs = array(); |
|---|
| 53 |
foreach (sfConfig::get('sf_module_dirs', array()) as $key => $value) |
|---|
| 54 |
{ |
|---|
| 55 |
$dirs[$key.'/'.$suffix] = $value; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
$dirs[sfConfig::get('sf_app_module_dir').'/'.$suffix] = false; |
|---|
| 59 |
|
|---|
| 60 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$suffix)) |
|---|
| 61 |
{ |
|---|
| 62 |
$dirs = array_merge($dirs, array_combine($pluginDirs, array_fill(0, count($pluginDirs), true))); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
$dirs[sfConfig::get('sf_symfony_data_dir').'/modules/'.$suffix] = true; |
|---|
| 66 |
|
|---|
| 67 |
return $dirs; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
* Gets directories where template files are stored for a given module. |
|---|
| 72 |
* |
|---|
| 73 |
* @param string The module name |
|---|
| 74 |
* |
|---|
| 75 |
* @return array An array of directories |
|---|
| 76 |
*/ |
|---|
| 77 |
static public function getTemplateDirs($moduleName) |
|---|
| 78 |
{ |
|---|
| 79 |
$suffix = $moduleName.'/'.sfConfig::get('sf_app_module_template_dir_name'); |
|---|
| 80 |
|
|---|
| 81 |
$dirs = array(); |
|---|
| 82 |
foreach (sfConfig::get('sf_module_dirs', array()) as $key => $value) |
|---|
| 83 |
{ |
|---|
| 84 |
$dirs[] = $key.'/'.$suffix; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
$dirs[] = sfConfig::get('sf_app_module_dir').'/'.$suffix; |
|---|
| 88 |
|
|---|
| 89 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$suffix)) |
|---|
| 90 |
{ |
|---|
| 91 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
$dirs[] = sfConfig::get('sf_symfony_data_dir').'/modules/'.$suffix; |
|---|
| 95 |
$dirs[] = sfConfig::get('sf_module_cache_dir').'/auto'.ucfirst($suffix); |
|---|
| 96 |
|
|---|
| 97 |
return $dirs; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* Gets the template directory to use for a given module and template file. |
|---|
| 102 |
* |
|---|
| 103 |
* @param string The module name |
|---|
| 104 |
* @param string The template file |
|---|
| 105 |
* |
|---|
| 106 |
* @return string A template directory |
|---|
| 107 |
*/ |
|---|
| 108 |
static public function getTemplateDir($moduleName, $templateFile) |
|---|
| 109 |
{ |
|---|
| 110 |
$dirs = self::getTemplateDirs($moduleName); |
|---|
| 111 |
foreach ($dirs as $dir) |
|---|
| 112 |
{ |
|---|
| 113 |
if (is_readable($dir.'/'.$templateFile)) |
|---|
| 114 |
{ |
|---|
| 115 |
return $dir; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
return null; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
* Gets the template to use for a given module and template file. |
|---|
| 124 |
* |
|---|
| 125 |
* @param string The module name |
|---|
| 126 |
* @param string The template file |
|---|
| 127 |
* |
|---|
| 128 |
* @return string A template path |
|---|
| 129 |
*/ |
|---|
| 130 |
static public function getTemplatePath($moduleName, $templateFile) |
|---|
| 131 |
{ |
|---|
| 132 |
$dir = self::getTemplateDir($moduleName, $templateFile); |
|---|
| 133 |
|
|---|
| 134 |
return $dir ? $dir.'/'.$templateFile : null; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
* Gets the i18n directory to use for a given module. |
|---|
| 139 |
* |
|---|
| 140 |
* @param string The module name |
|---|
| 141 |
* |
|---|
| 142 |
* @return string An i18n directory |
|---|
| 143 |
*/ |
|---|
| 144 |
static public function getI18NDir($moduleName) |
|---|
| 145 |
{ |
|---|
| 146 |
$suffix = $moduleName.'/'.sfConfig::get('sf_app_module_i18n_dir_name'); |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
$dir = sfConfig::get('sf_app_module_dir').'/'.$suffix; |
|---|
| 150 |
if (is_dir($dir)) |
|---|
| 151 |
{ |
|---|
| 152 |
return $dir; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
$dirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$suffix); |
|---|
| 157 |
if (isset($dirs[0])) |
|---|
| 158 |
{ |
|---|
| 159 |
return $dirs[0]; |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
* Gets directories where template files are stored for a generator class and a specific theme. |
|---|
| 165 |
* |
|---|
| 166 |
* @param string The generator class name |
|---|
| 167 |
* @param string The theme name |
|---|
| 168 |
* |
|---|
| 169 |
* @return array An array of directories |
|---|
| 170 |
*/ |
|---|
| 171 |
static public function getGeneratorTemplateDirs($class, $theme) |
|---|
| 172 |
{ |
|---|
| 173 |
$dirs = array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template'); |
|---|
| 174 |
|
|---|
| 175 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/data/generator/'.$class.'/'.$theme.'/template')) |
|---|
| 176 |
{ |
|---|
| 177 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
$dirs[] = sfConfig::get('sf_symfony_data_dir').'/generator/'.$class.'/default/template'; |
|---|
| 181 |
|
|---|
| 182 |
return $dirs; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
* Gets directories where the skeleton is stored for a generator class and a specific theme. |
|---|
| 187 |
* |
|---|
| 188 |
* @param string The generator class name |
|---|
| 189 |
* @param string The theme name |
|---|
| 190 |
* |
|---|
| 191 |
* @return array An array of directories |
|---|
| 192 |
*/ |
|---|
| 193 |
static public function getGeneratorSkeletonDirs($class, $theme) |
|---|
| 194 |
{ |
|---|
| 195 |
$dirs = array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton'); |
|---|
| 196 |
|
|---|
| 197 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/data/generator/'.$class.'/'.$theme.'/skeleton')) |
|---|
| 198 |
{ |
|---|
| 199 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
$dirs[] = sfConfig::get('sf_symfony_data_dir').'/generator/'.$class.'/default/skeleton'; |
|---|
| 203 |
|
|---|
| 204 |
return $dirs; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
* Gets the template to use for a generator class. |
|---|
| 209 |
* |
|---|
| 210 |
* @param string The generator class name |
|---|
| 211 |
* @param string The theme name |
|---|
| 212 |
* @param string The template path |
|---|
| 213 |
* |
|---|
| 214 |
* @return string A template path |
|---|
| 215 |
* |
|---|
| 216 |
* @throws sfException |
|---|
| 217 |
*/ |
|---|
| 218 |
static public function getGeneratorTemplate($class, $theme, $path) |
|---|
| 219 |
{ |
|---|
| 220 |
$dirs = self::getGeneratorTemplateDirs($class, $theme); |
|---|
| 221 |
foreach ($dirs as $dir) |
|---|
| 222 |
{ |
|---|
| 223 |
if (is_readable($dir.'/'.$path)) |
|---|
| 224 |
{ |
|---|
| 225 |
return $dir.'/'.$path; |
|---|
| 226 |
} |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
throw new sfException(sprintf('Unable to load "%s" generator template in: %s', $path, implode(', ', $dirs))); |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
* Gets the configuration file paths for a given relative configuration path. |
|---|
| 234 |
* |
|---|
| 235 |
* @param string The configuration path |
|---|
| 236 |
* |
|---|
| 237 |
* @return array An array of paths |
|---|
| 238 |
*/ |
|---|
| 239 |
static public function getConfigPaths($configPath) |
|---|
| 240 |
{ |
|---|
| 241 |
$globalConfigPath = basename(dirname($configPath)).'/'.basename($configPath); |
|---|
| 242 |
|
|---|
| 243 |
$files = array( |
|---|
| 244 |
sfConfig::get('sf_symfony_data_dir').'/'.$globalConfigPath, |
|---|
| 245 |
sfConfig::get('sf_symfony_data_dir').'/'.$configPath, |
|---|
| 246 |
); |
|---|
| 247 |
|
|---|
| 248 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/'.$globalConfigPath)) |
|---|
| 249 |
{ |
|---|
| 250 |
$files = array_merge($files, $pluginDirs); |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
$files = array_merge($files, array( |
|---|
| 254 |
sfConfig::get('sf_root_dir').'/'.$globalConfigPath, |
|---|
| 255 |
sfConfig::get('sf_root_dir').'/'.$configPath, |
|---|
| 256 |
sfConfig::get('sf_app_dir').'/'.$globalConfigPath, |
|---|
| 257 |
sfConfig::get('sf_cache_dir').'/'.$configPath, |
|---|
| 258 |
)); |
|---|
| 259 |
|
|---|
| 260 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/'.$configPath)) |
|---|
| 261 |
{ |
|---|
| 262 |
$files = array_merge($files, $pluginDirs); |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
$files[] = sfConfig::get('sf_app_dir').'/'.$configPath; |
|---|
| 266 |
|
|---|
| 267 |
$configs = array(); |
|---|
| 268 |
foreach (array_unique($files) as $file) |
|---|
| 269 |
{ |
|---|
| 270 |
if (is_readable($file)) |
|---|
| 271 |
{ |
|---|
| 272 |
$configs[] = $file; |
|---|
| 273 |
} |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
return $configs; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
* Gets the helper directories for a given module name. |
|---|
| 281 |
* |
|---|
| 282 |
* @param string The module name |
|---|
| 283 |
* |
|---|
| 284 |
* @return array An array of directories |
|---|
| 285 |
*/ |
|---|
| 286 |
static public function getHelperDirs($moduleName = '') |
|---|
| 287 |
{ |
|---|
| 288 |
$dirs = array(); |
|---|
| 289 |
|
|---|
| 290 |
if ($moduleName) |
|---|
| 291 |
{ |
|---|
| 292 |
$dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/'.sfConfig::get('sf_app_module_lib_dir_name').'/helper'; |
|---|
| 293 |
|
|---|
| 294 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$moduleName.'/lib/helper')) |
|---|
| 295 |
{ |
|---|
| 296 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 297 |
} |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
$dirs[] = sfConfig::get('sf_app_lib_dir').'/helper'; |
|---|
| 301 |
|
|---|
| 302 |
$dirs[] = sfConfig::get('sf_lib_dir').'/helper'; |
|---|
| 303 |
|
|---|
| 304 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/helper')) |
|---|
| 305 |
{ |
|---|
| 306 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 307 |
} |
|---|
| 308 |
|
|---|
| 309 |
$dirs[] = sfConfig::get('sf_symfony_lib_dir').'/helper'; |
|---|
| 310 |
|
|---|
| 311 |
return $dirs; |
|---|
| 312 |
} |
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
* Loads helpers. |
|---|
| 316 |
* |
|---|
| 317 |
* @param array An array of helpers to load |
|---|
| 318 |
* @param string A module name (optional) |
|---|
| 319 |
* |
|---|
| 320 |
* @throws sfViewException |
|---|
| 321 |
*/ |
|---|
| 322 |
static public function loadHelpers($helpers, $moduleName = '') |
|---|
| 323 |
{ |
|---|
| 324 |
static $loaded = array(); |
|---|
| 325 |
|
|---|
| 326 |
$dirs = self::getHelperDirs($moduleName); |
|---|
| 327 |
foreach ((array) $helpers as $helperName) |
|---|
| 328 |
{ |
|---|
| 329 |
if (isset($loaded[$helperName])) |
|---|
| 330 |
{ |
|---|
| 331 |
continue; |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
$fileName = $helperName.'Helper.php'; |
|---|
| 335 |
foreach ($dirs as $dir) |
|---|
| 336 |
{ |
|---|
| 337 |
$included = false; |
|---|
| 338 |
if (is_readable($dir.'/'.$fileName)) |
|---|
| 339 |
{ |
|---|
| 340 |
include($dir.'/'.$fileName); |
|---|
| 341 |
$included = true; |
|---|
| 342 |
break; |
|---|
| 343 |
} |
|---|
| 344 |
} |
|---|
| 345 |
|
|---|
| 346 |
if (!$included) |
|---|
| 347 |
{ |
|---|
| 348 |
|
|---|
| 349 |
if ((@include('helper/'.$fileName)) != 1) |
|---|
| 350 |
{ |
|---|
| 351 |
$dirs = array_merge($dirs, explode(PATH_SEPARATOR, get_include_path())); |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
foreach ($dirs as &$dir) |
|---|
| 355 |
{ |
|---|
| 356 |
$dir = str_replace('%SF_ROOT_DIR%', sfConfig::get('sf_root_dir'), $dir); |
|---|
| 357 |
} |
|---|
| 358 |
|
|---|
| 359 |
throw new sfViewException(sprintf('Unable to load "%sHelper.php" helper in: %s', $helperName, implode(', ', $dirs))); |
|---|
| 360 |
} |
|---|
| 361 |
} |
|---|
| 362 |
|
|---|
| 363 |
$loaded[$helperName] = true; |
|---|
| 364 |
} |
|---|
| 365 |
} |
|---|
| 366 |
|
|---|
| 367 |
static public function loadPluginConfig() |
|---|
| 368 |
{ |
|---|
| 369 |
if ($pluginConfigs = glob(sfConfig::get('sf_plugins_dir').'/*/config/config.php')) |
|---|
| 370 |
{ |
|---|
| 371 |
foreach ($pluginConfigs as $config) |
|---|
| 372 |
{ |
|---|
| 373 |
include($config); |
|---|
| 374 |
} |
|---|
| 375 |
} |
|---|
| 376 |
} |
|---|
| 377 |
} |
|---|
| 378 |
|
|---|