1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\FixturesBundle\Loader; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\FixturesBundle\Listener\AfterSuiteListenerInterface; |
15
|
|
|
use Sylius\Bundle\FixturesBundle\Listener\BeforeSuiteListenerInterface; |
16
|
|
|
use Sylius\Bundle\FixturesBundle\Listener\SuiteEvent; |
17
|
|
|
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Kamil Kokot <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class HookableSuiteLoader implements SuiteLoaderInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var SuiteLoaderInterface |
26
|
|
|
*/ |
27
|
|
|
private $decoratedSuiteLoader; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param SuiteLoaderInterface $decoratedSuiteLoader |
31
|
|
|
*/ |
32
|
|
|
public function __construct(SuiteLoaderInterface $decoratedSuiteLoader) |
33
|
|
|
{ |
34
|
|
|
$this->decoratedSuiteLoader = $decoratedSuiteLoader; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function load(SuiteInterface $suite) |
41
|
|
|
{ |
42
|
|
|
$suiteEvent = new SuiteEvent($suite); |
43
|
|
|
|
44
|
|
|
$this->executeBeforeSuiteListeners($suite, $suiteEvent); |
45
|
|
|
|
46
|
|
|
$this->decoratedSuiteLoader->load($suite); |
47
|
|
|
|
48
|
|
|
$this->executeAfterSuiteListeners($suite, $suiteEvent); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param SuiteInterface $suite |
53
|
|
|
* @param SuiteEvent $suiteEvent |
54
|
|
|
*/ |
55
|
|
|
private function executeBeforeSuiteListeners(SuiteInterface $suite, SuiteEvent $suiteEvent) |
56
|
|
|
{ |
57
|
|
|
foreach ($suite->getListeners() as $listener => $listenerOptions) { |
58
|
|
|
if (!$listener instanceof BeforeSuiteListenerInterface) { |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$listener->beforeSuite($suiteEvent, $listenerOptions); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param SuiteInterface $suite |
68
|
|
|
* @param SuiteEvent $suiteEvent |
69
|
|
|
*/ |
70
|
|
|
private function executeAfterSuiteListeners(SuiteInterface $suite, SuiteEvent $suiteEvent) |
71
|
|
|
{ |
72
|
|
|
foreach ($suite->getListeners() as $listener => $listenerOptions) { |
73
|
|
|
if (!$listener instanceof AfterSuiteListenerInterface) { |
74
|
|
|
continue; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$listener->afterSuite($suiteEvent, $listenerOptions); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|