diff options
author | David King <imkingdavid@gmail.com> | 2012-10-19 19:53:29 -0400 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-11-10 11:40:09 +0100 |
commit | f48709f5bb8fb1b916d308e3b4bb06bc96d08611 (patch) | |
tree | dc662d3c6f42e2fe1cba86fce7608a84521c0143 /phpBB/includes/event/kernel_compiler_pass.php | |
parent | 957508c8b1a71c603c31728dfab79640554c541e (diff) | |
download | forums-f48709f5bb8fb1b916d308e3b4bb06bc96d08611.tar forums-f48709f5bb8fb1b916d308e3b4bb06bc96d08611.tar.gz forums-f48709f5bb8fb1b916d308e3b4bb06bc96d08611.tar.bz2 forums-f48709f5bb8fb1b916d308e3b4bb06bc96d08611.tar.xz forums-f48709f5bb8fb1b916d308e3b4bb06bc96d08611.zip |
[feature/compiled-dic] Compile the DI Container into a cached class
PHPBB3-11152
Diffstat (limited to 'phpBB/includes/event/kernel_compiler_pass.php')
-rw-r--r-- | phpBB/includes/event/kernel_compiler_pass.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/phpBB/includes/event/kernel_compiler_pass.php b/phpBB/includes/event/kernel_compiler_pass.php new file mode 100644 index 0000000000..18b6661cd4 --- /dev/null +++ b/phpBB/includes/event/kernel_compiler_pass.php @@ -0,0 +1,72 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + +class phpbb_event_kernel_compiler_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) + { + $definition = $container->getDefinition('dispatcher'); + $user = $container->get('user'); + + 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($user->lang('NO_EVENT_ATTRIBUTE', $id)); + } + + if (!isset($event['method'])) + { + $event['method'] = 'on'.preg_replace(array( + '/(?<=\b)[a-z]/ie', + '/[^a-z0-9]/i' + ), array('strtoupper("\\0")', ''), $event['event']); + } + + $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($user->lang('SUBSCRIBER_WRONG_TYPE', $id, $interface)); + } + + $definition->addMethodCall('addSubscriberService', array($id, $class)); + } + } +} |