Passed
Pull Request — master (#6127)
by Angel Fernando Quiroz
07:52
created

PluginEventSubscriberPass::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
nc 3
nop 1
dl 0
loc 16
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\DependencyInjection\Compiler;
8
9
use SplFileInfo;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Definition;
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use Symfony\Component\Finder\Finder;
15
16
class PluginEventSubscriberPass implements CompilerPassInterface
17
{
18
    /**
19
     * @inheritDoc
20
     */
21
    public function process(ContainerBuilder $container): void
22
    {
23
        $pluginSubscriberDir = __DIR__.'/../../../../public/plugin';
24
25
        $finder = new Finder();
26
        $finder->files()->in($pluginSubscriberDir)->name('*EventSubscriber.php');
27
28
        /** @var SplFileInfo $file */
29
        foreach ($finder as $file) {
30
            $className = pathinfo($file->getFilename(), PATHINFO_FILENAME);
31
32
            if (class_exists($className) && is_subclass_of($className, EventSubscriberInterface::class)) {
33
                $definition = new Definition($className);
34
                $definition->setAutowired(true);
35
                $definition->addTag('kernel.event_subscriber');
36
                $container->setDefinition($className, $definition);
37
            }
38
        }
39
    }
40
}