Module::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrineFixtures;
6
7
use Arp\LaminasDoctrineFixtures\Command\ImportCommand;
8
use Doctrine\ORM\Tools\Console\ConsoleRunner;
9
use Laminas\EventManager\Event;
10
use Laminas\ModuleManager\ModuleManager;
11
use Psr\Container\ContainerInterface;
12
use Symfony\Component\Console\Application;
13
14
/**
15
 * @author  Alex Patterson <[email protected]>
16
 * @package Arp\LaminasDoctrineFixtures
17
 */
18
class Module
19
{
20
    /**
21
     * @param ModuleManager $moduleManager
22
     */
23
    public function init(ModuleManager $moduleManager): void
24
    {
25
        $eventManager = $moduleManager->getEventManager()->getSharedManager();
26
27
        if (null === $eventManager) {
28
            return;
29
        }
30
31
        $eventManager->attach('doctrine', 'loadCli.post', [$this, 'addImportCommand']);
32
    }
33
34
    /**
35
     * @param Event $event
36
     */
37
    public function addImportCommand(Event $event): void
38
    {
39
        /** @var Application $cliApplication */
40
        $cliApplication = $event->getTarget();
41
42
        $container = $event->getParam('ServiceManager', null);
43
44
        if (
45
            null === $container
46
            || ! $container instanceof ContainerInterface
47
            || ! $container->has(ImportCommand::class)
48
        ) {
49
            return;
50
        }
51
52
        ConsoleRunner::addCommands($cliApplication);
53
54
        $cliApplication->add($container->get(ImportCommand::class));
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getConfig(): array
61
    {
62
        return require __DIR__ . '/../config/module.config.php';
63
    }
64
}
65