This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContextCompiler.php
More file actions
63 lines (53 loc) · 1.42 KB
/
ContextCompiler.php
File metadata and controls
63 lines (53 loc) · 1.42 KB
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
58
59
60
61
62
63
<?php
namespace FDevs\Fixture;
use FDevs\Fixture\Command\ContextHandlerInterface;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
class ContextCompiler implements ContextHandlerInterface
{
/**
* @var iterable|ContextHandlerInterface[]
*/
private $handlers;
/**
* ContextCompiler constructor.
*
* @param iterable|ContextHandlerInterface[] $handlers
*/
public function __construct(iterable $handlers)
{
$this->handlers = $handlers;
}
/**
* @inheritDoc
*/
public function configureOptions(InputDefinition $def): ContextHandlerInterface
{
$this->proceedHandlers(function (ContextHandlerInterface $handler) use ($def) {
$handler->configureOptions($def);
});
return $this;
}
/**
* @inheritDoc
*/
public function buildContext(InputInterface $input, array $context = []): array
{
$this->proceedHandlers(function (ContextHandlerInterface $handler) use (&$context, $input) {
$context = $handler->buildContext($input, $context);
});
return $context;
}
/**
* @param callable $func
*
* @return ContextCompiler
*/
private function proceedHandlers(callable $func): self
{
foreach ($this->handlers as $handler) {
$func($handler);
}
return $this;
}
}