/** * {@inheritdoc} */ public function load($resource, $type = null) { if (!is_dir($resource)) { throw new \InvalidArgumentException(sprintf('Given resource of type "%s" is no directory.', $resource)); } $collection = new RouteCollection(); $directoryIterator = new \DirectoryIterator($resource); foreach ($directoryIterator as $file) { if ($file->getFilename() === '.' || $file->getFilename() === '..') { continue; } $imported = $this->processor->importResource($this, ClassUtils::findClassInFile($file->getPathname()), array(), null, null, 'rest'); $collection->addCollection($imported); } return $collection; }
/** * Returns controller locator by it's id. * * @param string $controller * * @throws \InvalidArgumentException * * @return array */ private function getControllerLocator($controller) { $class = null; $prefix = null; if (0 === strpos($controller, '@')) { $file = $this->locator->locate($controller); $controllerClass = ClassUtils::findClassInFile($file); if (false === $controllerClass) { throw new \InvalidArgumentException(sprintf('Can\'t find class for controller "%s"', $controller)); } $controller = $controllerClass; } if ($this->container->has($controller)) { // service_id $prefix = $controller . ':'; if (method_exists($this->container, 'enterScope')) { $this->container->enterScope('request'); $this->container->set('request', new Request()); } $class = get_class($this->container->get($controller)); if (method_exists($this->container, 'enterScope')) { $this->container->leaveScope('request'); } } elseif (class_exists($controller)) { // full class name $class = $controller; $prefix = $class . '::'; } elseif (false !== strpos($controller, ':')) { // bundle:controller notation try { $notation = $this->controllerParser->parse($controller . ':method'); list($class) = explode('::', $notation); $prefix = $class . '::'; } catch (\Exception $e) { throw new \InvalidArgumentException(sprintf('Can\'t locate "%s" controller.', $controller)); } } if (empty($class)) { throw new \InvalidArgumentException(sprintf('Class could not be determined for Controller identified by "%s".', $controller)); } return [$prefix, $class]; }