PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Symfony/Component/Routing/Loader/AnnotationGlobLoader.php

http://github.com/fabpot/symfony
PHP | 76 lines | 28 code | 8 blank | 40 comment | 4 complexity | 8fc1242ddb14697c7491907cd39aea9d MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Loader;
  11. use Symfony\Component\Routing\RouteCollection;
  12. /**
  13. * AnnotationGlobLoader loads routing information from annotations set
  14. * on PHP classes and methods.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class AnnotationGlobLoader extends AnnotationDirectoryLoader
  19. {
  20. /**
  21. * Loads from annotations from a directory glob pattern.
  22. *
  23. * @param string $glob A directory glob pattern containing "*"
  24. * @param string $type The resource type
  25. *
  26. * @return RouteCollection A RouteCollection instance
  27. *
  28. * @throws \InvalidArgumentException When route can't be parsed
  29. */
  30. public function load($glob, $type = null)
  31. {
  32. $collection = new RouteCollection();
  33. foreach ($this->getAbsolutePaths($glob) as $path) {
  34. $collection->addCollection(parent::load($path, $type));
  35. }
  36. return $collection;
  37. }
  38. /**
  39. * Returns true if this class supports the given resource.
  40. *
  41. * @param mixed $resource A resource
  42. * @param string $type The resource type
  43. *
  44. * @return Boolean True if this class supports the given resource, false otherwise
  45. */
  46. public function supports($resource, $type = null)
  47. {
  48. return is_string($resource) && false !== strpos($resource, '*') && (!$type || 'annotation' === $type);
  49. }
  50. /**
  51. * Gets all absolute paths matched by expanding the glob pattern within all
  52. * resource search paths.
  53. *
  54. * @param string $glob
  55. *
  56. * @return array An array of paths matching the glob pattern
  57. */
  58. private function getAbsolutePaths($glob)
  59. {
  60. $dirs = array();
  61. foreach ($this->paths as $path) {
  62. if (false !== ($d = glob($path.DIRECTORY_SEPARATOR.$glob, GLOB_ONLYDIR | GLOB_BRACE))) {
  63. $dirs = array_merge($dirs, $d);
  64. }
  65. }
  66. return $dirs;
  67. }
  68. }