コード例 #1
0
 /**
  * Provides add-ons with the ability to modify the TubePress IOC container
  * before it is put into production.
  *
  * @param tubepress_api_ioc_ContainerInterface $container The core IOC container.
  *
  * @throws InvalidArgumentException If a service tag doesn't include the event attribute.
  *
  * @api
  * @since 3.1.0
  */
 public function process(tubepress_api_ioc_ContainerInterface $container)
 {
     if (!$container->hasDefinition(tubepress_api_event_EventDispatcherInterface::_)) {
         return;
     }
     $eventDispatcherDefinition = $container->getDefinition(tubepress_api_event_EventDispatcherInterface::_);
     $listenerServiceIds = $container->findTaggedServiceIds(tubepress_api_ioc_ContainerExtensionInterface::TAG_EVENT_LISTENER);
     foreach ($listenerServiceIds as $serviceId => $events) {
         foreach ($events as $event) {
             $priority = isset($event['priority']) ? $event['priority'] : 0;
             if (!isset($event['event'])) {
                 throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $serviceId, tubepress_api_ioc_ContainerExtensionInterface::TAG_EVENT_LISTENER));
             }
             if (!isset($event['method'])) {
                 $onSuffix = preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), array($this, '_callbackStrToUpper'), $event['event']);
                 $event['method'] = 'on' . $onSuffix;
                 $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
             }
             $eventDispatcherDefinition->addMethodCall('addListenerService', array($event['event'], array($serviceId, $event['method']), $priority));
         }
     }
 }
 /**
  * Provides add-ons with the ability to modify the TubePress IOC container
  * before it is put into production.
  *
  * @param tubepress_api_ioc_ContainerInterface $container The core IOC container.
  *
  * @throws InvalidArgumentException If a service tag doesn't include the event attribute.
  *
  * @api
  * @since 3.1.0
  */
 public function process(tubepress_api_ioc_ContainerInterface $container)
 {
     $consumerIds = $container->findTaggedServiceIds(tubepress_api_ioc_ContainerExtensionInterface::TAG_TAGGED_SERVICES_CONSUMER);
     foreach ($consumerIds as $consumerId => $tags) {
         $consumerDefinition = $container->getDefinition($consumerId);
         foreach ($tags as $tagData) {
             if (!isset($tagData['tag'])) {
                 throw new InvalidArgumentException('Tagged set consumers must specify which tagged services they would like to consume');
             }
             $matchingServiceIds = $container->findTaggedServiceIds($tagData['tag']);
             if (empty($matchingServiceIds)) {
                 continue;
             }
             if (!isset($tagData['method'])) {
                 throw new InvalidArgumentException('Tagged set consumers must specify which method to run for each tagged service ID');
             }
             $references = array();
             foreach ($matchingServiceIds as $id => $attributes) {
                 $references[] = new tubepress_impl_ioc_Reference($id);
             }
             $consumerDefinition->addMethodCall($tagData['method'], array($references));
         }
     }
 }