1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Jean-François Lépine <https://twitter.com/Halleck45> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Hal\Application\Config; |
11
|
|
|
use Hal\Component\Config\Hydrator; |
12
|
|
|
use Hal\Component\Config\Loader; |
13
|
|
|
use Hal\Component\Config\Validator; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Config factory |
18
|
|
|
* |
19
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
20
|
|
|
*/ |
21
|
|
|
class ConfigFactory |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Factory config according Input |
25
|
|
|
* |
26
|
|
|
* @param InputInterface $input |
27
|
|
|
* @return Configuration |
28
|
|
|
*/ |
29
|
|
|
public function factory(InputInterface $input) { |
30
|
|
|
|
31
|
|
|
$config = new Configuration(); |
32
|
|
|
|
33
|
|
|
$treeBuilder = new TreeBuilder(); |
34
|
|
|
$hydrator = new Hydrator(new Validator($treeBuilder->getTree())); |
35
|
|
|
|
36
|
|
|
// first, load config file |
37
|
|
|
$locator = new ConfigLocator(); |
38
|
|
|
$filename = $locator->locate($input->getOption('config')); |
39
|
|
|
|
40
|
|
|
if(null !== $filename) { |
41
|
|
|
$loader = new Loader($hydrator); |
42
|
|
|
$config = $loader->load($filename); |
43
|
|
|
} else { |
44
|
|
|
$config = $hydrator->hydrates($config, array()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
// then, overwrite configuration by arguments provided in run |
49
|
|
|
strlen($input->getArgument('path')) > 0 && $config->getPath()->setBasePath($input->getArgument('path')); |
50
|
|
|
strlen($input->getOption('extensions')) > 0 && $config->getPath()->setExtensions($input->getOption('extensions')); |
51
|
|
|
strlen($input->getOption('excluded-dirs')) > 0 && $config->getPath()->setExcludedDirs($input->getOption('excluded-dirs')); |
52
|
|
|
strlen($input->getOption('symlinks')) > 0 && $config->getPath()->setFollowSymlinks(true); |
53
|
|
|
strlen($input->getOption('report-xml')) > 0 && $config->getLogging()->setReport('xml', $input->getOption('report-xml')); |
54
|
|
|
strlen($input->getOption('report-cli')) > 0 && $config->getLogging()->setReport('cli', $input->getOption('report-cli')); |
55
|
|
|
strlen($input->getOption('report-json')) > 0 && $config->getLogging()->setReport('json', $input->getOption('report-json')); |
56
|
|
|
strlen($input->getOption('report-html')) > 0 && $config->getLogging()->setReport('html', $input->getOption('report-html')); |
57
|
|
|
strlen($input->getOption('report-csv')) > 0 && $config->getLogging()->setReport('csv', $input->getOption('report-csv')); |
58
|
|
|
strlen($input->getOption('violations-xml')) > 0 && $config->getLogging()->setViolation('xml', $input->getOption('violations-xml')); |
59
|
|
|
strlen($input->getOption('chart-bubbles')) > 0 && $config->getLogging()->setChart('bubbles', $input->getOption('chart-bubbles')); |
60
|
|
|
strlen($input->getOption('failure-condition')) > 0 && $config->setFailureCondition($input->getOption('failure-condition')); |
61
|
|
|
strlen($input->getOption('template-title')) > 0 && $config->getTemplate()->setTitle($input->getOption('template-title')); |
62
|
|
|
strlen($input->getOption('ignore-errors')) > 0 && $config->setIgnoreErrors(true); |
63
|
|
|
|
64
|
|
|
return $config; |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |