1 | <?php |
||
14 | class ConfigurationReader |
||
15 | { |
||
16 | /** |
||
17 | * @var \Symfony\Component\Console\Input\InputInterface |
||
18 | */ |
||
19 | protected $input; |
||
20 | |||
21 | /** |
||
22 | * @param InputInterface $input |
||
23 | */ |
||
24 | public function __construct(InputInterface $input) |
||
25 | { |
||
26 | $this->input = $input; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Read configuration information from input |
||
31 | * |
||
32 | * @return Configuration |
||
33 | */ |
||
34 | public function read() |
||
35 | { |
||
36 | $configuration = new Configuration(); |
||
37 | $configuration->setPaths($this->readPaths()); |
||
38 | |||
39 | $options = [ |
||
40 | 'focus' => [$configuration, 'setFocusPattern'], |
||
41 | 'skip' => [$configuration, 'setSkipPattern'], |
||
42 | 'grep' => [$configuration, 'setGrep'], |
||
43 | 'no-colors' => [$configuration, 'disableColors'], |
||
44 | 'force-colors' => [$configuration, 'enableColorsExplicit'], |
||
45 | 'bail' => [$configuration, 'stopOnFailure'], |
||
46 | 'configuration' => [$configuration, 'setConfigurationFile'] |
||
47 | ]; |
||
48 | |||
49 | foreach ($options as $option => $callable) { |
||
50 | $this->callForOption($option, $callable); |
||
51 | } |
||
52 | |||
53 | return $configuration; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Static access to reader |
||
58 | * |
||
59 | * @param InputInterface $input |
||
60 | * @return Configuration |
||
61 | */ |
||
62 | public static function readInput(InputInterface $input) |
||
68 | |||
69 | /** |
||
70 | * Execute a callback if the input object has a value for the |
||
71 | * given option name. |
||
72 | * |
||
73 | * @param string $optionName |
||
74 | * @param callable $callable |
||
75 | */ |
||
76 | protected function callForOption($optionName, callable $callable) |
||
83 | |||
84 | private function readPaths() |
||
85 | { |
||
104 | } |
||
105 |