public function load($class)
{
if (!class_exists($class)) {
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
}
$class = new \ReflectionClass($class);
$annotClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
$globals = array(
'pattern' => '',
'requirements' => array(),
'options' => array(),
'defaults' => array(),
);
if ($annot = $this->reader->getClassAnnotation($class, $annotClass)) {
if (null !== $annot->getPattern()) {
$globals['pattern'] = $annot->getPattern();
}
if (null !== $annot->getRequirements()) {
$globals['requirements'] = $annot->getRequirements();
}
if (null !== $annot->getOptions()) {
$globals['options'] = $annot->getOptions();
}
if (null !== $annot->getDefaults()) {
$globals['defaults'] = $annot->getDefaults();
}
}
$this->reader->setDefaultAnnotationNamespace('Symfony\\Component\\Routing\\Annotation\\');
$collection = new RouteCollection();
foreach ($class->getMethods() as $method) {
if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
if (null === $annot->getName()) {
$annot->setName($this->getDefaultRouteName($class, $method));
}
$defaults = array_merge($globals['defaults'], $annot->getDefaults());
$requirements = array_merge($globals['requirements'], $annot->getRequirements());
$options = array_merge($globals['options'], $annot->getOptions());
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options);
$this->configureRoute($route, $class, $method);
$collection->add($annot->getName(), $route);
}
}
return $collection;
}