本文整理匯總了PHP中Illuminate\Routing\Router::dispatch方法的典型用法代碼示例。如果您正苦於以下問題:PHP Router::dispatch方法的具體用法?PHP Router::dispatch怎麽用?PHP Router::dispatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::dispatch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handle
/**
* @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'));
}
示例2: dispatch
/**
* 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);
}
示例3: dispatch
/**
* 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);
}
示例4: call
/**
* @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.');
}
}
示例5: dispatchToRouter
/**
* Get the route dispatcher callback.
*
* @return \Closure
*/
protected function dispatchToRouter()
{
return function ($request) {
$this->app->instance('request', $request);
return $this->router->dispatch($request);
};
}
示例6: invoke
/**
* 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) {
}
}
示例7: run
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();
}
示例8:
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);
}
示例9: dispatch
/**
* @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;
}
示例10: invoke
/**
* 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());
}
}
示例11: invoke
/**
* 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());
}
}
示例12: map
/**
* 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');
});
}
示例13: Dispatcher
<?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();
示例14: dispatch
/**
* 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);
}
示例15: dispatch
public function dispatch(Request $request)
{
$this->getRoutes();
return parent::dispatch($request);
}