diff options
Diffstat (limited to 'phpBB/phpbb/di')
| -rw-r--r-- | phpBB/phpbb/di/extension/config.php | 80 | ||||
| -rw-r--r-- | phpBB/phpbb/di/extension/core.php | 67 | ||||
| -rw-r--r-- | phpBB/phpbb/di/extension/ext.php | 67 | ||||
| -rw-r--r-- | phpBB/phpbb/di/pass/collection_pass.php | 44 | ||||
| -rw-r--r-- | phpBB/phpbb/di/pass/kernel_pass.php | 67 | ||||
| -rw-r--r-- | phpBB/phpbb/di/service_collection.php | 79 | ||||
| -rw-r--r-- | phpBB/phpbb/di/service_collection_iterator.php | 46 | 
7 files changed, 450 insertions, 0 deletions
diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php new file mode 100644 index 0000000000..a7d7284f85 --- /dev/null +++ b/phpBB/phpbb/di/extension/config.php @@ -0,0 +1,80 @@ +<?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 config extension +*/ +class config extends Extension +{ +	public function __construct($config_file) +	{ +		$this->config_file = $config_file; +	} + +	/** +	* Loads a specific configuration. +	* +	* @param array            $config    An array of configuration values +	* @param ContainerBuilder $container A ContainerBuilder instance +	* +	* @throws \InvalidArgumentException When provided tag is not defined in this extension +	*/ +	public function load(array $config, ContainerBuilder $container) +	{ +		require($this->config_file); + +		$container->setParameter('core.adm_relative_path', (isset($phpbb_adm_relative_path) ? $phpbb_adm_relative_path : 'adm/')); +		$container->setParameter('core.table_prefix', $table_prefix); +		$container->setParameter('cache.driver.class', $this->convert_30_acm_type($acm_type)); +		$container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($dbms)); +		$container->setParameter('dbal.dbhost', $dbhost); +		$container->setParameter('dbal.dbuser', $dbuser); +		$container->setParameter('dbal.dbpasswd', $dbpasswd); +		$container->setParameter('dbal.dbname', $dbname); +		$container->setParameter('dbal.dbport', $dbport); +		$container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); +	} + +	/** +	* 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 'config'; +	} + +	/** +	* Convert 3.0 ACM type to 3.1 cache driver class name +	* +	* @param string $acm_type ACM type +	* @return string cache driver class +	*/ +	protected function convert_30_acm_type($acm_type) +	{ +		if (preg_match('#^[a-z]+$#', $acm_type)) +		{ +			return 'phpbb\\cache\\driver\\' . $acm_type; +		} + +		return $acm_type; +	} +} diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php new file mode 100644 index 0000000000..ca4fa5c082 --- /dev/null +++ b/phpBB/phpbb/di/extension/core.php @@ -0,0 +1,67 @@ +<?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; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\Config\FileLocator; + +/** +* Container core extension +*/ +class core extends Extension +{ +	/** +	* Config path +	* @var string +	*/ +	protected $config_path; + +	/** +	* Constructor +	* +	* @param string $config_path Config path +	*/ +	public function __construct($config_path) +	{ +		$this->config_path = $config_path; +	} + +	/** +	* Loads a specific configuration. +	* +	* @param array            $config    An array of configuration values +	* @param ContainerBuilder $container A ContainerBuilder instance +	* +	* @throws \InvalidArgumentException When provided tag is not defined in this extension +	*/ +	public function load(array $config, ContainerBuilder $container) +	{ +		$loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($this->config_path))); +		$loader->load('services.yml'); +	} + +	/** +	* 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 'core'; +	} +} diff --git a/phpBB/phpbb/di/extension/ext.php b/phpBB/phpbb/di/extension/ext.php new file mode 100644 index 0000000000..718c992d2e --- /dev/null +++ b/phpBB/phpbb/di/extension/ext.php @@ -0,0 +1,67 @@ +<?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; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\Config\FileLocator; + +/** +* Container ext extension +*/ +class ext extends Extension +{ +	protected $paths = array(); + +	public function __construct($enabled_extensions) +	{ +		foreach ($enabled_extensions as $ext => $path) +		{ +			$this->paths[] = $path; +		} +	} + +	/** +	* Loads a specific configuration. +	* +	* @param array            $config    An array of configuration values +	* @param ContainerBuilder $container A ContainerBuilder instance +	* +	* @throws \InvalidArgumentException When provided tag is not defined in this extension +	*/ +	public function load(array $config, ContainerBuilder $container) +	{ +		foreach ($this->paths as $path) +		{ +			if (file_exists($path . '/config/services.yml')) +			{ +				$loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($path . '/config'))); +				$loader->load('services.yml'); +			} +		} +	} + +	/** +	* 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 'ext'; +	} +} diff --git a/phpBB/phpbb/di/pass/collection_pass.php b/phpBB/phpbb/di/pass/collection_pass.php new file mode 100644 index 0000000000..a5c054674e --- /dev/null +++ b/phpBB/phpbb/di/pass/collection_pass.php @@ -0,0 +1,44 @@ +<?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\pass; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + +/** +* Appends an add method call to the definition of each collection service for +* the services tagged with the appropriate name defined in the collection's +* service_collection tag. +*/ +class collection_pass implements CompilerPassInterface +{ +	/** +	* Modify the container before it is passed to the rest of the code +	* +	* @param ContainerBuilder $container ContainerBuilder object +	* @return null +	*/ +	public function process(ContainerBuilder $container) +	{ +		foreach ($container->findTaggedServiceIds('service_collection') as $id => $data) +		{ +			$definition = $container->getDefinition($id); + +			foreach ($container->findTaggedServiceIds($data[0]['tag']) as $service_id => $service_data) +			{ +				$definition->addMethodCall('add', array($service_id)); +			} +		} +	} +} diff --git a/phpBB/phpbb/di/pass/kernel_pass.php b/phpBB/phpbb/di/pass/kernel_pass.php new file mode 100644 index 0000000000..c154c7532d --- /dev/null +++ b/phpBB/phpbb/di/pass/kernel_pass.php @@ -0,0 +1,67 @@ +<?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\pass; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + +class kernel_pass implements CompilerPassInterface +{ +	/** +	* Modify the container before it is passed to the rest of the code +	* +	* @param ContainerBuilder $container ContainerBuilder object +	* @return null +	* @throws \InvalidArgumentException +	*/ +	public function process(ContainerBuilder $container) +	{ +		$definition = $container->getDefinition('dispatcher'); + +		foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) +		{ +			foreach ($events as $event) +			{ +				$priority = isset($event['priority']) ? $event['priority'] : 0; + +				if (!isset($event['event'])) +				{ +					throw new \InvalidArgumentException(sprintf('Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); +				} + +				if (!isset($event['method'])) +				{ +					throw new \InvalidArgumentException(sprintf('Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', $id)); +				} + +				$definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); +			} +		} + +		foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) +		{ +			// We must assume that the class value has been correctly filled, even if the service is created by a factory +			$class = $container->getDefinition($id)->getClass(); + +			$refClass = new \ReflectionClass($class); +			$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; +			if (!$refClass->implementsInterface($interface)) +			{ +				throw new \InvalidArgumentException(sprintf('Service "%1$s" must implement interface "%2$s".', $id, $interface)); +			} + +			$definition->addMethodCall('addSubscriberService', array($id, $class)); +		} +	} +} diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php new file mode 100644 index 0000000000..82ca9bf679 --- /dev/null +++ b/phpBB/phpbb/di/service_collection.php @@ -0,0 +1,79 @@ +<?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; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** +* Collection of services to be configured at container compile time. +*/ +class service_collection extends \ArrayObject +{ +	/** +	* @var \Symfony\Component\DependencyInjection\ContainerInterface +	*/ +	protected $container; + +	/** +	* Constructor +	* +	* @param ContainerInterface $container Container object +	*/ +	public function __construct(ContainerInterface $container) +	{ +		$this->container = $container; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function getIterator() +	{ +		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} +	*/ +	public function offsetGet($index) +	{ +		return $this->container->get($index); +	} + +	/** +	* Add a service to the collection +	* +	* @param string $name The service name +	* @return null +	*/ +	public function add($name) +	{ +		$this->offsetSet($name, null); +	} +} diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php new file mode 100644 index 0000000000..0d031ab52d --- /dev/null +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -0,0 +1,46 @@ +<?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; + +/** +* Iterator which loads the services when they are requested +*/ +class service_collection_iterator extends \ArrayIterator +{ +	/** +	* @var \phpbb\di\service_collection +	*/ +	protected $collection; + +	/** +	* Construct an ArrayIterator for service_collection +	* +	* @param \phpbb\di\service_collection $collection The collection to iterate over +	* @param int $flags Flags to control the behaviour of the ArrayObject object. +	* @see ArrayObject::setFlags() +	*/ +	public function __construct(service_collection $collection, $flags = 0) +	{ +		parent::__construct($collection, $flags); +		$this->collection = $collection; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function current() +	{ +		return $this->collection->offsetGet($this->key()); +	} +}  | 
