abstract class AnnotationClassLoader implements LoaderInterface

AnnotationClassLoader loads routing information from a PHP class and its methods.

You need to define an implementation for the getRouteDefaults() 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()
    {
    }
}

Properties

protected $reader
protected string $routeAnnotationClass
protected int $defaultRouteIndex

Methods

__construct(Reader $reader)

No description

setRouteAnnotationClass(string $class)

Sets the annotation class to read route properties from.

load(string $class, string|null $type = null)

Loads from annotations from a class.

addRoute(RouteCollection $collection, $annot, $globals, ReflectionClass $class, ReflectionMethod $method)

No description

bool
supports(mixed $resource, string|null $type = null)

Returns whether this class supports the given resource.

setResolver(LoaderResolverInterface $resolver)

Sets the loader resolver.

getResolver()

Gets the loader resolver.

string
getDefaultRouteName(ReflectionClass $class, ReflectionMethod $method)

Gets the default route name for a class method.

getGlobals(ReflectionClass $class)

No description

createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)

No description

configureRoute(Route $route, ReflectionClass $class, ReflectionMethod $method, $annot)

No description

Details

__construct(Reader $reader)

Parameters

Reader $reader

setRouteAnnotationClass(string $class)

Sets the annotation class to read route properties from.

Parameters

string $class A fully-qualified class name

load(string $class, string|null $type = null)

Loads from annotations from a class.

Parameters

string $class A class name
string|null $type The resource type or null if unknown

Exceptions

InvalidArgumentException When route can't be parsed

protected addRoute(RouteCollection $collection, $annot, $globals, ReflectionClass $class, ReflectionMethod $method)

Parameters

RouteCollection $collection
$annot
$globals
ReflectionClass $class
ReflectionMethod $method

bool supports(mixed $resource, string|null $type = null)

Returns whether this class supports the given resource.

Parameters

mixed $resource A resource
string|null $type The resource type or null if unknown

Return Value

bool True if this class supports the given resource, false otherwise

setResolver(LoaderResolverInterface $resolver)

Sets the loader resolver.

Parameters

LoaderResolverInterface $resolver

LoaderResolverInterface getResolver()

Gets the loader resolver.

Return Value

LoaderResolverInterface A LoaderResolverInterface instance

protected string getDefaultRouteName(ReflectionClass $class, ReflectionMethod $method)

Gets the default route name for a class method.

Parameters

ReflectionClass $class
ReflectionMethod $method

Return Value

string

protected getGlobals(ReflectionClass $class)

Parameters

ReflectionClass $class

protected createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)

Parameters

$path
$defaults
$requirements
$options
$host
$schemes
$methods
$condition

abstract protected configureRoute(Route $route, ReflectionClass $class, ReflectionMethod $method, $annot)

Parameters

Route $route
ReflectionClass $class
ReflectionMethod $method
$annot