本文整理匯總了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);
});
}