Completed
Pull Request — master (#84)
by Daniel
02:13
created

EventDispatchingGridMetadataFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
use Psi\Component\Grid\Event\GridMetadataEvent;
8
use Psi\Component\Grid\Metadata\GridMetadata;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
11
class EventDispatchingGridMetadataFactory implements GridMetadataFactoryInterface
12
{
13
    /**
14
     * @var GridMetadataFactoryInterface
15
     */
16
    private $innerFactory;
17
18
    /**
19
     * @var EventDispatcherInterface
20
     */
21
    private $eventDispatcher;
22
23
    public function __construct(
24
        GridMetadataFactoryInterface $innerFactory,
25
        EventDispatcherInterface $eventDispatcher
26
    ) {
27
        $this->innerFactory = $innerFactory;
28
        $this->eventDispatcher = $eventDispatcher;
29
    }
30
31
    public function getGridMetadata(string $classFqn, string $variant): GridMetadata
32
    {
33
        $gridMetadata = $this->innerFactory->getGridMetadata($classFqn, $variant);
34
        $event = new GridMetadataEvent($gridMetadata);
35
        $this->eventDispatcher->dispatch(Events::METADATA_LOADED, $event);
36
37
        return $event->getMetadata();
38
    }
39
}
40