| 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 the helper directories for a given module name. |
|---|
| 23 |
* |
|---|
| 24 |
* @param string $moduleName The module name |
|---|
| 25 |
* |
|---|
| 26 |
* @return array An array of directories |
|---|
| 27 |
*/ |
|---|
| 28 |
static public function getHelperDirs($moduleName = '') |
|---|
| 29 |
{ |
|---|
| 30 |
$dirs = array(); |
|---|
| 31 |
|
|---|
| 32 |
if ($moduleName) |
|---|
| 33 |
{ |
|---|
| 34 |
$dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/lib/helper'; |
|---|
| 35 |
|
|---|
| 36 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$moduleName.'/lib/helper')) |
|---|
| 37 |
{ |
|---|
| 38 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 39 |
} |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
$dirs[] = sfConfig::get('sf_app_lib_dir').'/helper'; |
|---|
| 43 |
|
|---|
| 44 |
$dirs[] = sfConfig::get('sf_lib_dir').'/helper'; |
|---|
| 45 |
|
|---|
| 46 |
if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/helper')) |
|---|
| 47 |
{ |
|---|
| 48 |
$dirs = array_merge($dirs, $pluginDirs); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
$dirs[] = sfConfig::get('sf_symfony_lib_dir').'/helper'; |
|---|
| 52 |
|
|---|
| 53 |
return $dirs; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
* Loads helpers. |
|---|
| 58 |
* |
|---|
| 59 |
* @param array $helpers An array of helpers to load |
|---|
| 60 |
* @param string $moduleName A module name (optional) |
|---|
| 61 |
* |
|---|
| 62 |
* @throws sfViewException |
|---|
| 63 |
*/ |
|---|
| 64 |
static public function loadHelpers($helpers, $moduleName = '') |
|---|
| 65 |
{ |
|---|
| 66 |
static $loaded = array(); |
|---|
| 67 |
|
|---|
| 68 |
$dirs = self::getHelperDirs($moduleName); |
|---|
| 69 |
foreach ((array) $helpers as $helperName) |
|---|
| 70 |
{ |
|---|
| 71 |
if (isset($loaded[$helperName])) |
|---|
| 72 |
{ |
|---|
| 73 |
continue; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
$fileName = $helperName.'Helper.php'; |
|---|
| 77 |
foreach ($dirs as $dir) |
|---|
| 78 |
{ |
|---|
| 79 |
$included = false; |
|---|
| 80 |
if (is_readable($dir.'/'.$fileName)) |
|---|
| 81 |
{ |
|---|
| 82 |
include_once($dir.'/'.$fileName); |
|---|
| 83 |
$included = true; |
|---|
| 84 |
break; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
if (!$included) |
|---|
| 89 |
{ |
|---|
| 90 |
|
|---|
| 91 |
if ((@include_once('helper/'.$fileName)) != 1) |
|---|
| 92 |
{ |
|---|
| 93 |
$dirs = array_merge($dirs, explode(PATH_SEPARATOR, get_include_path())); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
foreach ($dirs as &$dir) |
|---|
| 97 |
{ |
|---|
| 98 |
$dir = str_replace('%SF_ROOT_DIR%', sfConfig::get('sf_root_dir'), $dir); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
throw new sfViewException(sprintf('Unable to load "%sHelper.php" helper in: %s.', $helperName, implode(', ', $dirs))); |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
$loaded[$helperName] = true; |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|