How Can I configure routing that package yiisoft/swagger
is using? I installed all necessary packages, but still can’t use routes like Route::...
Documentation of yiisoft/router
https://github.com/yiisoft/router says that I have to do somenthing like:
<code>// Define routes
$routes = [
Route::get('/')
->action(static function (ServerRequestInterface $request, RequestHandlerInterface $next) use ($responseFactory) {
$response = $responseFactory->createResponse();
$response
->getBody()
->write('You are at homepage.');
return $response;
}),
Route::get('/test/{id:w+}')
->action(static function (CurrentRoute $currentRoute, RequestHandlerInterface $next) use ($responseFactory) {
$id = $currentRoute->getArgument('id');
$response = $responseFactory->createResponse();
$response
->getBody()
->write('You are at test with argument ' . $id);
return $response;
})
];
// Add routes defined to route collector
$collector = $container->get(RouteCollectorInterface::class);
$collector->addGroup(Group::create(null)->routes($routes));
// Initialize URL matcher
/** @var UrlMatcherInterface $urlMatcher */
$urlMatcher = new UrlMatcher(new RouteCollection($collector));
// Do the match against $request which is PSR-7 ServerRequestInterface.
$result = $urlMatcher->match($request);
if (!$result->isSuccess()) {
// 404
}
// $result->arguments() contains arguments from the match.
// Run middleware assigned to a route found.
$response = $result->process($request, $notFoundHandler);
</code>
<code>// Define routes
$routes = [
Route::get('/')
->action(static function (ServerRequestInterface $request, RequestHandlerInterface $next) use ($responseFactory) {
$response = $responseFactory->createResponse();
$response
->getBody()
->write('You are at homepage.');
return $response;
}),
Route::get('/test/{id:w+}')
->action(static function (CurrentRoute $currentRoute, RequestHandlerInterface $next) use ($responseFactory) {
$id = $currentRoute->getArgument('id');
$response = $responseFactory->createResponse();
$response
->getBody()
->write('You are at test with argument ' . $id);
return $response;
})
];
// Add routes defined to route collector
$collector = $container->get(RouteCollectorInterface::class);
$collector->addGroup(Group::create(null)->routes($routes));
// Initialize URL matcher
/** @var UrlMatcherInterface $urlMatcher */
$urlMatcher = new UrlMatcher(new RouteCollection($collector));
// Do the match against $request which is PSR-7 ServerRequestInterface.
$result = $urlMatcher->match($request);
if (!$result->isSuccess()) {
// 404
}
// $result->arguments() contains arguments from the match.
// Run middleware assigned to a route found.
$response = $result->process($request, $notFoundHandler);
</code>
// Define routes
$routes = [
Route::get('/')
->action(static function (ServerRequestInterface $request, RequestHandlerInterface $next) use ($responseFactory) {
$response = $responseFactory->createResponse();
$response
->getBody()
->write('You are at homepage.');
return $response;
}),
Route::get('/test/{id:w+}')
->action(static function (CurrentRoute $currentRoute, RequestHandlerInterface $next) use ($responseFactory) {
$id = $currentRoute->getArgument('id');
$response = $responseFactory->createResponse();
$response
->getBody()
->write('You are at test with argument ' . $id);
return $response;
})
];
// Add routes defined to route collector
$collector = $container->get(RouteCollectorInterface::class);
$collector->addGroup(Group::create(null)->routes($routes));
// Initialize URL matcher
/** @var UrlMatcherInterface $urlMatcher */
$urlMatcher = new UrlMatcher(new RouteCollection($collector));
// Do the match against $request which is PSR-7 ServerRequestInterface.
$result = $urlMatcher->match($request);
if (!$result->isSuccess()) {
// 404
}
// $result->arguments() contains arguments from the match.
// Run middleware assigned to a route found.
$response = $result->process($request, $notFoundHandler);
But where to put this configuration code? All of this in routes.php?
When I just add route configuration like:
<code>Route::get('/health-check')->action([HealthCheckController::class, 'index']),
</code>
<code>Route::get('/health-check')->action([HealthCheckController::class, 'index']),
</code>
Route::get('/health-check')->action([HealthCheckController::class, 'index']),
I receive exception `Exception (Invalid Configuration)
<code>'yiibaseInvalidConfigException' with message 'URL rule class must implement UrlRuleInterface.
</code>
<code>'yiibaseInvalidConfigException' with message 'URL rule class must implement UrlRuleInterface.
</code>
'yiibaseInvalidConfigException' with message 'URL rule class must implement UrlRuleInterface.
I have tried to put this config in routes.php
file but without success.