-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
FEATURE: Separate RouteConfiguration from Router #2970
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still like the direction, but I stumbled upon a major issue: This change removes the lazy loading & parsing of routes
(see #2970 (comment))
@sorenmalling here's my suggestion briefly scratched out: interface RoutesProvider
{
public function getRoutes(): Routes;
}
final class ConfigurationRoutesProvider implements RoutesProvider
{
private ?Routes $routes = null;
public function __construct(
private readonly ConfigurationManager $configurationManager
) {}
public function getRoutes(): Routes
{
return $this->routes ??= Routes::fromConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES));
}
}
final class Router implements RouterInterface
{
public function __construct(
private readonly RoutesProviderInterface $routesProvider,
) {}
// ...
} The extension point would be a custom implementation of the final class MyRoutesProvider implements RoutesProvider
{
private ?Routes $routes = null;
public function __construct(
private readonly ConfigurationRoutesProvider $configurationRoutesProvider,
) {}
public function getRoutes(): Routes
{
if ($this->routes === null) {
$this->routes = $this->appendCustomRoutes($this->configurationRoutesProvider->getRoutes());
}
return $this->>routes;
}
private function appendCustomRoutes(Routes $routes): Routes
{
// load routes from annotations etc.
}
} |
How about we put the extension point into the RoutesLoader class? Routes is a configuration, the Routes have been loaded, now extend that - we avoid having a new Provider concept, that requires overriding (which will lead to dropping the Yaml configurated routes, right?) |
@bwaidelich @mhsdesign Tried my best to implement suggestion and to address the injection issue. Will you re-review that concept of |
wow thank you so much @mficzel ;) |
I solved all open discussions and code suggestions, introduced a TestingRoutesProvider and targeted 9.0 this is now nearly finished. |
I cannot really self approve partly my own work but count this as a +0.5
f72e223
to
5256af2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this was a joined effort and i committed as well count me as half of a review :)
Thank you so much @sorenmalling for the initial improvement and @mficzel for making it work after the long pause. (And of course @bwaidelich for the discussions ^^)
Lets merge it to 9.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testing route provider could be moved to tests but other than that.
* @internal implementation detail. Please use {@see FunctionalTestCase::registerRoute} instead. | ||
*/ | ||
#[Flow\Scope("singleton")] | ||
final class TestingRoutesProvider implements RoutesProviderInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed with @mficzel this class resides here correctly.
Neos\Flow\Tests
has no proxy building and the TestingPrivilegeManager
also lives in Classes
.
Fyi phpstan 3 catched a bug in |
This separates the Routes configuration from the router by introducing a
RoutesProviderInterface
which will be used by the router implementation together with aConfigurationRoutesProvider
that implements the current configuration from Routes.yaml.Switching out the internal implementation of the
RoutesProviderInterface
can be done via Objects.yaml to add custom behaviour. But be aware that this is not covered by our api promises. All Implementations should include the routes provided by theConfigurationRoutesProvider
.This change also makes sure, that the RouteCommandController uses the current
RoutesProviderInterface
implementation, instead of hard coded Flow router. That ensures that all Routes available to the router are now also visible to route cli-commands.Fixes: #2948
Upgrade instructions
This change removes the methods
getRoutes
andaddRoute
from the Router that previously were mainly used in functional-tests as they were never part of the Router Interface.To adjust for that the existing utility
FunctionalTestCase->registerRoute
method has to be used instead ofFunctionalTestCase->router->addRoute
.The method
Router::setRoutesConfiguration
, which was also previously used for internal testing has been removed without official replacement. You could technically inject a custom routes provider to do so but be aware that this is internal behaviour.Review instructions
Run the ./flow routing:list command - you will see the list as expected
Checklist
FEATURE|TASK|BUGFIX
!!!
and have upgrade-instructions