eZ\Publish\Core\SignalSlot\SignalDispatcher\DefaultSignalDispatcher::emit PHP Method

emit() public method

All assigned slots will eventually receive the $signal
public emit ( eZ\Publish\Core\SignalSlot\Signal $signal )
$signal eZ\Publish\Core\SignalSlot\Signal
    public function emit(Signal $signal)
    {
        $signalName = get_class($signal);
        if (!isset($this->signalSlotMap[$signalName])) {
            $this->signalSlotMap[$signalName] = array();
        }
        foreach (array_merge($this->signalSlotMap['*'], $this->signalSlotMap[$signalName]) as $slot) {
            /* @var \eZ\Publish\Core\SignalSlot\Slot $slot */
            $slot->receive($signal);
        }
    }

Usage Example

 public function testEmitSignalMultipleSlots()
 {
     $signal = $this->getMock('\\eZ\\Publish\\Core\\SignalSlot\\Signal');
     $slot = $this->getMock('\\eZ\\Publish\\Core\\SignalSlot\\Slot');
     $slot->expects($this->once())->method('receive')->with($signal);
     $slot2 = $this->getMock('\\eZ\\Publish\\Core\\SignalSlot\\Slot');
     $slot2->expects($this->once())->method('receive')->with($signal);
     $slot3 = $this->getMock('\\eZ\\Publish\\Core\\SignalSlot\\Slot');
     $slot3->expects($this->once())->method('receive')->with($signal);
     $dispatcher = new SignalSlot\SignalDispatcher\DefaultSignalDispatcher();
     $dispatcher->attach('\\' . get_class($signal), $slot);
     $dispatcher->attach('\\' . get_class($signal), $slot2);
     // Registering a wildcard slot. It is supposed to receive all the signals, whatever they are.
     $dispatcher->attach('*', $slot3);
     $dispatcher->emit($signal);
 }
DefaultSignalDispatcher