AnnotationClassLoader
in package
implements
LoaderInterface
AnnotationClassLoader 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 annotation can be set on the class (for global parameters), and on each method.
The @Route annotation main value is the route path. The annotation 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
Interfaces, Classes and Traits
- LoaderInterface
Table of Contents
- $defaultRouteIndex : int
- $reader : mixed
- $routeAnnotationClass : string
- __construct() : mixed
- getResolver() : mixed
- {@inheritdoc}
- load() : RouteCollection
- Loads from annotations from a class.
- setResolver() : mixed
- {@inheritdoc}
- setRouteAnnotationClass() : mixed
- Sets the annotation class to read route properties from.
- supports() : mixed
- {@inheritdoc}
- addRoute() : mixed
- configureRoute() : mixed
- createRoute() : mixed
- getDefaultRouteName() : string
- Gets the default route name for a class method.
- getGlobals() : mixed
- resetGlobals() : mixed
Properties
$defaultRouteIndex
protected
int
$defaultRouteIndex
= 0
$reader
protected
mixed
$reader
$routeAnnotationClass
protected
string
$routeAnnotationClass
= 'Symfony\Component\Routing\Annotation\Route'
Methods
__construct()
public
__construct(Reader $reader) : mixed
Parameters
- $reader : Reader
Return values
mixed —getResolver()
{@inheritdoc}
public
getResolver() : mixed
Return values
mixed —load()
Loads from annotations from a class.
public
load(string $class[, string|null $type = null ]) : RouteCollection
Parameters
- $class : string
-
A class name
- $type : string|null = null
-
The resource type
Tags
Return values
RouteCollection —A RouteCollection instance
setResolver()
{@inheritdoc}
public
setResolver(LoaderResolverInterface $resolver) : mixed
Parameters
- $resolver : LoaderResolverInterface
Return values
mixed —setRouteAnnotationClass()
Sets the annotation class to read route properties from.
public
setRouteAnnotationClass(string $class) : mixed
Parameters
- $class : string
-
A fully-qualified class name
Return values
mixed —supports()
{@inheritdoc}
public
supports(mixed $resource[, mixed $type = null ]) : mixed
Parameters
- $resource : mixed
- $type : mixed = null
Return values
mixed —addRoute()
protected
addRoute(RouteCollection $collection, Route $annot, array<string|int, mixed> $globals, ReflectionClass $class, ReflectionMethod $method) : mixed
Parameters
- $collection : RouteCollection
- $annot : Route
-
or an object that exposes a similar interface
- $globals : array<string|int, mixed>
- $class : ReflectionClass
- $method : ReflectionMethod
Return values
mixed —configureRoute()
protected
abstract configureRoute(Route $route, ReflectionClass $class, ReflectionMethod $method, mixed $annot) : mixed
Parameters
- $route : Route
- $class : ReflectionClass
- $method : ReflectionMethod
- $annot : mixed
Return values
mixed —createRoute()
protected
createRoute(mixed $path, mixed $defaults, mixed $requirements, mixed $options, mixed $host, mixed $schemes, mixed $methods, mixed $condition) : mixed
Parameters
- $path : mixed
- $defaults : mixed
- $requirements : mixed
- $options : mixed
- $host : mixed
- $schemes : mixed
- $methods : mixed
- $condition : mixed
Return values
mixed —getDefaultRouteName()
Gets the default route name for a class method.
protected
getDefaultRouteName(ReflectionClass $class, ReflectionMethod $method) : string
Parameters
- $class : ReflectionClass
- $method : ReflectionMethod
Return values
string —getGlobals()
protected
getGlobals(ReflectionClass $class) : mixed
Parameters
- $class : ReflectionClass
Return values
mixed —resetGlobals()
private
resetGlobals() : mixed