dispatch() public method

Dispatch the request to the application.
public dispatch ( Illuminate\Http\Request $request ) : Illuminate\Http\Response
$request Illuminate\Http\Request
return Illuminate\Http\Response
Example #1
0
 /**
  * @param Request $request
  * @param int $type
  * @param bool $catch
  * @return mixed
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     // ensure the request is available in the container.
     $this->instance('request', $request);
     // dispatch the request.
     return $this->router->dispatch($this->make('request'));
 }
Example #2
0
 /**
  * Dispatch a request.
  *
  * @param \Illuminate\Http\Request $request
  * @param string                   $version
  *
  * @return mixed
  */
 public function dispatch(Request $request, $version)
 {
     if (!isset($this->routes[$version])) {
         throw new UnknownVersionException();
     }
     $routes = $this->mergeExistingRoutes($this->routes[$version]);
     $this->router->setRoutes($routes);
     return $this->router->dispatch($request);
 }
Example #3
0
 /**
  * Dispatch a request.
  *
  * @param \Illuminate\Http\Request $request
  * @param string                   $version
  *
  * @return mixed
  */
 public function dispatch(Request $request, $version)
 {
     if (!isset($this->routes[$version])) {
         throw new UnknownVersionException();
     }
     $this->router->setRoutes($this->routes[$version]);
     // Because the above call will reset the routes defined on the applications
     // UrlGenerator we will simply rebind the routes to the application
     // container which will trigger the rebinding event.
     $this->container->instance('routes', $this->applicationRoutes);
     return $this->router->dispatch($request);
 }
Example #4
0
 /**
  * @param $uri
  * @param $method
  * @param array $parameters
  * @param bool $collection
  *
  * @return mixed|string
  */
 public function call($uri, $method, $parameters = [], $collection = true)
 {
     try {
         $origin_input = $this->request->input();
         $request = $this->request->create($uri, $method, $parameters);
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         $this->request->replace($origin_input);
         return $this->getResponse($dispatch, $dispatch->getContent(), $collection);
     } catch (NotFoundHttpException $e) {
         throw new NotFoundHttpException('Request Not Found.');
     }
 }
Example #5
0
 /**
  * Get the route dispatcher callback.
  *
  * @return \Closure
  */
 protected function dispatchToRouter()
 {
     return function ($request) {
         $this->app->instance('request', $request);
         return $this->router->dispatch($request);
     };
 }
Example #6
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     // Parameters for GET, POST
     $parameters = $parameters ? current($parameters) : array();
     try {
         // store the original request data and route
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // replace the request input...
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // replace the request input and route back to the original state
         $this->request->replace($originalInput);
         $this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
     }
 }
 public function run()
 {
     $router = new Router(new Dispatcher($this->container), $this->container);
     $router->get('/', HomeController::class . '@index');
     $router->get('/responsabilidad/{id}', HomeController::class . '@show');
     $response = $router->dispatch(Request::capture());
     $response->send();
 }
Example #8
0
 function it_can_handle_a_request(Request $request, Response $response, Router $router)
 {
     // arrange
     $router->dispatch($request)->willReturn($response);
     $this->setRouter($router);
     // act and assert
     $this->handle($request)->shouldReturn($response);
 }
Example #9
0
 /**
  * @docInherit
  */
 public function dispatch(Request $request)
 {
     // Set locale
     $initialLocale = App::getLocale();
     $locale = $this->extractLocale($request);
     App::setLocale($locale);
     setlocale(LC_COLLATE, $locale . '_CA.utf8');
     setlocale(LC_CTYPE, $locale . '_CA.utf8');
     setlocale(LC_TIME, $locale . '_CA.utf8');
     $this->storeLocale($locale);
     // Dispatch request
     $response = parent::dispatch($request);
     // Reset the locale
     App::setLocale($initialLocale);
     return $response;
 }
Example #10
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     if (!preg_match('/^http(s)?:/', $uri)) {
         $uri = '/' . ltrim($uri, '/');
     }
     try {
         // Store the original request data and route.
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // Masking route to allow testing with PHPUnit.
         /*if ( ! $originalRoute instanceof Route)
           {
               $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request());
           }*/
         // Create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // Replace the request input...
         $this->request->replace($request->input());
         // Dispatch request.
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // Restore the request input and route back to the original state.
         $this->request->replace($originalInput);
         // This method have been removed from Laravel.
         //$this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
         //trigger_error('Not found');
         var_dump($e->getMessage());
     } catch (FatalErrorException $e) {
         var_dump($e->getMessage());
     }
 }
