Tentative de régler le bordel

This commit is contained in:
Gauvain Boiché
2020-03-31 15:58:31 +02:00
parent a1864c0414
commit 459b46df7b
345 changed files with 10758 additions and 4066 deletions

View File

@@ -158,13 +158,18 @@ class container_builder
}
else
{
$this->container_extensions = array(new extension\core($this->get_config_path()));
$this->container_extensions = [
new extension\core($this->get_config_path()),
];
if ($this->use_extensions)
{
$this->load_extensions();
}
// Add tables extension after all extensions
$this->container_extensions[] = new extension\tables();
// Inject the config
if ($this->config_php_file)
{
@@ -481,7 +486,7 @@ class container_builder
$cached_container_dump = $dumper->dump(array(
'class' => 'phpbb_cache_container',
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
'base_class' => 'Symfony\\Component\\DependencyInjection\\Container',
));
$cache->write($cached_container_dump, $this->container->getResources());

View File

@@ -31,10 +31,15 @@ class container_configuration implements ConfigurationInterface
$rootNode
->children()
->booleanNode('require_dev_dependencies')->defaultValue(false)->end()
->booleanNode('allow_install_dir')->defaultValue(false)->end()
->arrayNode('debug')
->addDefaultsIfNotSet()
->children()
->booleanNode('exceptions')->defaultValue(false)->end()
->booleanNode('load_time')->defaultValue(false)->end()
->booleanNode('sql_explain')->defaultValue(false)->end()
->booleanNode('memory')->defaultValue(false)->end()
->booleanNode('show_errors')->defaultValue(false)->end()
->end()
->end()
->arrayNode('twig')
@@ -45,6 +50,12 @@ class container_configuration implements ConfigurationInterface
->booleanNode('enable_debug_extension')->defaultValue(false)->end()
->end()
->end()
->arrayNode('session')
->addDefaultsIfNotSet()
->children()
->booleanNode('log_errors')->defaultValue(false)->end()
->end()
->end()
->end()
;
return $treeBuilder;

View File

@@ -71,6 +71,8 @@ class core extends Extension
}
}
$container->setParameter('allow_install_dir', $config['allow_install_dir']);
// Set the Twig options if defined in the environment
$definition = $container->getDefinition('template.twig.environment');
$twig_environment_options = $definition->getArgument(static::TWIG_OPTIONS_POSITION);
@@ -97,6 +99,12 @@ class core extends Extension
{
$container->setParameter('debug.' . $name, $value);
}
// Set the log options
foreach ($config['session'] as $name => $value)
{
$container->setParameter('session.' . $name, $value);
}
}
/**

View File

@@ -0,0 +1,59 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\di\extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* Container tables extension
*/
class tables extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
// Tables is a reserved parameter and will be overwritten at all times
$tables = [];
// Add access via 'tables' parameter to acquire array with all tables
$parameterBag = $container->getParameterBag();
$parameters = $parameterBag->all();
foreach ($parameters as $parameter_name => $parameter_value)
{
if (!preg_match('/tables\.(.+)/', $parameter_name, $matches))
{
continue;
}
$tables[$matches[1]] = $parameter_value;
}
$container->setParameter('tables', $tables);
}
/**
* Returns the recommended alias to use in XML.
*
* This alias is also the mandatory prefix to use when using YAML.
*
* @return string The alias
*/
public function getAlias()
{
return 'tables';
}
}

View File

@@ -49,21 +49,6 @@ class service_collection extends \ArrayObject
return new service_collection_iterator($this);
}
// Because of a PHP issue we have to redefine offsetExists
// (even with a call to the parent):
// https://bugs.php.net/bug.php?id=66834
// https://bugs.php.net/bug.php?id=67067
// But it triggers a sniffer issue that we have to skip
// @codingStandardsIgnoreStart
/**
* {@inheritdoc}
*/
public function offsetExists($index)
{
return parent::offsetExists($index);
}
// @codingStandardsIgnoreEnd
/**
* {@inheritdoc}
*/
@@ -76,11 +61,11 @@ class service_collection extends \ArrayObject
* Add a service to the collection
*
* @param string $name The service name
* @return null
* @return void
*/
public function add($name)
{
$this->offsetSet($name, null);
$this->offsetSet($name, false);
}
/**
@@ -103,4 +88,35 @@ class service_collection extends \ArrayObject
{
return $this->service_classes;
}
/**
* Returns the service associated to a class
*
* @return mixed
* @throw \RuntimeException if the
*/
public function get_by_class($class)
{
$service_id = null;
foreach ($this->service_classes as $id => $service_class)
{
if ($service_class === $class)
{
if ($service_id !== null)
{
throw new \RuntimeException('More than one service definitions found for class "'.$class.'" in collection.');
}
$service_id = $id;
}
}
if ($service_id === null)
{
throw new \RuntimeException('No service found for class "'.$class.'" in collection.');
}
return $this->offsetGet($service_id);
}
}