Skip to content

Custom annotation classes #4

@donquixote

Description

@donquixote

I was looking at AnnotatedRouteControllerLoader::configureRoute().
Currently this supports a limited and hardcoded selection of annotation classes.

What about a new interface for generic route config annotations, like this:

interface RouteConfigurationAnnotationInterface {
  public function configureRoute(Route $route);
}

Then in AnnotatedRouteControllerLoader::configureRoute() we would add this:

            } elseif ($configuration instanceof RouteConfigurationAnnotationInterface) {
                $configuration->configureRoute($route);

As a (controversial) use case, currently I am thinking of this: #3
E.g. a @MenuLink(..) annotation, which would set an option in the route, which later can be read by a menu link plugin derivative.

Maybe there are less controversial use cases.
E.g. shortcuts for @Security: Instead of @Security(access=true), one could then write @AccessPublic.
Or instead of @Security(role="admin"), write @Role("admin")

Or maybe a @RouteTitle("Hello") or a generic @Option(_title = "Hello"), instead of @Route("/path/to/hello", options = {"title" = "Hello"})

Ok, I am not sure yet if my examples are really worthwhile, but I do think it would open some interesting possibilities.

Btw, I prefer longer identifiers like @RouteTitle over just @Title, this reduces the ambiguity on IDE autocomplete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions