Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
71.79% |
28 / 39 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| core | |
71.79% |
28 / 39 |
|
75.00% |
3 / 4 |
18.40 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| load | |
67.65% |
23 / 34 |
|
0.00% |
0 / 1 |
15.10 | |||
| getConfiguration | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getAlias | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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\Config\FileLocator; |
| 17 | use Symfony\Component\Config\Resource\FileResource; |
| 18 | use Symfony\Component\Console\Output\OutputInterface; |
| 19 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 20 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
| 21 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
| 22 | use phpbb\filesystem\helper as filesystem_helper; |
| 23 | |
| 24 | /** |
| 25 | * Container core extension |
| 26 | */ |
| 27 | class core extends Extension |
| 28 | { |
| 29 | /** |
| 30 | * Index of array in service template.twig.environment inside services_twig.yml |
| 31 | * @var int |
| 32 | */ |
| 33 | const TWIG_OPTIONS_POSITION = 8; |
| 34 | |
| 35 | /** |
| 36 | * Config path |
| 37 | * @var string |
| 38 | */ |
| 39 | protected $config_path; |
| 40 | |
| 41 | /** |
| 42 | * Constructor |
| 43 | * |
| 44 | * @param string $config_path Config path |
| 45 | */ |
| 46 | public function __construct($config_path) |
| 47 | { |
| 48 | $this->config_path = $config_path; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Loads a specific configuration. |
| 53 | * |
| 54 | * @param array $configs An array of configuration values |
| 55 | * @param ContainerBuilder $container A ContainerBuilder instance |
| 56 | * |
| 57 | * @throws \InvalidArgumentException When provided tag is not defined in this extension |
| 58 | */ |
| 59 | public function load(array $configs, ContainerBuilder $container) |
| 60 | { |
| 61 | $loader = new YamlFileLoader($container, new FileLocator(filesystem_helper::realpath($this->config_path))); |
| 62 | $loader->load($container->getParameter('core.environment') . '/container/environment.yml'); |
| 63 | |
| 64 | $config = $this->getConfiguration($configs, $container); |
| 65 | $config = $this->processConfiguration($config, $configs); |
| 66 | |
| 67 | if ($config['require_dev_dependencies']) |
| 68 | { |
| 69 | if (!class_exists('Symfony\Component\BrowserKit\HttpBrowser')) |
| 70 | { |
| 71 | trigger_error( |
| 72 | 'Composer development dependencies have not been set up for the ' . $container->getParameter('core.environment') . ' environment yet, run ' . |
| 73 | "'php ../composer.phar install --dev' from the phpBB directory to do so.", |
| 74 | E_USER_ERROR |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | $container->setParameter('allow_install_dir', $config['allow_install_dir']); |
| 80 | |
| 81 | // Set the Twig options if defined in the environment |
| 82 | $definition = $container->getDefinition('template.twig.environment'); |
| 83 | $twig_environment_options = $definition->getArgument(static::TWIG_OPTIONS_POSITION); |
| 84 | if ($config['twig']['debug']) |
| 85 | { |
| 86 | $twig_environment_options['debug'] = true; |
| 87 | } |
| 88 | if ($config['twig']['auto_reload']) |
| 89 | { |
| 90 | $twig_environment_options['auto_reload'] = true; |
| 91 | } |
| 92 | |
| 93 | // Replace the 8th argument, the options passed to the environment |
| 94 | $definition->replaceArgument(static::TWIG_OPTIONS_POSITION, $twig_environment_options); |
| 95 | |
| 96 | if ($config['twig']['enable_debug_extension']) |
| 97 | { |
| 98 | $definition = $container->getDefinition('template.twig.extensions.debug'); |
| 99 | $definition->addTag('twig.extension'); |
| 100 | } |
| 101 | |
| 102 | $composer_output = OutputInterface::VERBOSITY_NORMAL; |
| 103 | if ($config['extensions']['composer_verbose']) |
| 104 | { |
| 105 | $composer_output = OutputInterface::VERBOSITY_VERBOSE; |
| 106 | } |
| 107 | if ($config['extensions']['composer_debug']) |
| 108 | { |
| 109 | $composer_output = OutputInterface::VERBOSITY_DEBUG; |
| 110 | } |
| 111 | |
| 112 | $container->setParameter('extensions.composer.output', $composer_output); |
| 113 | |
| 114 | // Set the debug options |
| 115 | foreach ($config['debug'] as $name => $value) |
| 116 | { |
| 117 | $container->setParameter('debug.' . $name, $value); |
| 118 | } |
| 119 | |
| 120 | // Set the log options |
| 121 | foreach ($config['session'] as $name => $value) |
| 122 | { |
| 123 | $container->setParameter('session.' . $name, $value); |
| 124 | } |
| 125 | |
| 126 | // Set the finder options |
| 127 | foreach ($config['finder'] as $name => $value) |
| 128 | { |
| 129 | $container->setParameter('finder.' . $name, $value); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * {@inheritdoc} |
| 135 | */ |
| 136 | public function getConfiguration(array $config, ContainerBuilder $container) |
| 137 | { |
| 138 | $r = new \ReflectionClass('\phpbb\di\extension\container_configuration'); |
| 139 | $container->addResource(new FileResource($r->getFileName())); |
| 140 | |
| 141 | return new container_configuration(); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Returns the recommended alias to use in XML. |
| 146 | * |
| 147 | * This alias is also the mandatory prefix to use when using YAML. |
| 148 | * |
| 149 | * @return string The alias |
| 150 | */ |
| 151 | public function getAlias(): string |
| 152 | { |
| 153 | return 'core'; |
| 154 | } |
| 155 | } |