Skip to content

[Routing] add Multiclass per file loader #38414

@ybenhssaien

Description

@ybenhssaien

Description
Since the AnnotationFileLoader loads annotation on one class per file (which is a PSR recommendation) the framework may be able to load annotations from multiple class in the same file (may be usefull in same cases like a DefaultController with default actions ...)

The idea here is to add a AnnotationMultipleClassFileLoader with annotations type key to support multiple class per file declaration

Example

<?php

namespace App;

use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route(path="/", name="home")
 */
class IndexController
{
    public function __invoke()
    {
        return __METHOD__;
    }
}

class TestController
{
    /**
     * @Route(path="/test.{format}", name="test", requirements={"format": "\w+"}, defaults={"format": "html"})
     */
    public function test()
    {
        return __METHOD__;
    }

    /**
     * @Route(path="/test1.{format}", name="test1", requirements={"format": "\w+"}, defaults={"format": "html"})
     */
    public function test1()
    {
        return __METHOD__;
    }
}

AnnotationFileLoader Vs AnnotationMultipleClassFileLoader :

The first dump Annotation file is loaded with AnnotationFileLoader while the second Annotation file multiple class is loaded with AnnotationMultipleClassFileLoader :

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions