Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • AbstractCommandEvent
  • AbstractContainerAwareEvent
  • AbstractEnvironmentAwareEvent
  • AbstractModelAwareEvent
  • AbstractModelCommandEvent
  • AbstractViewAwareEvent
  • EventPropagator
  • PostCreateModelEvent
  • PostDeleteModelEvent
  • PostDuplicateModelEvent
  • PostPasteModelEvent
  • PostPersistModelEvent
  • PreCreateModelEvent
  • PreDeleteModelEvent
  • PreDuplicateModelEvent
  • PrePasteModelEvent
  • PrePersistModelEvent

Interfaces

  • CommandEventInterface
  • EventPropagatorInterface
  • ModelCommandEventInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\Event;
 14: 
 15: /**
 16:  * The generic event propagator implementation.
 17:  *
 18:  * @package DcGeneral\Event
 19:  */
 20: class EventPropagator implements EventPropagatorInterface
 21: {
 22:     /**
 23:      * The attached event dispatcher.
 24:      *
 25:      * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
 26:      */
 27:     protected $dispatcher;
 28: 
 29:     /**
 30:      * Create a new instance.
 31:      *
 32:      * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher The event dispatcher to attach.
 33:      */
 34:     public function __construct($dispatcher)
 35:     {
 36:         $this->dispatcher = $dispatcher;
 37:     }
 38: 
 39:     /**
 40:      * {@inheritDoc}
 41:      */
 42:     public function propagate($eventName, $event = null, $suffixes = array())
 43:     {
 44:         if (!is_array($suffixes))
 45:         {
 46:             $suffixes = func_get_args();
 47: 
 48:             // Skip $eventName.
 49:             array_shift($suffixes);
 50:             // Skip $event.
 51:             array_shift($suffixes);
 52:         }
 53: 
 54:         while ($suffixes)
 55:         {
 56:             // First, try to dispatch to all DCA registered subscribers.
 57:             $event = $this->propagateExact($eventName, $event, $suffixes);
 58:             array_pop($suffixes);
 59: 
 60:             if ($event->isPropagationStopped() === true)
 61:             {
 62:                 return $event;
 63:             }
 64:         }
 65: 
 66:         // Second, try to dispatch to all globally registered subscribers.
 67:         if ((!$event) || $event->isPropagationStopped() === false)
 68:         {
 69:             $event = $this->dispatcher->dispatch($eventName, $event);
 70:         }
 71: 
 72:         return $event;
 73:     }
 74: 
 75:     /**
 76:      * {@inheritDoc}
 77:      */
 78:     public function propagateExact($eventName, $event = null, $suffixes = array())
 79:     {
 80:         if (!is_array($suffixes))
 81:         {
 82:             $suffixes = func_get_args();
 83: 
 84:             // Skip $eventName.
 85:             array_shift($suffixes);
 86:             // Skip $event.
 87:             array_shift($suffixes);
 88:         }
 89: 
 90:         $event = $this->dispatcher->dispatch(
 91:             sprintf(
 92:                 '%s%s',
 93:                 $eventName,
 94:                 '[' . implode('][', $suffixes) . ']'
 95:             ),
 96:             $event
 97:         );
 98: 
 99:         return $event;
100:     }
101: }
102: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0