1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Kévin Dunglas <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This source file is subject to the MIT license that is bundled |
7
|
|
|
* with this source code in the file LICENSE. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Dunglas\ActionBundle\DependencyInjection; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
15
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
* |
20
|
|
|
* @author Kévin Dunglas <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class DunglasActionExtension extends Extension |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function load(array $configs, ContainerBuilder $container) |
28
|
|
|
{ |
29
|
|
|
$configuration = new Configuration(); |
30
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
31
|
|
|
|
32
|
|
|
foreach (['actions', 'commands'] as $type) { |
33
|
|
|
if (!$this->isConfigEnabled($container, $config[$type])) { |
34
|
|
|
continue; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$directories = $this->resolveDirectories($container, $config[$type]['directories']); |
38
|
|
|
|
39
|
|
|
$directories = array_merge($directories, $this->getAutodiscoveredDirectories( |
40
|
|
|
$container, |
41
|
|
|
$config[$type]['autodiscover']['directories'] |
42
|
|
|
)); |
43
|
|
|
|
44
|
|
|
$container->setParameter(sprintf('dunglas_action.%s.directories', $type), $directories); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ($this->isConfigEnabled($container, $config['actions']) && class_exists('Symfony\Component\Routing\Loader\AnnotationDirectoryLoader')) { |
48
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
49
|
|
|
$loader->load('routing.xml'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Gets the list of directories to autodiscover. |
55
|
|
|
* |
56
|
|
|
* @param ContainerBuilder $container |
57
|
|
|
* @param string $directory |
|
|
|
|
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
private function resolveDirectories(ContainerBuilder $container, $directories) { |
62
|
|
|
$kernelRootDir = $container->getParameter('kernel.root_dir'); |
63
|
|
|
|
64
|
|
|
foreach ($directories as &$directory) { |
65
|
|
|
$directory = $kernelRootDir.DIRECTORY_SEPARATOR.$directory; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $directories; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Gets the list of directories to autodiscover. |
73
|
|
|
* |
74
|
|
|
* @param ContainerBuilder $container |
75
|
|
|
* @param string[] $directories |
76
|
|
|
* |
77
|
|
|
* @return string[] |
78
|
|
|
*/ |
79
|
|
|
private function getAutodiscoveredDirectories(ContainerBuilder $container, $directories) |
80
|
|
|
{ |
81
|
|
|
$resolvedDirectories = []; |
82
|
|
|
|
83
|
|
|
foreach ($container->getParameter('kernel.bundles') as $bundle) { |
84
|
|
|
$reflectionClass = new \ReflectionClass($bundle); |
85
|
|
|
$bundleDirectory = dirname($reflectionClass->getFileName()); |
86
|
|
|
|
87
|
|
|
foreach ($directories as $discovery) { |
88
|
|
|
$actionDirectory = $bundleDirectory.DIRECTORY_SEPARATOR.$discovery; |
89
|
|
|
|
90
|
|
|
if (file_exists($actionDirectory)) { |
91
|
|
|
$resolvedDirectories[] = $actionDirectory; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $resolvedDirectories; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.