/** * Search error handler class and return its instance * * @param string $subdir * @return ErrorHandlerStandard */ protected function _searchErrorHandler($subdir) { $controllerDir = PathManager::getControllerDirectory(); $dirs = array(); if ($subdir != '') { $dirs = explode('/', trim($subdir, '/')); } $handler = null; $path = ''; while (true) { $path = $controllerDir; if (count($dirs) > 0) { $path .= '/' . implode('/', $dirs); } if (file_exists($path . '/error_handler.php')) { require_once $path . '/error_handler.php'; $className = NameManager::toClass(implode('_', $dirs) . '_error_handler'); if (Loader::classExists($className)) { $handler = new $className(); break; } else { if (Loader::classExists('ErrorHandler')) { $handler = new ErrorHandler(); break; } } } if ($path == $controllerDir) { break; } array_pop($dirs); } if (!$handler instanceof ErrorHandlerStandard) { $handler = new ErrorHandlerStandard(); } return $handler; }
/** * Load a file that defines the controller class * * @param string $className The name of the controller class to read * @param string $subdir Controller subdirectory that contains the file * @return boolean */ public static function loadController($className, $subdir = '') { // verify the existence of a file $path = PathManager::getControllerDirectory(); if ($subdir != '') { $path .= '/' . trim($subdir, '/'); } $res = self::load($className, $path, false, false); return $res; }
/** * Get path sub directory path is removed from url * * @param array $params Parts of url path splitted by "/" * @return array $params Parts of url path sub directory path is removed. */ protected function _getSubdirRemovedParams($params) { $controllerDir = PathManager::getControllerDirectory(); $subDirs = $this->_getSubDirs($controllerDir . '/' . trim($this->_subdir, '/')); if (count($subDirs) > 0) { foreach ($params as $key => $param) { if (in_array($param, $subDirs)) { $this->_subdir .= '/' . $param; $newParams = $params; unset($newParams[$key]); $newParams = array_merge($newParams); return $this->_getSubdirRemovedParams($newParams); } else { return $params; } } } return $params; }