These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * This file is part of the PommProject/PommBundle package. |
||
4 | * |
||
5 | * (c) 2014 - 2016 Grégoire HUBERT <[email protected]> |
||
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 PommProject\PommBundle\DependencyInjection\Compiler; |
||
11 | |||
12 | use Symfony\Component\DependencyInjection as DI; |
||
13 | |||
14 | /** |
||
15 | * Class PoolerPass |
||
16 | * @package PommProject\PommBundle\DependencyInjection\Compiler |
||
17 | * @author Miha Vrhovnik |
||
18 | */ |
||
19 | class ModelPass implements DI\Compiler\CompilerPassInterface |
||
20 | { |
||
21 | public function process(DI\ContainerBuilder $container) |
||
22 | { |
||
23 | $this->addTagged($container, 'pomm.model', 'pomm.pooler.model', 'getModel'); |
||
24 | |||
25 | $this->addTagged($container, 'pomm.model_layer', 'pomm.pooler.model_layer', 'getModelLayer'); |
||
26 | } |
||
27 | |||
28 | private function addTagged(DI\ContainerBuilder $container, $tag, $defaultServiceId, $method) |
||
29 | { |
||
30 | /** @var DI\Definition[] $definitions */ |
||
31 | $definitions = []; |
||
32 | |||
33 | // find all service IDs with the appropriate tag |
||
34 | $taggedServices = $container->findTaggedServiceIds($tag); |
||
35 | |||
36 | foreach ($taggedServices as $id => $tags) { |
||
37 | $class = $container->getDefinition($id) |
||
38 | ->getClass() |
||
39 | ; |
||
40 | |||
41 | $serviceId = isset($tags[0]['pooler']) ? $tags[0]['pooler'] : $defaultServiceId; |
||
42 | $sessionId = isset($tags[0]['session']) ? $tags[0]['session'] : 'pomm.default_session'; |
||
43 | |||
44 | if (!array_key_exists($serviceId, $definitions)) { |
||
45 | if ($container->hasDefinition($serviceId)) { |
||
46 | $definitions[$serviceId] = $container->getDefinition($serviceId); |
||
47 | |||
48 | $interface = 'PommProject\PommBundle\Model\ServiceMapInterface'; |
||
49 | if (!in_array($interface, class_implements($definitions[$serviceId]->getClass()), true)) { |
||
50 | throw new \RuntimeException(sprintf('Your pooler should implement %s.', $interface)); |
||
51 | } |
||
52 | } else { |
||
53 | throw new \RuntimeException(sprintf('There is no pooler service with id %s.', $serviceId)); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | $definitions[$serviceId]->addMethodCall('addModelToServiceMapping', [$class, $id . '.pomm.inner']); |
||
58 | |||
59 | $old = $container->getDefinition($id); |
||
60 | $old->setPublic(true); |
||
61 | $container->removeDefinition($id); |
||
62 | $container->addDefinitions([$id . '.pomm.inner' => $old]); |
||
63 | |||
64 | $service = $container->register($id, $old->getClass()) |
||
65 | ->setFactory([new DI\Reference($sessionId), $method]) |
||
66 | ->addArgument($old->getClass()) |
||
67 | ; |
||
68 | |||
69 | if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.3', '<')) { |
||
70 | $service->addAutowiringType($old->getClass()); |
||
0 ignored issues
–
show
|
|||
71 | } |
||
72 | |||
73 | $container->setAlias($class, $id); |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.