AttributeClassLoader
in package
implements
LoaderInterface
AttributeClassLoader loads routing information from a PHP class and its methods.
You need to define an implementation for the configureRoute() method. Most of the time, this method should define some PHP callable to be called for the route (a controller in MVC speak).
The #[Route] attribute can be set on the class (for global parameters), and on each method.
The #[Route] attribute main value is the route path. The attribute also recognizes several parameters: requirements, options, defaults, schemes, methods, host, and name. The name parameter is mandatory. Here is an example of how you should be able to use it:
#[Route('/Blog')]
class Blog
{
#[Route('/', name: 'blog_index')]
public function index()
{
}
#[Route('/{id}', name: 'blog_post', requirements: ["id" => '\d+'])]
public function show()
{
}
}
Tags
Table of Contents
Interfaces
- LoaderInterface
- LoaderInterface is the interface implemented by all loader classes.
Properties
- $defaultRouteIndex : int
- $env : string|null
- $reader : Reader|null
- $routeAnnotationClass : string
- $hasDeprecatedAnnotations : bool
Methods
- __construct() : mixed
- getResolver() : LoaderResolverInterface
- Gets the loader resolver.
- load() : mixed
- Loads a resource.
- setResolver() : void
- Sets the loader resolver.
- setRouteAnnotationClass() : void
- Sets the annotation class to read route properties from.
- supports() : bool
- Returns whether this class supports the given resource.
- addRoute() : void
- configureRoute() : void
- createRoute() : Route
- getDefaultRouteName() : string
- Gets the default route name for a class method.
- getGlobals() : array<string, mixed>
- getAnnotations() : iterable<int, Route>
- resetGlobals() : array<string|int, mixed>
Properties
$defaultRouteIndex
protected
int
$defaultRouteIndex
= 0
$env
protected
string|null
$env
$reader
in Symfony 6.4, this property will be removed in Symfony 7.
protected
Reader|null
$reader
$routeAnnotationClass
protected
string
$routeAnnotationClass
= \Symfony\Component\Routing\Attribute\Route::class
$hasDeprecatedAnnotations
private
bool
$hasDeprecatedAnnotations
= false
Methods
__construct()
public
__construct([string|null $env = null ]) : mixed
Parameters
- $env : string|null = null
getResolver()
Gets the loader resolver.
public
getResolver() : LoaderResolverInterface
Return values
LoaderResolverInterfaceload()
Loads a resource.
public
load(mixed $class[, string|null $type = null ]) : mixed
Parameters
- $class : mixed
- $type : string|null = null
Tags
setResolver()
Sets the loader resolver.
public
setResolver(LoaderResolverInterface $resolver) : void
Parameters
- $resolver : LoaderResolverInterface
setRouteAnnotationClass()
Sets the annotation class to read route properties from.
public
setRouteAnnotationClass(string $class) : void
Parameters
- $class : string
supports()
Returns whether this class supports the given resource.
public
supports(mixed $resource[, string|null $type = null ]) : bool
Parameters
- $resource : mixed
-
A resource
- $type : string|null = null
Return values
booladdRoute()
protected
addRoute(RouteCollection $collection, Route $annot, array<string|int, mixed> $globals, ReflectionClass $class, ReflectionMethod $method) : void
Parameters
- $collection : RouteCollection
- $annot : Route
-
or an object that exposes a similar interface
- $globals : array<string|int, mixed>
- $class : ReflectionClass
- $method : ReflectionMethod
configureRoute()
protected
abstract configureRoute(Route $route, ReflectionClass $class, ReflectionMethod $method, object $annot) : void
Parameters
- $route : Route
- $class : ReflectionClass
- $method : ReflectionMethod
- $annot : object
createRoute()
protected
createRoute(string $path, array<string|int, mixed> $defaults, array<string|int, mixed> $requirements, array<string|int, mixed> $options, string|null $host, array<string|int, mixed> $schemes, array<string|int, mixed> $methods, string|null $condition) : Route
Parameters
- $path : string
- $defaults : array<string|int, mixed>
- $requirements : array<string|int, mixed>
- $options : array<string|int, mixed>
- $host : string|null
- $schemes : array<string|int, mixed>
- $methods : array<string|int, mixed>
- $condition : string|null
Return values
RoutegetDefaultRouteName()
Gets the default route name for a class method.
protected
getDefaultRouteName(ReflectionClass $class, ReflectionMethod $method) : string
Parameters
- $class : ReflectionClass
- $method : ReflectionMethod
Return values
stringgetGlobals()
protected
getGlobals(ReflectionClass $class) : array<string, mixed>
Parameters
- $class : ReflectionClass
Return values
array<string, mixed>getAnnotations()
private
getAnnotations(ReflectionClass|ReflectionMethod $reflection) : iterable<int, Route>
Parameters
- $reflection : ReflectionClass|ReflectionMethod
Return values
iterable<int, Route>resetGlobals()
private
resetGlobals() : array<string|int, mixed>