-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorageHandler.php
57 lines (48 loc) · 1.37 KB
/
StorageHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types = 1);
namespace LoversOfBehat\ScreenshotExtension;
use LoversOfBehat\ScreenshotExtension\Storage\StorageInterface;
/**
* Default implementation of the service that handles screenshot storage.
*/
class StorageHandler implements StorageHandlerInterface
{
/**
* @var iterable
*/
protected $plugins;
/**
* The configuration for the screenshot extension.
*
* @var array
*/
protected $config;
/**
* Constructs a StorageHandler service.
*
* @param iterable $plugins
* The storage plugins.
* @param array $config
* The configuration for the screenshot extension.
*/
public function __construct(iterable $plugins, array $config)
{
$this->plugins = $plugins;
$this->config = $config;
}
/**
* {@inheritdoc}
*/
public function store(ScreenshotInterface $screenshot): void
{
$iterator = $this->plugins->getIterator();
foreach ($iterator as $plugin) {
if (!$plugin instanceof StorageInterface) {
throw new \DomainException('All services tagged with "screenshot_extension.storage" should implement \LoversOfBehat\ScreenshotExtension\Storage\StorageInterface.');
}
if ($plugin->isEnabled()) {
$plugin->store($screenshot);
}
}
}
}