/**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $redirect = $this->defaults;
     if (count($this->defaults) == 1 && !isset($this->defaults['controller'])) {
         $redirect = $this->defaults[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $argOptions['context'] = array('action' => $redirect['action'], 'controller' => $redirect['controller']);
         $args = Router::getArgs($params['_args_'], $argOptions);
         $redirect += $args['pass'];
         $redirect += $args['named'];
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
 }
Example #2
0
 /**
  * Restructure params in case we're serving a plugin.
  *
  * @param array $params Array on where to re-set 'controller', 'action', and 'pass' indexes
  * @param boolean $reverse
  * @return array Restructured array
  * @access protected
  */
 function _restructureParams($params, $reverse = false)
 {
     if ($reverse === true) {
         extract(Router::getArgs($params['action']));
         $params = array_merge($params, array('controller' => $params['plugin'], 'action' => $params['controller'], 'pass' => array_merge($pass, $params['pass']), 'named' => array_merge($named, $params['named'])));
         $this->plugin = $params['plugin'];
     } else {
         $params['plugin'] = $params['controller'];
         $params['controller'] = $params['action'];
         if (isset($params['pass'][0])) {
             $params['action'] = $params['pass'][0];
             array_shift($params['pass']);
         } else {
             $params['action'] = null;
         }
     }
     return $params;
 }
Example #3
0
 /**
  * Restructure params in case we're serving a plugin.
  *
  * @param array $params Array on where to re-set 'controller', 'action', and 'pass' indexes
  * @param boolean $reverse
  * @return array Restructured array
  * @access protected
  */
 protected function _restructureParams($params, $reverse = false)
 {
     if ($reverse === true) {
         extract(Router::getArgs($params['action']));
         $params = array_merge($params, array('controller' => $params['plugin'], 'action' => $params['controller'], 'pass' => array_merge($pass, $params['pass']), 'named' => array_merge($named, $params['named'])));
     } else {
         $params['plugin'] = $params['controller'];
     }
     return $params;
 }
 /**
  * Get controller to use, either plugin controller or application controller
  *
  * @param array $params Array of parameters
  * @return mixed name of controller if not loaded, or object if loaded
  * @access private
  */
 function __getController($params = null)
 {
     if (!is_array($params)) {
         $params = $this->params;
     }
     $controller = false;
     if (!($ctrlClass = $this->__loadController($params))) {
         if (!isset($params['plugin'])) {
             $params = $this->_restructureParams($params);
         }
         if (!($ctrlClass = $this->__loadController($params))) {
             $params = am($params, array('controller' => $params['plugin'], 'action' => $params['controller'], 'pass' => am($params['pass'], Router::getArgs($params['action']))));
             if (!($ctrlClass = $this->__loadController($params))) {
                 return false;
             }
         }
     }
     if (class_exists($ctrlClass)) {
         $this->params = $params;
         $controller =& new $ctrlClass();
     }
     return $controller;
 }
Example #5
0
<?php

include "./swoole_include.php";
$http = new swoole_http_server("0.0.0.0", 9501);
$http->on('request', function ($request, $response) {
    if ($request->server['request_uri'] !== '/favicon.ico') {
        //设置参数
        $req = new Request($request);
        //var_dump( $request );
        //获取类.方法.参数
        $rou = new Router($req);
        $class = $rou->getClass();
        $method = $rou->getMethod();
        $args = $rou->getArgs();
        //按需加载类文件
        $fileName = SWOOLE_MODEL_PATH . $class . '.class.php';
        if (is_file($fileName)) {
            require_once $fileName;
        } else {
            Log::write($class . ' is not found', 'EMERG', 3, 'swoole');
            $response->end('url is error, please check your url!');
        }
        //调用回调函数,获取数据
        $data = call_user_func_array(array($class, $method), $args);
        //返回处理信息
        $res = new Response($data);
        $response->end($res->getData());
    }
});
$http->start();