Example #11
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     try {
         // Store the original request data and route.
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // Masking route to allow testing with PHPUnit.
         // if ( ! $originalRoute instanceof Route)
         // {
         //     $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request());
         // }
         $requestMethod = strtoupper($method);
         // Create a new request to the API resource
         $request = $this->request->create($uri, $requestMethod, $parameters);
         // Replace request method and input.
         $this->request->setMethod($requestMethod);
         $this->request->replace($request->input());
         // Dispatch request.
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // Restore the request input and route back to the original state.
         $this->request->replace($originalInput);
         return $response;
     } catch (NotFoundHttpException $e) {
         throw new HmvcNotFoundHttpException('Request Not Found.');
     } catch (FatalErrorException $e) {
         throw new HmvcFatalErrorException($e->getMessage());
     }
 }
 /**
  * Define the routes for the application.
  *
  * @param  \Illuminate\Routing\Router $router
  *
  * @return void
  */
 public function map(Router $router)
 {
     $router->group(['namespace' => $this->namespace], function (Router $router) {
         $router->get('/', function (Router $router) {
             return $router->dispatch(Request::create('product', 'GET', []));
         });
         $router->get('/about-us', function () {
             return view('about-us', ['navActive' => 'about-us']);
         });
         $router->resource('/product', 'ProductController', ['except' => ['show']]);
         $router->resource('/category', 'CategoryController', ['except' => ['index']]);
         $router->resource('/cart', 'CartController', ['only' => ['index', 'store', 'destroy']]);
         $router->resource('/order', 'OrderController', ['only' => ['index', 'store', 'update']]);
         $router->get('order/history', 'OrderController@history');
         $router->get('/search', 'ProductController@search');
         $router->get('/login', 'Auth\\AuthController@getLogin');
         $router->post('/login', 'Auth\\AuthController@postLogin');
         $router->get('/logout', 'Auth\\AuthController@getLogout');
         $router->get('/register', 'Auth\\AuthController@getRegister');
         $router->post('/register', 'Auth\\AuthController@postRegister');
         $router->get('/account/edit', 'Auth\\AuthController@edit');
         $router->put('/account/edit', 'Auth\\AuthController@update');
     });
 }
Example #13
0
<?php

/**
 * Illuminate/Routing
 *
 * @source https://github.com/illuminate/routing
 * @contributor Muhammed Gufran
 * @contributor Matt Stauffer
 * @contributor https://github.com/jwalton512
 */
require_once 'vendor/autoload.php';
use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
// Using Illuminate/Events/Dispatcher here (not required); any implementation of
// Illuminate/Contracts/Event/Dispatcher is acceptable
$events = new Dispatcher(new Container());
// Create the router instance
$router = new Router($events);
// Load the routes
require_once 'routes.php';
// Create a request from server variables
$request = Request::capture();
// Dispatch the request through the router
$response = $router->dispatch($request);
// Send the response back to the browser
$response->send();
Example #14
0
 /**
  * Get the response for a given request.
  * Overloaded so that we can merge route groups.
  * 
  * @param  \Symfony\Component\HttpFoundation\Request  $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function dispatch(Request $request)
 {
     $this->mergeRouteGroups();
     return parent::dispatch($request);
 }
Example #15
0
 public function dispatch(Request $request)
 {
     $this->getRoutes();
     return parent::dispatch($request);
 }
Example #16
0
 /**
  * Dispatch the request to the application and return either a regular response
  * or an API response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response|\Dingo\Api\Http\Response
  * @throws \Exception
  */
 public function dispatch(Request $request)
 {
     if (!$this->requestTargettingApi($request)) {
         return parent::dispatch($request);
     }
     $this->container->instance('Illuminate\\Http\\Request', $request);
     ApiResponse::getTransformer()->setRequest($request);
     try {
         $response = parent::dispatch($request);
     } catch (Exception $exception) {
         if ($request instanceof InternalRequest) {
             throw $exception;
         } else {
             $response = $this->handleException($exception);
         }
     }
     $this->container->forgetInstance('Illuminate\\Http\\Request');
     return $response instanceof ApiResponse ? $response->morph($this->requestedFormat) : $response;
 }
Example #17
0
 /**
  * Dispatch the request to the application and return either a regular response
  * or an API response.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @throws \Exception
  *
  * @return \Illuminate\Http\Response|\Dingo\Api\Http\Response
  */
 public function dispatch(Request $request)
 {
     if (!$this->isApiRequest($request)) {
         return parent::dispatch($request);
     }
     list($version, $format) = $this->parseAcceptHeader($request);
     $this->currentVersion = $version;
     $this->currentFormat = $format;
     $this->container->instance('Illuminate\\Http\\Request', $request);
     try {
         $response = parent::dispatch($request);
         // Attempt to get the formatter so that we can catch and handle
         // any exceptions due to a poorly formatted accept header.
         $response->getFormatter($format);
     } catch (Exception $exception) {
         $response = $this->handleException($request, $exception);
     }
     // This goes hand in hand with the above. We'll check to see if a
     // formatter exists for the requested response format. If not
     // then we'll revert to the default format because we are
     // most likely formatting an error response.
     if (!$response->hasFormatter($format)) {
         $format = $this->properties->getFormat();
     }
     $response->getFormatter($format)->setRequest($request)->setResponse($response);
     $response = $response->morph($format);
     return $response;
 }
Example #18
0
 /**
  * Dispatch the request to the application.
  *
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response 
  * @static 
  */
 public static function dispatch($request)
 {
     return \Illuminate\Routing\Router::dispatch($request);
 }
Example #19
0
 /**
  * Try and execute the requested route.
  * If the requested route is an API route,
  * catch all HttpExceptions and make it a nice response.
  *
  * @param  Request $request
  * @return \Illuminate\Http\Response
  */
 public function dispatch(Request $request)
 {
     // If the route is not an API route,
     // dont modify the response
     if (!$this->isApiRequest($request)) {
         return parent::dispatch($request);
     }
     try {
         $response = Response::makeFromExisting(parent::dispatch($request));
     } catch (HttpExceptionInterface $exception) {
         $response = Response::makeFromException($exception);
     } catch (ModelNotFoundException $exception) {
         $response = Response::makeFromException(new NotFoundResourceException($exception->getModel()));
     }
     return $response->finalize($this->getMutator($request), $this->getEncoder($request), $request);
 }