Merge pull request #4094 from Nicofuma/ticket/14377

[ticket/14377] Allow extensions to register compiler pass
This commit is contained in:
Marc Alexander 2015-12-23 19:27:19 +01:00
commit b1e4a3e1b7
2 changed files with 41 additions and 0 deletions

View file

@ -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)));

View file

@ -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());
}
}
}
}