本文整理汇总了PHP中FastRoute\simpleDispatcher函数的典型用法代码示例。如果您正苦于以下问题:PHP simpleDispatcher函数的具体用法?PHP simpleDispatcher怎么用?PHP simpleDispatcher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了simpleDispatcher函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initRoutes
/**
* Initialize the route dispatcher and defined routes.
*/
protected function initRoutes()
{
$this->dispatcher = FastRoute\simpleDispatcher(function (RouteCollector $r) {
$r->addRoute('GET', '/', 'IndexController@index');
$r->addRoute('GET', '/{id:\\d+}', 'IndexController@withId');
});
}
开发者ID:jarlskov,项目名称:framework,代码行数:10,代码来源:RouteProvider.php
示例2: __construct
/**
* Router constructor.
*/
public function __construct()
{
$dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $collector) {
$collector->addRoute(['GET'], '/logout', [new \App\Controllers\AdminController(), 'logout']);
$collector->addRoute(['GET', 'POST'], '/[{table}[/{action}[/{id}]]]', [new \App\Controllers\AdminController(), 'main']);
});
$factory = new Abimo\Factory();
$request = $factory->request();
$method = $request->method();
$uri = $request->uri();
$route = $dispatcher->dispatch($method, $uri);
switch ($route[0]) {
case FastRoute\Dispatcher::NOT_FOUND:
$response = $factory->response();
$response->header('404', true, 404)->send();
throw new \ErrorException("Route {$method} {$uri} not found.");
break;
case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
$response = $factory->response();
$response->header('405', true, 405)->send();
throw new \ErrorException("Method {$method} not allowed.");
break;
case FastRoute\Dispatcher::FOUND:
$handler = $route[1];
$arguments = $route[2];
call_user_func_array($handler, $arguments);
}
}
开发者ID:nilopc-interesting-libs,项目名称:curdle,代码行数:31,代码来源:Router.php
示例3: __construct
/**
* Create a new server application instance.
*
* @param string $path The path to the application files.
*/
public function __construct(string $path)
{
$this->path = $path;
// Register some routes.
$this->dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', actions\IndexAction::class);
$r->addRoute('GET', '/blog', actions\BlogAction::class);
$r->addRoute('GET', '/category/{category}', actions\CategoryAction::class);
$r->addRoute('GET', '/portfolio', actions\PortfolioAction::class);
$r->addRoute('GET', '/{year:\\d{4}}/{month:\\d{2}}/{day:\\d{2}}/{name}', actions\ArticleAction::class);
$r->addRoute('GET', '/{asset:(?:content|assets)/[^?]+}[?{query}]', actions\AssetAction::class);
// Complicated feed routes :/
$r->addRoute('GET', '/sitemap.xml', actions\SitemapAction::class);
$r->addRoute('GET', '/feed[/{category:[a-z]+}]', actions\AtomFeedAction::class);
$r->addRoute('GET', '/feed.atom', actions\AtomFeedAction::class);
$r->addRoute('GET', '/feed/{category:[a-z]+}.atom', actions\AtomFeedAction::class);
$r->addRoute('GET', '/feed.rss', actions\RssFeedAction::class);
$r->addRoute('GET', '/feed/{category:[a-z]+}.rss', actions\RssFeedAction::class);
});
// Create the server object.
$this->server = new Server(new RequestHandler($this));
// Create some core services.
$this->renderer = new Renderer($path . '/templates');
$this->assetManager = new AssetManager($path . '/static');
$this->articleStore = new ArticleStore($path . '/articles');
}
开发者ID:coderstephen,项目名称:blog,代码行数:31,代码来源:Application.php
示例4: setUp
public function setUp()
{
$router = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', ['TestApp\\Controller\\Index', 'index']);
});
$this->app = new App($router);
}
开发者ID:butkimtinh,项目名称:penny,代码行数:7,代码来源:EventFlowTest.php
示例5: setUp
public function setUp()
{
chdir(__DIR__ . '/app/');
$this->router = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/load', ['TestApp\\Controller\\Index', 'loadedParams'], ['name' => 'load']);
});
}
开发者ID:butkimtinh,项目名称:penny,代码行数:7,代码来源:AppLoaderTest.php
示例6: __invoke
/**
* Invocation
*
* Register routes container and request attributes
*
* @param ServerRequestInterface $request Request
* @param ResponseInterface $response Response
* @param TornadoHttp $next Next Middleware - TornadoHttp container
* @return ResponseInterface
* @throws HttpMethodNotAllowedException
* @throws HttpNotFoundException
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, TornadoHttp $next)
{
/** @var \FastRoute\Dispatcher\GroupCountBased $dispatcher */
$dispatcher = FastRoute\simpleDispatcher(function (RouteCollector $routeCollector) {
foreach ($this->routes as $key => $route) {
$routeCollector->addRoute($route['methods'], $route['path'], $key);
}
});
$method = $request->getMethod();
$uri = rawurldecode(parse_url($request->getUri(), \PHP_URL_PATH));
$route = $dispatcher->dispatch($method, $uri);
$handler = null;
$vars = null;
switch ($route[0]) {
case Dispatcher::NOT_FOUND:
throw new HttpNotFoundException('Inexistent route for the url ' . $request->getUri());
case Dispatcher::METHOD_NOT_ALLOWED:
throw new HttpMethodNotAllowedException('Method not allowed');
case Dispatcher::FOUND:
$handler = $route[1];
$vars = $route[2];
break;
}
$request = $request->withAttribute(Router::REGISTER_KEY, $handler);
foreach ($vars as $name => $value) {
$request = $request->withAttribute($name, $value);
}
return $next($request, $response);
}
开发者ID:danielspk,项目名称:tornadohttpskeletonapplication,代码行数:41,代码来源:Resolver.php
示例7: setUp
public function setUp()
{
$config = Loader::load();
$config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', ['TestApp\\Controller\\IndexController', 'index']);
});
$this->app = new App(Container\PHPDiFactory::buildContainer($config));
}
开发者ID:amir20202000,项目名称:penny,代码行数:8,代码来源:EventFlowTest.php
示例8: __construct
public function __construct()
{
$this->dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', 'IndexController');
$r->addRoute('POST', '/', 'IndexController');
});
$this->request = Request::createFromGlobals();
}
开发者ID:ChiVincent,项目名称:KMoneyFramework,代码行数:8,代码来源:Route.php
示例9: registerRoutes
/**
* Register necessary routes with route provider
*/
protected function registerRoutes()
{
$this->dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $routeCollector) {
$this->each(function (RouteRequest $routeRequest) use($routeCollector) {
$routeCollector->addRoute($routeRequest->method, $routeRequest->route, $routeRequest->callable);
});
});
}
开发者ID:jasonmichels,项目名称:groundworkphp,代码行数:11,代码来源:Router.php
示例10: createDispatcher
/**
* Instantiates the router using the routes in the container.
*/
private function createDispatcher()
{
$this->dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $collector) {
foreach ($this->container->get('routes') as $route) {
$collector->addRoute($route['method'], $route['pattern'], $route['service']);
}
});
}
开发者ID:AndrewCarterUK,项目名称:php-berkshire-website,代码行数:11,代码来源:Application.php
示例11: setUp
public function setUp()
{
$this->router = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $manager) {
$manager->addRoute('GET', '/', ['TestApp\\Controller\\IndexController', 'index'], ['name' => 'index']);
$manager->addRoute('GET', '/fail', ['TestApp\\Controller\\IndexController', 'none'], ['name' => 'fail']);
$manager->addRoute('GET', '/dummy', ['TestApp\\Controller\\IndexController', 'dummy'], ['name' => 'dummy']);
});
}
开发者ID:gianarb,项目名称:penny,代码行数:8,代码来源:DispatcherTest.php
示例12: dispatcher
/**
* @return Dispatcher
*/
protected function dispatcher()
{
return FastRoute\simpleDispatcher(function (RouteCollector $collector) {
foreach ($this->directory as $request => $action) {
list($method, $path) = explode(' ', $request, 2);
$collector->addRoute($method, $this->directory->prefix($path), $action);
}
});
}
开发者ID:equip,项目名称:framework,代码行数:12,代码来源:DispatchHandler.php
示例13: setUp
public function setUp()
{
chdir(__DIR__ . '/app/');
$config = Loader::load();
$config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/load', ['TestApp\\Controller\\IndexController', 'loadedParams'], ['name' => 'load']);
});
$this->container = Container\PHPDiFactory::buildContainer($config);
}
开发者ID:amir20202000,项目名称:penny,代码行数:9,代码来源:AppLoaderTest.php
示例14: setUp
public function setUp()
{
$config = Loader::load();
$config['router'] = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', [get_class($this), 'index']);
});
$config['dispatcher'] = \Di\object('PennyTest\\Utils\\FastSymfonyDispatcher')->constructor(\Di\get('router'), \Di\get('di'));
$this->app = new App(Container\PHPDiFactory::buildContainer($config));
}
开发者ID:amir20202000,项目名称:penny,代码行数:9,代码来源:SymfonyKernelTest.php
示例15: setUp
public function setUp()
{
$this->router = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $router) {
$router->addRoute('GET', '/', ['TestApp\\Controller\\Index', 'diTest']);
});
$builder = new ContainerBuilder();
$builder->useAnnotations(true);
$dic = $builder->build();
$this->container = $dic;
}
开发者ID:butkimtinh,项目名称:penny,代码行数:10,代码来源:DiTest.php
示例16: compile
public function compile()
{
if (!$this->dispatcher) {
$this->dispatcher = BaseFastRoute\simpleDispatcher(function (BaseFastRoute\RouteCollector $r) {
foreach ($this->routes as $route) {
$r->addRoute($route[0], $route[1], $route[2]);
}
});
}
}
开发者ID:RickySu,项目名称:php-webutil,代码行数:10,代码来源:FastRoute.php
示例17: dispatcher
/**
* @return Dispatcher
*/
protected function dispatcher()
{
return FastRoute\simpleDispatcher(function (RouteCollector $collector) {
foreach ($this->directory as $request => $action) {
// 'GET /foo' becomes ['GET', '/foo']
list($method, $path) = explode(' ', $request, 2);
$collector->addRoute($method, $path, $action);
}
});
}
开发者ID:JasonBusse,项目名称:rest_scheduler,代码行数:13,代码来源:DispatchHandler.php
示例18: getRouteDispatcher
/**
* @return Dispatcher
*/
protected function getRouteDispatcher()
{
$dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$routes = Routes::$routeRegister;
foreach ($routes as $route) {
$r->addRoute($route->getRequestMethod(), $route->getPathPattern(), $route);
}
});
return $dispatcher;
}
开发者ID:pumatertion,项目名称:bleicker.fastroute-requesthandler,代码行数:13,代码来源:RequestHandler.php
示例19: __construct
/**
* Add routes definition to collector and dispatch it
*
* @param array $routes
* @param array $routerOptions
*/
public function __construct(array $routes, array $routerOptions = [])
{
$this->routes = $routes;
$this->routerOptions = array_merge($this->routerOptions, $routerOptions);
if (!$this->routerOptions['cacheDisabled']) {
$this->dispatcher = cachedDispatcher($this->prepareRoutes(), $this->routerOptions);
} else {
$this->dispatcher = simpleDispatcher($this->prepareRoutes(), $this->routerOptions);
}
}
开发者ID:simukti,项目名称:kadalkesit,代码行数:16,代码来源:RouteManager.php
示例20: __construct
/**
* Initialize a Router.
*
* Routes require a 'path' key and may have optional 'methods' and 'defaults' keys.
*
* @param array $routeData Array of routes
*/
public function __construct(array $routeData)
{
$this->dispatcher = simpleDispatcher(function ($r) use($routeData) {
foreach ($routeData as $data) {
if (is_array($data)) {
$data = Route::fromArray($data);
}
$r->addRoute($data->getMethods(), $data->getPath(), $data);
}
});
}
开发者ID:ifcanduela,项目名称:pew,代码行数:18,代码来源:Router.php
注:本文中的FastRoute\simpleDispatcher函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论