コード例 #1
0
ファイル: router.php プロジェクト: ydhl/yangzie
 public static function load_routers()
 {
     foreach (glob(YZE_APP_MODULES_INC . "*") as $module) {
         $phar_wrap = is_file($module) ? "phar://" : "";
         if (@file_exists("{$phar_wrap}{$module}/__module__.php")) {
             include_once "{$phar_wrap}{$module}/__module__.php";
             $module_name = strtolower(basename($module));
             if ($phar_wrap) {
                 $module_name = ucfirst(preg_replace('/\\.phar$/', "", $module_name));
             }
             $class = "\\app\\{$module_name}\\" . ucfirst($module_name) . "_Module";
             $object = new $class();
             $mappings = $object->get_module_config('routers');
             if ($mappings) {
                 YZE_Router::get_Instance()->set_Routers($module_name, $mappings);
             }
         }
     }
 }
コード例 #2
0
ファイル: request.php プロジェクト: ydhl/yangzie
 /**
  * 初始化请求
  * 解析请求的uri,如果没有传入url,默认解析当前请求的uri
  *
  * @param string $uri            
  * @param string $method
  *            该请求的方法
  * @param string $format
  *            请求返回的格式, 如果uri中没有明确指定格式,则返回该格式
  * @return YZE_Request
  */
 public function init($newUri = null, $action = null, $format = null, $request_method = null)
 {
     if (count(self::$instances) == 0) {
         $this->is_top_request = true;
     }
     self::$instances[] = $this;
     $this->_init($newUri);
     if ($request_method) {
         $this->request_method = $request_method;
     } else {
         $this->request_method = $_SERVER['REQUEST_METHOD'];
     }
     $uri = $this->the_uri();
     if ($newUri) {
         parse_str(parse_url($newUri, PHP_URL_QUERY), $args);
         if ($args) {
             $this->get = array_merge($this->get, $args);
         }
     }
     $routers = YZE_Router::get_instance()->get_routers();
     $config_args = self::parse_url($routers, $uri);
     // 地址映射及返回格式
     $this->set_vars(@(array) $config_args['args']);
     if ($format && !$this->get_var("__yze_resp_format__")) {
         $this->set_var("__yze_resp_format__", $format);
     }
     if ($config_args) {
         $controller_name = @$config_args['controller_name'];
         $curr_module = @$config_args['module'];
     }
     $action = self::the_val($action ? $action : $this->get_var("action"), "index");
     $method = ($this->is_get() ? "" : "post_") . str_replace("-", "_", $action);
     $this->set_method($method);
     if (@$curr_module && $controller_name) {
         $this->set_module($curr_module)->set_controller_name($controller_name);
     } else {
         $this->controller_name = "yze_default";
         $this->controller_class = "Yze_Default_Controller";
         $this->controller = new Yze_Default_Controller($this);
     }
     $controller_cls = $this->controller_class();
     if (!($controller = $this->controller())) {
         throw new YZE_Resource_Not_Found_Exception("Controller {$controller_cls} Not Found");
     }
     if (!method_exists($controller, $method)) {
         throw new YZE_Resource_Not_Found_Exception($controller_cls . "::" . $method . " not found");
     }
     if (!$this->is_get() and $this->the_post_datas()) {
         $model = $this->get_modify_model();
         YZE_Session_Context::get_instance()->save_post_datas($this->the_uri(), $this->the_post_datas());
     }
     return $this;
 }