aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2015-12-23 19:27:19 +0100
committerMarc Alexander <admin@m-a-styles.de>2015-12-23 19:27:19 +0100
commitb1e4a3e1b7efb3d131dd02fca76009e971585dac (patch)
treec56894735743b3d43c751d59ab6b47e4d7ac211e
parent6a4e296c436aa52477e7ebacdebc152fc3bcb2b1 (diff)
parentd256d81a51b9d6153e7c2e6499a7b559c14997f0 (diff)
downloadforums-b1e4a3e1b7efb3d131dd02fca76009e971585dac.tar
forums-b1e4a3e1b7efb3d131dd02fca76009e971585dac.tar.gz
forums-b1e4a3e1b7efb3d131dd02fca76009e971585dac.tar.bz2
forums-b1e4a3e1b7efb3d131dd02fca76009e971585dac.tar.xz
forums-b1e4a3e1b7efb3d131dd02fca76009e971585dac.zip
Merge pull request #4094 from Nicofuma/ticket/14377
[ticket/14377] Allow extensions to register compiler pass
-rw-r--r--build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php5
-rw-r--r--phpBB/phpbb/di/container_builder.php36
2 files changed, 41 insertions, 0 deletions
diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
index 7ffd1aadd6..c04113b84e 100644
--- a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
+++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
@@ -87,6 +87,11 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
$old_simple_statement = $simple_statement;
$simple_class_name_start = $phpcsFile->findNext(array(T_NS_SEPARATOR, T_STRING), ($simple_statement + 1));
+
+ if ($simple_class_name_start === false) {
+ continue;
+ }
+
$simple_class_name_end = $phpcsFile->findNext($find, ($simple_statement + 1), null, true);
$simple_class_name = trim($phpcsFile->getTokensAsString($simple_class_name_start, ($simple_class_name_end - $simple_class_name_start)));
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());
+ }
+ }
+ }
}