-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatcher: handle and find #328
Comments
It's util to Clockwork. I created a DataSource to use on Clockwork BEFOREAFTERLeagueRouterDataSource<?php
namespace App\DataSources;
use Clockwork\DataSource\DataSourceInterface;
use Clockwork\Request\Request;
use League\Route\Dispatcher;
use League\Route\Router;
// it is also necessary to obtain the array of routes
class AppRouter extends Router
{
public function getData(): array
{
return $this->routeCollector->getData();
}
}
class LeagueRouterDataSource implements DataSourceInterface
{
public function __construct(
protected AppRouter $router,
protected ServerRequestInterface $request
) {
}
public function resolve(Request $request)
{
$request->controller = $this->getController();
}
protected function getController()
{
$data = $this->router->getData();
$dispatcher = new Dispatcher($data);
$dispatcher->setStrategy($this->router->getStrategy());
$match = $dispatcher->dispatchAndReturn($this->request);
// or
// $match = $dispatcher->dispatch($method, $uri);
// dispatch method is public and not be necessary create the dispatchAndReturn method
$callable = $match[1]->getCallable();
// if use magic method __invoke
if (is_object($callable)) {
return get_class($callable);
}
// if use syntax [controller, method] or "controller::method"
if (is_array($callable)) {
[$controller, $method] = $callable;
return get_class($controller) . "@{$method}";
}
// if use anonymous function
return "Closure";
}
} |
I know this is very late, but what is the intended use case for this? I'll close the issue for now, but will re-open and consider for 6.1 release if a good use case is provided |
The main aim of this function is the ability to get meta data about routing for the dynamic testing purposes |
@vanodevium can you expand a little? For example, would an array of all of the route objects be useful? Or are you looking for something key => value based? Because of how the groups, and pass through to FastRoute works, it'd be handy to have as much info as possible about what you're trying to achieve so I can come up with something that will be useful for this but also maybe in other ways. |
I'm asking mainly because we also have #330 which seems like it might be similar. |
Imho, for my case, there would be awesome to take concrete handler for concrete route string |
Is there any way to only find the specific handler, but not handle it?
In simple way, this is original dispatchRequest()
But I wanna method which return only
$match
array, without processing. Something like:The text was updated successfully, but these errors were encountered: