示例#1
0
 /**
  * Execute the Request
  *
  * @param array 	$action
  * @param array 	$params
  *
  * @return self
  */
 public function perform()
 {
     // set the input
     if (!is_null($this->input)) {
         CCIn::instance($this->input);
     } else {
         CCIn::instance(CCServer::instance());
     }
     // set current request
     static::$_current =& $this;
     // route is invalid show 404
     if (!$this->route instanceof CCRoute) {
         $this->route = CCRouter::resolve('#404');
     }
     /*
      * call wake events
      * if one event returns an response all other calls will be skipped also events!
      */
     foreach (CCRouter::events_matching('wake', $this->route->uri) as $callback) {
         if (($return = CCContainer::call($callback)) instanceof CCResponse) {
             $this->response = $return;
             return $this;
         }
     }
     /*
      * a closure
      */
     if (!is_array($this->route->callback) && is_callable($this->route->callback)) {
         // execute and capture the output
         ob_start();
         // run the closure
         $return = call_user_func_array($this->route->callback, $this->route->params);
         // catch the output
         $output = ob_get_clean();
         // do we got a response?
         if (!$return instanceof CCResponse) {
             // if not create one with the captured output
             $return = CCResponse::create($output);
         }
     } elseif (is_callable($this->route->callback)) {
         // execute the callback and get the return
         $return = call_user_func_array($this->route->callback, array($this->route->action, $this->route->params));
         // do we got a response?
         if (!$return instanceof CCResponse) {
             // if not create one with the return as string
             $return = CCResponse::create((string) $return);
         }
     } else {
         $return = CCResponse::error(404);
     }
     // set the response
     $this->response = $return;
     /*
      * call sleep events
      * if one event returns an response all other calls will be skipped also events!
      */
     foreach (CCRouter::events_matching('sleep', $this->route->uri) as $callback) {
         if ($return = CCContainer::call($callback, $this->response) instanceof CCResponse) {
             $this->response = $return;
             return $this;
         }
     }
     return $this;
 }
示例#2
0
 /**
  * Test Container direct calls
  */
 public function testCall()
 {
     $this->assertTrue(CCContainer::call('user.valid'));
 }