diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-12-22 18:48:12 +0100 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-12-22 18:48:49 +0100 |
commit | d44e34aa141361781eae67814278b390cebaf4e5 (patch) | |
tree | 80b241991786cc24764facc943a70d83faf01c34 /phpBB/phpbb/di/container_builder.php | |
parent | 332ca57942092a691463281c38b2285a45c95d16 (diff) | |
download | forums-d44e34aa141361781eae67814278b390cebaf4e5.tar forums-d44e34aa141361781eae67814278b390cebaf4e5.tar.gz forums-d44e34aa141361781eae67814278b390cebaf4e5.tar.bz2 forums-d44e34aa141361781eae67814278b390cebaf4e5.tar.xz forums-d44e34aa141361781eae67814278b390cebaf4e5.zip |
[ticket/14377] Allow extensions to register compiler pass
PHPBB3-14377
Diffstat (limited to 'phpBB/phpbb/di/container_builder.php')
-rw-r--r-- | phpBB/phpbb/di/container_builder.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 0a94aac98d..8f175c966c 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\Filesystem\Exception\IOException; +use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; class container_builder @@ -158,6 +159,11 @@ class container_builder // Event listeners "Symfony style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); + if ($this->use_extensions) + { + $this->register_ext_compiler_pass(); + } + $filesystem = new filesystem(); $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); $loader->load($this->container->getParameter('core.environment') . '/config.yml'); @@ -512,4 +518,34 @@ class container_builder { return $this->environment ?: PHPBB_ENVIRONMENT; } + + private function register_ext_compiler_pass() + { + $finder = new Finder(); + $finder + ->name('*_pass.php') + ->path('di/pass') + ->files() + ->ignoreDotFiles(true) + ->ignoreUnreadableDirs(true) + ->ignoreVCS(true) + ->followLinks() + ->in($this->phpbb_root_path . 'ext/') + ; + + /** @var \SplFileInfo $pass */ + foreach ($finder as $pass) + { + $filename = $pass->getPathname(); + $filename = substr($filename, 0, -strlen('.' . $pass->getExtension())); + $filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename); + $className = preg_replace('#^.*ext/#', '', $filename); + $className = '\\' . str_replace('/', '\\', $className); + + if (class_exists($className) && in_array('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface', class_implements($className), true)) + { + $this->container->addCompilerPass(new $className()); + } + } + } } |