Symfony2 API
Class

Symfony\Component\Routing\Loader\AnnotationClassLoader

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()
    {
    }
}

Methods

__construct(Reader $reader)

Constructor.

setRouteAnnotationClass(string $class)

Sets the annotation class to read route properties from.

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

Loads from annotations from a class.

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

Returns whether this class supports the given resource.

setResolver(LoaderResolverInterface $resolver)

Sets the loader resolver.

LoaderResolverInterface getResolver()

Gets the loader resolver.

Details

at line 80
public __construct(Reader $reader)

Constructor.

Parameters

Reader $reader

at line 90
public setRouteAnnotationClass(string $class)

Sets the annotation class to read route properties from.

Parameters

string $class A fully-qualified class name

at line 105
public RouteCollection 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

Return Value

RouteCollection A RouteCollection instance

Exceptions

InvalidArgumentException When route can't be parsed

at line 171
public 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

at line 179
public setResolver(LoaderResolverInterface $resolver)

Sets the loader resolver.

Parameters

LoaderResolverInterface $resolver A LoaderResolverInterface instance

at line 186
public LoaderResolverInterface getResolver()

Gets the loader resolver.

Return Value

LoaderResolverInterface A LoaderResolverInterface instance