/** * 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; }