コード例 #1
0
ファイル: Router.php プロジェクト: sujinw/php-lugit-framework
 protected function __construct()
 {
     if (isset($_SERVER['REQUEST_URI'])) {
         $this->full_url_path = $_SERVER['REQUEST_URI'];
     } elseif (isset($_SERVER['argv'])) {
         $this->full_url_path = $_SERVER['PHP_SELF'] . '?' . $_SERVER['argv'][0];
     } else {
         $this->full_url_path = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
     }
     $pos = strpos($this->full_url_path, '?');
     if ($pos === false) {
         $this->url_get = '';
         $this->url_path = $this->full_url_path;
     } else {
         $this->url_get = substr($this->full_url_path, $pos + 1);
         $this->url_path = substr($this->full_url_path, 0, $pos);
     }
     //把连续的“\"或“/”替换成一个“/”
     $this->url_path = preg_replace('/[\\/\\\\]+/', '/', $this->url_path);
     //去掉末尾的斜杠
     $this->url_path = substr($this->url_path, -1) == '/' ? substr($this->url_path, 1, -1) : substr($this->url_path, 1);
     $array_urlPath = array();
     if ($this->url_path) {
         $pos = strpos($this->url_path, '/');
         if ($pos === false) {
             $array_urlPath = array(0 => $this->url_path);
         } else {
             $array_urlPath = explode('/', $this->url_path);
         }
     }
     $this->controllerName = isset($array_urlPath[0]) ? strtolower($array_urlPath[0]) : 'index';
     $this->actionName = isset($array_urlPath[1]) ? strtolower($array_urlPath[1]) : 'index';
     //获得并设置参数
     $this->array_parameter = array();
     if (($arrayCount = count($array_urlPath)) > 2) {
         for ($i = 2; $i < $arrayCount; ++$i) {
             $this->array_parameter[] = Basic::safeUrl($array_urlPath[$i]);
         }
     }
     if (!Singleton::getInstance('RequestModule')->isPost()) {
         $this->checkUrl();
     }
 }