diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
Diffstat (limited to 'vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php')
-rw-r--r-- | vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php new file mode 100644 index 00000000..abd68ed6 --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php | |||
@@ -0,0 +1,77 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Routing\Loader; | ||
13 | |||
14 | use Symfony\Component\Routing\RouteCollection; | ||
15 | use Symfony\Component\Config\Resource\DirectoryResource; | ||
16 | |||
17 | /** | ||
18 | * AnnotationDirectoryLoader loads routing information from annotations set | ||
19 | * on PHP classes and methods. | ||
20 | * | ||
21 | * @author Fabien Potencier <fabien@symfony.com> | ||
22 | */ | ||
23 | class AnnotationDirectoryLoader extends AnnotationFileLoader | ||
24 | { | ||
25 | /** | ||
26 | * Loads from annotations from a directory. | ||
27 | * | ||
28 | * @param string $path A directory path | ||
29 | * @param string|null $type The resource type | ||
30 | * | ||
31 | * @return RouteCollection A RouteCollection instance | ||
32 | * | ||
33 | * @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed | ||
34 | */ | ||
35 | public function load($path, $type = null) | ||
36 | { | ||
37 | $dir = $this->locator->locate($path); | ||
38 | |||
39 | $collection = new RouteCollection(); | ||
40 | $collection->addResource(new DirectoryResource($dir, '/\.php$/')); | ||
41 | $files = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY)); | ||
42 | usort($files, function (\SplFileInfo $a, \SplFileInfo $b) { | ||
43 | return (string) $a > (string) $b ? 1 : -1; | ||
44 | }); | ||
45 | |||
46 | foreach ($files as $file) { | ||
47 | if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) { | ||
48 | continue; | ||
49 | } | ||
50 | |||
51 | if ($class = $this->findClass($file)) { | ||
52 | $refl = new \ReflectionClass($class); | ||
53 | if ($refl->isAbstract()) { | ||
54 | continue; | ||
55 | } | ||
56 | |||
57 | $collection->addCollection($this->loader->load($class, $type)); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | return $collection; | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * {@inheritdoc} | ||
66 | */ | ||
67 | public function supports($resource, $type = null) | ||
68 | { | ||
69 | try { | ||
70 | $path = $this->locator->locate($resource); | ||
71 | } catch (\Exception $e) { | ||
72 | return false; | ||
73 | } | ||
74 | |||
75 | return is_string($resource) && is_dir($path) && (!$type || 'annotation' === $type); | ||
76 | } | ||
77 | } | ||