Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
show
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 configure
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\install\console\command\update\config;
15
16use phpbb\install\helper\iohandler\factory;
17use phpbb\install\updater_configuration;
18use phpbb\language\language;
19use Symfony\Component\Config\Definition\Exception\Exception;
20use Symfony\Component\Config\Definition\Processor;
21use Symfony\Component\Console\Command\Command;
22use Symfony\Component\Console\Input\InputArgument;
23use Symfony\Component\Console\Input\InputInterface;
24use Symfony\Component\Console\Output\OutputInterface;
25use Symfony\Component\Console\Style\SymfonyStyle;
26use Symfony\Component\Yaml\Exception\ParseException;
27use Symfony\Component\Yaml\Yaml;
28
29class show extends \phpbb\console\command\command
30{
31    /**
32     * @var factory
33     */
34    protected $iohandler_factory;
35
36    /**
37     * @var language
38     */
39    protected $language;
40
41    /**
42     * Constructor
43     *
44     * @param language $language
45     * @param factory $factory
46     */
47    public function __construct(language $language, factory $factory)
48    {
49        $this->iohandler_factory = $factory;
50        $this->language = $language;
51
52        parent::__construct(new \phpbb\user($language, 'datetime'));
53    }
54
55    /**
56     *
57     * {@inheritdoc}
58     */
59    protected function configure()
60    {
61        $this
62            ->setName('update:config:show')
63            ->addArgument(
64                'config-file',
65                InputArgument::REQUIRED,
66                $this->language->lang('CLI_CONFIG_FILE'))
67            ->setDescription($this->language->lang('CLI_INSTALL_SHOW_CONFIG'))
68        ;
69    }
70
71    /**
72     * Show the validated configuration
73     *
74     * @param InputInterface  $input  An InputInterface instance
75     * @param OutputInterface $output An OutputInterface instance
76     *
77     * @return int 0 if everything went fine, or a non-zero exit code
78     */
79    protected function execute(InputInterface $input, OutputInterface $output)
80    {
81        $this->iohandler_factory->set_environment('cli');
82
83        /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
84        $iohandler = $this->iohandler_factory->get();
85        $style = new SymfonyStyle($input, $output);
86        $iohandler->set_style($style, $output);
87
88        $config_file = $input->getArgument('config-file');
89
90        if (!is_file($config_file))
91        {
92            $iohandler->add_error_message(array('MISSING_FILE', $config_file));
93
94            return Command::FAILURE;
95        }
96
97        try
98        {
99            $config = Yaml::parse(file_get_contents($config_file), true);
100        }
101        catch (ParseException $e)
102        {
103            $iohandler->add_error_message('INVALID_YAML_FILE');
104
105            return Command::FAILURE;
106        }
107
108        $processor = new Processor();
109        $configuration = new updater_configuration();
110
111        try
112        {
113            $config = $processor->processConfiguration($configuration, $config);
114        }
115        catch (Exception $e)
116        {
117            $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
118
119            return Command::FAILURE;
120        }
121
122        $style->block(Yaml::dump(array('updater' => $config), 10, 4, true));
123
124        return Command::SUCCESS;
125    }
126}