本文整理汇总了PHP中Slim\App::any方法的典型用法代码示例。如果您正苦于以下问题:PHP App::any方法的具体用法?PHP App::any怎么用?PHP App::any使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\App
的用法示例。
在下文中一共展示了App::any方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpRoutes
public function setUpRoutes()
{
$this->app->get('/', function (Request $request, Response $response, array $args) {
$response->getBody()->write(file_get_contents(AppConfig::getPathToPublic() . '/app.html'));
});
$this->app->any('/api/users/[{id}]', Controller\UsersController::class);
$this->app->any('/api/sessions/[{api_key}]', Controller\SessionsController::class);
$this->app->any('/api/trips/[{id}]', Controller\TripsController::class);
$this->app->any('/api/trips/user/[{user_id}]', Controller\TripsController::class);
}
示例2: testAnyRoute
public function testAnyRoute()
{
$path = '/foo';
$callable = function ($req, $res) {
// Do something
};
$app = new App();
$route = $app->any($path, $callable);
$this->assertInstanceOf('\\Slim\\Route', $route);
$this->assertAttributeContains('GET', 'methods', $route);
$this->assertAttributeContains('POST', 'methods', $route);
$this->assertAttributeContains('PUT', 'methods', $route);
$this->assertAttributeContains('PATCH', 'methods', $route);
$this->assertAttributeContains('DELETE', 'methods', $route);
$this->assertAttributeContains('OPTIONS', 'methods', $route);
}
示例3: setMap
/**
* Sets main dynamic routing params into Slim app
*
* @param \Slim\App $app
*
* @return void
*/
public static function setMap($app, $namespace)
{
$app->any('/{controller}[/{params:.*}]', function ($request, $response, $args) use($app, $namespace) {
$contDI = $app->getContainer();
// Get dependencies.
// Get called method
$method = strtolower($request->getMethod());
// Get config namespace if necessary
$calledController = $namespace . '\\' . $args['controller'];
$controller = new $calledController();
if (is_a($controller, "\\mbarquin\\SlimDR\\ControllerInterface") === false) {
throw new \Exception('Controller must implement \\mbarquin\\SlimDR\\ControllerInterface');
}
$funcArgs = \mbarquin\SlimDR\Factory::getArgs($request, $response, $args, $contDI, $controller, $method);
call_user_func_array(array($controller, $method), $funcArgs);
});
}