当前位置: 首页>>代码示例>>PHP>>正文


PHP sfLoader::getControllerDirs方法代码示例

本文整理汇总了PHP中sfLoader::getControllerDirs方法的典型用法代码示例。如果您正苦于以下问题:PHP sfLoader::getControllerDirs方法的具体用法?PHP sfLoader::getControllerDirs怎么用?PHP sfLoader::getControllerDirs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfLoader的用法示例。


在下文中一共展示了sfLoader::getControllerDirs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: controllerExists

 /**
  * Looks for a controller and optionally throw exceptions if existence is required (i.e.
  * in the case of {@link getController()}).
  *
  * @param string  The name of the module
  * @param string  The name of the controller within the module
  * @param string  Either 'action' or 'component' depending on the type of controller to look for
  * @param boolean Whether to throw exceptions if the controller doesn't exist
  *
  * @throws sfConfigurationException thrown if the module is not enabled
  * @throws sfControllerException thrown if the controller doesn't exist and the $throwExceptions parameter is set to true
  *
  * @return boolean true if the controller exists, false otherwise
  */
 protected function controllerExists($moduleName, $controllerName, $extension, $throwExceptions)
 {
     $dirs = sfLoader::getControllerDirs($moduleName);
     foreach ($dirs as $dir => $checkEnabled) {
         // plugin module enabled?
         if ($checkEnabled && !in_array($moduleName, sfConfig::get('sf_enabled_modules')) && is_readable($dir)) {
             $error = 'The module "%s" is not enabled.';
             $error = sprintf($error, $moduleName);
             throw new sfConfigurationException($error);
         }
         // one action per file or one file for all actions
         $classFile = strtolower($extension);
         $classSuffix = ucfirst(strtolower($extension));
         $file = $dir . '/' . $controllerName . $classSuffix . '.class.php';
         if (is_readable($file)) {
             // action class exists
             require_once $file;
             $this->controllerClasses[$moduleName . '_' . $controllerName . '_' . $classSuffix] = $controllerName . $classSuffix;
             return true;
         }
         $module_file = $dir . '/' . $classFile . 's.class.php';
         if (is_readable($module_file)) {
             // module class exists
             require_once $module_file;
             if (!class_exists($moduleName . $classSuffix . 's', false)) {
                 if ($throwExceptions) {
                     throw new sfControllerException(sprintf('There is no "%s" class in your action file "%s".', $moduleName . $classSuffix . 's', $module_file));
                 }
                 return false;
             }
             // action is defined in this class?
             if (!in_array('execute' . ucfirst($controllerName), get_class_methods($moduleName . $classSuffix . 's'))) {
                 if ($throwExceptions) {
                     throw new sfControllerException(sprintf('There is no "%s" method in your action class "%s"', 'execute' . ucfirst($controllerName), $moduleName . $classSuffix . 's'));
                 }
                 return false;
             }
             $this->controllerClasses[$moduleName . '_' . $controllerName . '_' . $classSuffix] = $moduleName . $classSuffix . 's';
             return true;
         }
     }
     // send an exception if debug
     if ($throwExceptions && sfConfig::get('sf_debug')) {
         $dirs = array_keys($dirs);
         // remove sf_root_dir from dirs
         foreach ($dirs as &$dir) {
             $dir = str_replace(sfConfig::get('sf_root_dir'), '%SF_ROOT_DIR%', $dir);
         }
         throw new sfControllerException(sprintf('{sfController} controller "%s/%s" does not exist in: %s', $moduleName, $controllerName, implode(', ', $dirs)));
     }
     return false;
 }
开发者ID:net7,项目名称:Talia-CMS,代码行数:66,代码来源:sfController.class.php


注:本文中的sfLoader::getControllerDirs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。