function yaf_auto_load($classname) { $yafNamespace = 'Yaf'; $namespaceSeparator = '\\'; $fileName = ''; $namespace = ''; if ($yafNamespace . $namespaceSeparator === substr($classname, 0, strlen($yafNamespace . $namespaceSeparator))) { $fileName = ''; $namespace = ''; if (false !== ($lastNsPos = strripos($classname, $namespaceSeparator))) { $namespace = substr($classname, 0, $lastNsPos); $classname = substr($classname, $lastNsPos + 1); $fileName = str_replace($namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } } if ($namespace == 'Yaf' || stripos($namespace, 'Yaf' . $namespaceSeparator) === 0) { include_once APPLICATION_PATH . '/framework/Yaf_Namespace/G.php'; \Yaf\G::iniSet('yaf.use_namespace', true); $fileName = str_replace('Yaf' . DIRECTORY_SEPARATOR, 'Yaf_Namespace' . DIRECTORY_SEPARATOR, $fileName); } $path = $fileName . str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php'; if (file_exists(APPLICATION_PATH . '/framework/' . $path)) { require_once APPLICATION_PATH . '/framework/' . $path; } /*$path = str_replace("_", DIRECTORY_SEPARATOR, $classname); if (file_exists(APPLICATION_PATH . '/framework/' . $path . '.php')) { require_once(APPLICATION_PATH. '/framework/' . $path . '.php'); }*/ }
public function __construct($method = null, $module = null, $controller = null, $action = null, $params = array()) { if (!is_array($params)) { throw new \Yaf\Exception\TypeError('Expects the params is an array'); } if ($method == null) { if (isset($_SERVER['REQUEST_METHOD'])) { $method = $_SERVER['REQUEST_METHOD']; } else { $sapiType = php_sapi_name(); if (strtolower($sapiType) == 'cli' || substr($sapiType, 0, 3) == 'cgi') { $method = 'CLI'; } else { $method = 'unknown'; } } } $this->method = $method; if ($module != null || $action != null || $controller != null) { $this->setActionName($action); $this->setControllerName($controller); $this->setModuleName($module); $this->setRouted(true); } else { if ($module == null) { $this->setModuleName(\Yaf\G::get('default_module')); } if ($controller == null) { $this->setControllerName(\Yaf\G::get('default_controller')); } if ($action == null) { $this->setActionName(\Yaf\G::get('default_action')); } } if ($params) { $this->setParam($params); } }
/** * Finds a view script from the available directory. * * @param string $name The base name of the script. * @return void */ protected function _script($name) { if (preg_match('#\\.\\.[\\\\/]#', $name)) { throw new \Yaf\Exception('Requested scripts may not include parent ' . 'directory traversal ("../", "..\\" notation)'); } if ($this->_tpl_dir == '') { throw new \Yaf\Exception\LoadFailed\View('Could not determine the view script path, ' . 'you should call Yaf_View_Simple::setScriptPath to specific it'); } if (\Yaf\G::isAbsolutePath($name) && is_readable($name)) { return $name; } else { if (is_readable($this->_tpl_dir . DIRECTORY_SEPARATOR . $name)) { return $this->_tpl_dir . DIRECTORY_SEPARATOR . $name; } } throw new \Yaf\Exception\LoadFailed\View("Unable to find template " . $this->_tpl_dir . DIRECTORY_SEPARATOR . $name); }
/** * Processes a request and sets its controller and action based on a * supervar value. * * @param Yaf_Request_Abstract * @return Yaf_Request_Abstract|boolean */ public function route(\Yaf\Request_Abstract $request) { $requestUri = $request->getQuery($this->_varName); if ($requestUri == null || $requestUri == '') { return false; } $module = null; $controller = null; $action = null; $rest = null; $path = trim($requestUri, \Yaf\Router::URI_DELIMITER); if ($path != '' && $path != '/') { $path = explode(\Yaf\Router::URI_DELIMITER, $path); if (\Yaf\Application::isModuleName($path[0])) { $module = $path[0]; array_shift($path); } if (count($path) && !empty($path[0])) { $controller = $path[0]; array_shift($path); } if (count($path) && !empty($path[0])) { $action = $path[0]; array_shift($path); } $rest = implode(\Yaf\Router::URI_DELIMITER, $path); $actionPrefer = \Yaf\G::iniGet('yaf.action_prefer'); if ($module == null && $controller == null && $action == null) { if ($actionPrefer == true) { $action = $rest; } else { $controller = $rest; } $rest = null; } elseif ($module == null && $action == null && $rest == null) { if ($actionPrefer == true) { $action = $controller; $controller = null; } } elseif ($controller == null && $action == null && $rest != null) { $controller = $module; $action = $rest; $module = null; $rest = null; } elseif ($action == null && $rest == null) { $action = $controller; $controller = $module; $module = null; } elseif ($controller == null && $action == null) { $controller = $module; $action = $rest; $module = null; $rest = null; } elseif ($action == null) { $action = $rest; $rest = null; } if ($module != null) { $request->setModuleName($module); } if ($controller != null) { $request->setControllerName($controller); } if ($action != null) { $request->setActionName($action); } $params = array(); if ($rest != null && trim($rest) != '') { $path = explode(\Yaf\Router::URI_DELIMITER, $rest); if (($numSegs = count($path)) != 0) { for ($i = 0; $i < $numSegs; $i = $i + 2) { $key = urldecode($path[$i]); $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null; $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val; } } $request->setParam($params); } } return true; }