Development

/branches/1.1/lib/config/sfLoader.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/config/sfLoader.class.php

Revision 9085, 2.9 kB (checked in by Carl.Vondrick, 6 years ago)

1.1: fixed @param phpdoc to fit specs in config (refs #2991)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfLoader is a class which contains the logic to look for files/classes in symfony.
13  *
14  * @package    symfony
15  * @subpackage util
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
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'; // module
35
36       if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/modules/'.$moduleName.'/lib/helper'))
37       {
38         $dirs = array_merge($dirs, $pluginDirs);                                  // module plugins
39       }
40     }
41
42     $dirs[] = sfConfig::get('sf_app_lib_dir').'/helper';                          // application
43
44     $dirs[] = sfConfig::get('sf_lib_dir').'/helper';                              // project
45
46     if ($pluginDirs = glob(sfConfig::get('sf_plugins_dir').'/*/lib/helper'))
47     {
48       $dirs = array_merge($dirs, $pluginDirs);                                    // plugins
49     }
50
51     $dirs[] = sfConfig::get('sf_symfony_lib_dir').'/helper';                      // symfony
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         // search in the include path
91         if ((@include_once('helper/'.$fileName)) != 1)
92         {
93           $dirs = array_merge($dirs, explode(PATH_SEPARATOR, get_include_path()));
94
95           // remove sf_root_dir from dirs
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
Note: See TracBrowser for help on using the browser.