/** * Load a file that defines the view script class and return that instance * * @param string $className The name of the view script class to get instance * @param string $subdir View script subdirectory that contains the file * @return boolean|ViewScript * @throws ClassUndefinedException */ public static function getViewScriptInstance($className, $subdir = '') { $res = self::loadViewScript($className, $subdir); if ($res == false) { return false; } $instance = null; if ($subdir) { // if class name is added prefix. $splited = explode('/', trim($subdir, '/')); $splited[] = $className; $prefixedClassName = implode('_', $splited); $prefixedClassName = NameManager::toClass($prefixedClassName); if (self::classExists($prefixedClassName)) { $instance = new $prefixedClassName(); } } if ($instance === null) { if (!self::classExists($className)) { self::load('ClassUndefinedException', 'exception'); throw new ClassUndefinedException($className); } $instance = new $className(); } return $instance; }
/** * 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; }
/** * Create and return form layout element * * @param string $layoutTagName * @return FormLayoutAbstract * @throws FileNotExistException */ public function createLayout($layoutTagName) { $layoutClassName = NameManager::toClass('form_layout_' . trim(strtolower($layoutTagName))); if (!Loader::classExists($layoutClassName)) { $result = Loader::load($layoutClassName, 'html', true, false); if ($result == false) { $result = Loader::loadLibrary($layoutClassName); if ($result == false) { $fileName = NameManager::toPhpFile($layoutClassName); require_once 'exception/file_not_exist_exception.php'; throw new FileNotExistException($fileName); } } } $layoutInstance = new $layoutClassName($this); return $layoutInstance; }
/** * Create connection instance that extends PDO * * @return DbAdapterAbstract * @throws Exception */ protected static function _connect() { $snake = 'db_adapter_' . strtolower(self::$_config['type']); $adapterName = NameManager::toClass($snake); Loader::load($adapterName, 'db'); if (!Loader::classExists($adapterName)) { throw new ClassUndefinedException($adapterName); } $instance = new $adapterName(self::$_config); return $instance; }