You are here

public function AnnotationClassLoader::load in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/routing/Loader/AnnotationClassLoader.php \Symfony\Component\Routing\Loader\AnnotationClassLoader::load()

Loads from annotations from a class.

Parameters

string $class A class name:

string|null $type The resource type:

Return value

RouteCollection A RouteCollection instance

Throws

\InvalidArgumentException When route can't be parsed

File

vendor/symfony/routing/Loader/AnnotationClassLoader.php, line 105

Class

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

Namespace

Symfony\Component\Routing\Loader

Code

public function load($class, $type = null) {
  if (!class_exists($class)) {
    throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
  }
  $class = new \ReflectionClass($class);
  if ($class
    ->isAbstract()) {
    throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
  }
  $globals = $this
    ->getGlobals($class);
  $collection = new RouteCollection();
  $collection
    ->addResource(new FileResource($class
    ->getFileName()));
  foreach ($class
    ->getMethods() as $method) {
    $this->defaultRouteIndex = 0;
    foreach ($this->reader
      ->getMethodAnnotations($method) as $annot) {
      if ($annot instanceof $this->routeAnnotationClass) {
        $this
          ->addRoute($collection, $annot, $globals, $class, $method);
      }
    }
  }
  return $collection;
}