Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| config | |
92.86% |
13 / 14 |
|
75.00% |
3 / 4 |
8.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| load | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
| getAlias | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| convert_30_acm_type | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 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 | |
| 14 | namespace phpbb\di\extension; |
| 15 | |
| 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 17 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
| 18 | |
| 19 | /** |
| 20 | * Container config extension |
| 21 | */ |
| 22 | class config extends Extension |
| 23 | { |
| 24 | /** @var \phpbb\config_php_file */ |
| 25 | protected $config_php; |
| 26 | |
| 27 | public function __construct(\phpbb\config_php_file $config_php) |
| 28 | { |
| 29 | $this->config_php = $config_php; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Loads a specific configuration. |
| 34 | * |
| 35 | * @param array $configs An array of configuration values |
| 36 | * @param ContainerBuilder $container A ContainerBuilder instance |
| 37 | * |
| 38 | * @throws \InvalidArgumentException When provided tag is not defined in this extension |
| 39 | */ |
| 40 | public function load(array $configs, ContainerBuilder $container) |
| 41 | { |
| 42 | $parameters = array( |
| 43 | 'core.adm_relative_path' => $this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/', |
| 44 | 'core.table_prefix' => $this->config_php->get('table_prefix'), |
| 45 | 'cache.driver.class' => $this->convert_30_acm_type($this->config_php->get('acm_type')), |
| 46 | 'dbal.new_link' => defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK, |
| 47 | ); |
| 48 | $parameter_bag = $container->getParameterBag(); |
| 49 | |
| 50 | foreach ($parameters as $parameter => $value) |
| 51 | { |
| 52 | $container->setParameter($parameter, $parameter_bag->escapeValue($value)); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the recommended alias to use in XML. |
| 58 | * |
| 59 | * This alias is also the mandatory prefix to use when using YAML. |
| 60 | * |
| 61 | * @return string The alias |
| 62 | */ |
| 63 | public function getAlias(): string |
| 64 | { |
| 65 | return 'config'; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Convert 3.0 ACM type to 3.1 cache driver class name |
| 70 | * |
| 71 | * @param string $acm_type ACM type |
| 72 | * @return string cache driver class |
| 73 | */ |
| 74 | protected function convert_30_acm_type($acm_type) |
| 75 | { |
| 76 | if (preg_match('#^[a-z]+$#', $acm_type ?? '')) |
| 77 | { |
| 78 | return 'phpbb\\cache\\driver\\' . $acm_type; |
| 79 | } |
| 80 | |
| 81 | return $acm_type; |
| 82 | } |
| 83 | } |