-
-
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: Add Flow\Route
Attribute/Annotation
#3325
Conversation
3f88955
to
b156152
Compare
This one needs a little discussion:
|
ec69d07
to
fbdfa07
Compare
FYI: Related discussion: https://discuss.neos.io/t/rfc-future-of-routing-mvc-in-flow/6535 |
@mhsdesign @bwaidelich i am a bit frustraded how this turns out. While i like the suggestions on discuss the approach "we have to rewrite routing first" basically excludes this from beeing in Neos 9 (this close to a release we should not introduce any big changes we do not strictly need) which means we are stuck with Routes.yaml and in extension Policy.yaml for 9.0 I also see no easy way to only include part 1 of the discuss post (configure route provideres in seettings Regarding binding the current implementation to |
@mficzel I'm sorry that you're frustrated. But I think this is due to a misunderstanding: IMO there is no reason not to proceed with this one, we can always refactor it to use a different integration mechanism lateron. There's only two issues that we should tackle/decide upon IMO:
I think it would actually be pretty straightforward to skip the provider: '<providerClassName>' in our default |
@bwaidelich the handling of the whole Also specifying a provider via setting is probably not that trivial as one will have to pass at leas the package key and for that either allow options or pass the key from the configuration in any case. Imho it would make sense to just include searching for route attributes into what happens when you add a package key to |
Let's talk, I have some ideas and I think that they can solve the remaining issues without a lot of work |
fbdfa07
to
a1d8623
Compare
Regarding Cache flushing i added this class to the annotationCacheFlusher not sure this actually works as i could not find prior uses. |
@mficzel A little bit hacky, but with the following change: diff --git a/Neos.Flow/Classes/Configuration/Loader/RoutesLoader.php b/Neos.Flow/Classes/Configuration/Loader/RoutesLoader.php
index a02a5c152..8b2229c31 100644
--- a/Neos.Flow/Classes/Configuration/Loader/RoutesLoader.php
+++ b/Neos.Flow/Classes/Configuration/Loader/RoutesLoader.php
@@ -96,6 +96,13 @@ class RoutesLoader implements LoaderInterface
if (isset($routeFromSettings['suffix'])) {
$subRoutesConfiguration['suffix'] = $routeFromSettings['suffix'];
}
+ if (isset($routeFromSettings['provider'])) {
+ $routeDefinitions[] = [
+ 'name' => $packageKey,
+ 'provider' => $routeFromSettings['provider'],
+ ];
+ continue;
+ }
$routeDefinitions[] = [
'name' => $packageKey,
'uriPattern' => '<' . $subRoutesName . '>',
@@ -128,6 +135,10 @@ class RoutesLoader implements LoaderInterface
}
$mergedSubRoutesConfiguration = [$routeConfiguration];
foreach ($routeConfiguration['subRoutes'] as $subRouteKey => $subRouteOptions) {
+ if (isset($subRouteOptions['provider'])) {
+ $mergedRoutesConfiguration[] = $subRouteOptions;
+ continue;
+ }
if (!isset($subRouteOptions['package'])) {
throw new ParseErrorException(sprintf('Missing package configuration for SubRoute in Route "%s".', ($routeConfiguration['name'] ?? 'unnamed Route')), 1318414040);
}
diff --git a/Neos.Flow/Classes/Mvc/Routing/ConfigurationRoutesProvider.php b/Neos.Flow/Classes/Mvc/Routing/ConfigurationRoutesProvider.php
index f876008e8..a4567c559 100644
--- a/Neos.Flow/Classes/Mvc/Routing/ConfigurationRoutesProvider.php
+++ b/Neos.Flow/Classes/Mvc/Routing/ConfigurationRoutesProvider.php
@@ -6,6 +6,8 @@ namespace Neos\Flow\Mvc\Routing;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
+use Neos\Flow\Configuration\Loader\RoutesLoader;
+use Neos\Flow\ObjectManagement\ObjectManagerInterface;
/**
* @Flow\Scope("singleton")
@@ -15,13 +17,26 @@ final class ConfigurationRoutesProvider implements RoutesProviderInterface
private ConfigurationManager $configurationManager;
public function __construct(
- ConfigurationManager $configurationManager
+ ConfigurationManager $configurationManager,
+ private ObjectManagerInterface $objectManager,
) {
$this->configurationManager = $configurationManager;
}
public function getRoutes(): Routes
{
- return Routes::fromConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES));
+ $routes = [];
+ foreach ($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES) as $routeConfiguration) {
+ if (isset($routeConfiguration['provider'])) {
+ $provider = $this->objectManager->get($routeConfiguration['provider']);
+ assert($provider instanceof RoutesProviderInterface);
+ foreach ($provider->getRoutes() as $route) {
+ $routes[] = $route;
+ }
+ continue;
+ }
+ $routes[] = Route::fromConfiguration($routeConfiguration);
+ }
+ return Routes::create(...$routes);
}
} I can register custom providers via Neos:
Flow:
mvc:
routes:
'Foo':
provider: 'Some\Package\SomeRoutesProvider'
position: 'start' we could also add |
a1d8623
to
55eaaf6
Compare
Re your discussion points from 2 weeks ago:
I would say no because they are too easily confused with query parameters. We could always add it lateron
Personally I don't really care, but IMO there is no reason not to (but it could always be added lateron)
That would be solved with an explicit activation like suggested above ps: if you force push changes it makes it really hard to follow the progress |
318f6e6
to
fee7d9b
Compare
@bwaidelich it works now but is ugly as hell for now ... moved most of the logic of routes configuration loader into the ConfigurationRoutesProvider and integrated the annotation handling there. Have to figure out how to seperate and test this later. Also i think that adding "pathPrefix" and "additionalRouteProviders" to the Setting |
fee7d9b
to
096ae8e
Compare
The `Flow\Route` attribute allows to define routes directly on the affected method. This allows to avoid dealing with Routes.yaml in projects in simple cases where is sometimes is annoying to look up the exact syntax for that. Hint: While this is a very convenient way to add routes in project code it should not be used in libraries/packages that expect to be configured for the outside. In such cases the Routes.yaml is still preferred as it is easier to overwrite. Usage: ```php use Neos\Flow\Mvc\Controller\ActionController; use Neos\Flow\Annotations as Flow; class ExampleController extends ActionController { #[Flow\Route(uriPattern:'my/path', httpMethods: ['get'])] public function someAction(): void { } #[Flow\Route(uriPattern:'my/other/b-path', defaults: ['test' => 'b'])] #[Flow\Route(uriPattern:'my/other/c-path', defaults: ['test' => 'c'])] public function otherAction(): void { } } ``` The package: `WebSupply.RouteAnnotation` by @sorenmalling implemented similar ideas earlier. Resolves: neos#2059
372d18a
to
0d17819
Compare
…derOptions` in Settings `Neos.Flow.mvc.routes` ``` Neos: Flow: mvc: routes: Vendor.Example: provider: \Neos\Flow\Mvc\Routing\RouteAnnotationRoutesProvider providerOptions: classNames: - Vendor\Example\Controller\ExampleController ```
0d17819
to
6877a05
Compare
Jain if we make it purely specific for the for custom controllers i wouldnt want any suffix magic and have in |
at first. I don't think it's fair to block a new feature because it does not include another feature
I agree – we can just add a check for the controller base class and omit the magic if it's not a Flow ActionController. But IMO this can be done in a separate PR |
Agreed.
okay so exactly as described above in point 2?
but regarding:
i dont see a reason for that, a pr should IMO be self contained and complete. But dont worry i will prepare the necessary adjustments as it was my idea. Dont want to chase anyone around ^^ Regarding But it seems we want to go the route (hatahahah) of allowing the annotation to be placed at some point on methods and classes? class MyThingController extends ActionController
{
// @package My.Package
// @controller MyThing
// @action some
#[Flow\Route(path: 'foo')]
public function someAction()
{
}
} and // @package My.Package
// @controller MyRest
#[Flow\Route(path: 'foo')]
class MyRestController extends RestController
{
private function get()
{
}
private function post()
{
}
} |
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.
Thanks a lot, this was a struggle, I actually would rather hit merge now than later, I think @mhsdesign concerns can and should all be tackled in a different PR, it's important to remmeber that just because we decided on a redirection it's not reality yet and the controller chnages are not fully in not even speaking about documenting them. So IMHO totally fine if this doesn't work correctly for other controllers that are not fully there yet.
So giving this until tomorrow morning, then anything else becomes a separate PR as this here will be merged. |
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.
While i adjust the above ill also take care of these things ... lets see if i pass your constraints of tomorrow, but i have a lot going on at the moment
class ExampleController extends ActionController | ||
{ | ||
#[Flow\Route(uriPattern:'my/path', httpMethods: ['GET'])] | ||
public function someAction(): void | ||
{ | ||
} | ||
|
||
#[Flow\Route(uriPattern:'my/other/b-path', defaults: ['test' => 'b'])] | ||
#[Flow\Route(uriPattern:'my/other/c-path', defaults: ['test' => 'c'])] | ||
public function otherAction(string $test): void | ||
{ | ||
} | ||
} |
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.
ill try to add a functional test where once can see the feature 1 to 1 in action. Currently the unit tests are cool to have but really obscure :D
@kitsunet and me agreed to just allow this feature at first on the That being said, there will be a followup, and we are still developing Flow 9 so this must not necessary be the end of it - but even if it were and we only find a sane solution in Flow 9.1 it should be acceptable as this feature is itself a milestone. I will try to provide the constraints and the adjustments above today unless someone else does it ;) |
Neos.Flow/Tests/Unit/Mvc/Routing/AttributeRoutesProviderTest.php
Outdated
Show resolved
Hide resolved
Can we get a grip on this one or what is still blocking that from being merged, @mhsdesign ? |
I'll merge this as soon as tests are done, everything else can really happen in follow ups. |
I wish you were so eager with other prs ;) Two questions:
I would say we need one That means: The naming is of course discussable but i think it makes more sense. Also by that we can clearly document the one interface as api and describe how it can be used. Does this direction make sense to you? |
Likewise :)
But that should almost always be the case, right? I hope that the route is only evaluated if it hasn't been hit before and I'd say that's totally fine
Yes, it's special and a bit weird. But I don't think that it's a problem we have to solve:
IMO that's just a matter of documentation and it's quite a low-level API anyways |
FYI: Unfortunately this does not seem to work in production context, see #3400 |
#3401 is the bugfix just to have it refrenced here as well |
The
Flow\Route
attribute allows to define routes directly on the affected method. This allows to avoid dealing with Routes.yaml in projects in simple cases where is sometimes is annoying to look up the exact syntax for that.Usage:
To use annotation routes packages have to register the
AttributeRoutesProviderFactory
inNeos.Flow.mvc.routes
with Controller classNames or patterns.Settings.yaml:
This pr also adds the general option to register
provider
andproviderOptions
in the SettingNeos.Flow.mvc.routes
which was required obviously.The package:
WebSupply.RouteAnnotation
by @sorenmalling implemented similar ideas earlier.Resolves: #2059
Upgrade instructions
Review instructions
Alsow see: #3324 resolving #2060, both solutions ideally would work hand in hand
Checklist
FEATURE|TASK|BUGFIX
!!!
and have upgrade-instructions