Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RegisterListenersPass.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\EventDispatcher\DependencyInjection;
013
014 use Symfony\Component\DependencyInjection\ContainerBuilder;
015 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
016
017 /**
018 * Compiler pass to register tagged services for an event dispatcher.
019 */
020 class RegisterListenersPass implements CompilerPassInterface
021 {
022 /**
023 * @var string
024 */
025 protected $dispatcherService;
026
027 /**
028 * @var string
029 */
030 protected $listenerTag;
031
032 /**
033 * @var string
034 */
035 protected $subscriberTag;
036
037 /**
038 * Constructor.
039 *
040 * @param string $dispatcherService Service name of the event dispatcher in processed container
041 * @param string $listenerTag Tag name used for listener
042 * @param string $subscriberTag Tag name used for subscribers
043 */
044 public function __construct($dispatcherService = 'event_dispatcher', $listenerTag = 'kernel.event_listener', $subscriberTag = 'kernel.event_subscriber')
045 {
046 $this->dispatcherService = $dispatcherService;
047 $this->listenerTag = $listenerTag;
048 $this->subscriberTag = $subscriberTag;
049 }
050
051 public function process(ContainerBuilder $container)
052 {
053 if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
054 return;
055 }
056
057 $definition = $container->findDefinition($this->dispatcherService);
058
059 foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
060 $def = $container->getDefinition($id);
061 if (!$def->isPublic()) {
062 throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id));
063 }
064
065 if ($def->isAbstract()) {
066 throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
067 }
068
069 foreach ($events as $event) {
070 $priority = isset($event['priority']) ? $event['priority'] : 0;
071
072 if (!isset($event['event'])) {
073 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
074 }
075
076 if (!isset($event['method'])) {
077 $event['method'] = 'on'.preg_replace_callback(array(
078 '/(?<=\b)[a-z]/i',
079 '/[^a-z0-9]/i',
080 ), function ($matches) { return strtoupper($matches[0]); }, $event['event']);
081 $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
082 }
083
084 $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
085 }
086 }
087
088 foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) {
089 $def = $container->getDefinition($id);
090 if (!$def->isPublic()) {
091 throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id));
092 }
093
094 if ($def->isAbstract()) {
095 throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
096 }
097
098 // We must assume that the class value has been correctly filled, even if the service is created by a factory
099 $class = $container->getParameterBag()->resolveValue($def->getClass());
100 $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
101
102 if (!is_subclass_of($class, $interface)) {
103 if (!class_exists($class, false)) {
104 throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
105 }
106
107 throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
108 }
109
110 $definition->addMethodCall('addSubscriberService', array($id, $class));
111 }
112 }
113 }
114