lithium\action\Dispatcher::run PHP Method

run() public static method

Dispatches a request based on a request object (an instance or subclass of lithium\net\http\Request).
See also: lithium\action\Request
See also: lithium\action\Response
public static run ( object $request, array $options = [] ) : mixed
$request object An instance of a request object (usually `lithium\action\Request`) with HTTP request information.
$options array
return mixed Returns the value returned from the callable object retrieved from `Dispatcher::_callable()`, which is either a string or an instance of `lithium\action\Response`.
    public static function run($request, array $options = array())
    {
        $router = static::$_classes['router'];
        $params = compact('request', 'options');
        return static::_filter(__FUNCTION__, $params, function ($self, $params) use($router) {
            $request = $params['request'];
            $options = $params['options'];
            if (($result = $router::process($request)) instanceof Response) {
                return $result;
            }
            $params = $self::applyRules($result->params);
            if (!$params) {
                throw new DispatchException('Could not route request.');
            }
            $callable = $self::invokeMethod('_callable', array($result, $params, $options));
            return $self::invokeMethod('_call', array($callable, $result, $params));
        });
    }

Usage Example

Beispiel #1
0
 /**
  * Builds a composite AMF response based on the response bodies inside the 
  * original AMF request.
  *
  * @return Zend_Amf_Response_Http
  */
 public function processResponseBodies()
 {
     $responseBodies = $this->request->getAmfBodies();
     foreach ($responseBodies as $body) {
         //Extract params from request body
         $return = $this->extractUriAndParams($body);
         //Create fake request object
         $liRequest = new Request(array('data' => $return['params']));
         //Assign URL to request based on details
         if (isset($return['source'])) {
             $liRequest->url = '/' . $return['source'] . '/' . $return['method'];
         } elseif (isset($return['targetURI'])) {
             $liRequest->url = '/' . $return['targetURI'];
         }
         //Assign request params
         $liRequest->params += $return['params'];
         //Dispatch the request normally, and get the controller data
         $controllerResponse = Dispatcher::run($liRequest);
         //Add on the response data (or error) to the current response
         if (isset($controllerResponse->body['error'])) {
             $netStatusEvent = new StdClass();
             $netStatusEvent->_explicitType = 'flex.messaging.messages.ErrorMessage';
             $netStatusEvent->faultString = $controllerResponse->body['error'];
             $newBody = new \Zend_Amf_Value_MessageBody($body->getResponseURI() . \Zend_AMF_Constants::STATUS_METHOD, null, $netStatusEvent);
             $this->response->addAmfBody($newBody);
         } else {
             $newBody = new \Zend_Amf_Value_MessageBody($body->getResponseURI() . \Zend_AMF_Constants::STATUS_METHOD, null, $controllerResponse->body);
             $this->response->addAmfBody($newBody);
         }
     }
     return $this->response;
 }
All Usage Examples Of lithium\action\Dispatcher::run