Neos\Flow\SignalSlot\Dispatcher::dispatch PHP Метод

dispatch() публичный Метод

Dispatches a signal by calling the registered Slot methods
public dispatch ( string $signalClassName, string $signalName, array $signalArguments = [] ) : void
$signalClassName string Name of the class containing the signal
$signalName string Name of the signal
$signalArguments array arguments passed to the signal method
Результат void
    public function dispatch($signalClassName, $signalName, array $signalArguments = [])
    {
        if (!isset($this->slots[$signalClassName][$signalName])) {
            return;
        }
        foreach ($this->slots[$signalClassName][$signalName] as $slotInformation) {
            if (isset($slotInformation['object'])) {
                $object = $slotInformation['object'];
            } elseif (substr($slotInformation['method'], 0, 2) === '::') {
                if (!isset($this->objectManager)) {
                    if (is_callable($slotInformation['class'] . $slotInformation['method'])) {
                        $object = $slotInformation['class'];
                    } else {
                        throw new Exception\InvalidSlotException(sprintf('Cannot dispatch %s::%s to class %s. The object manager is not yet available in the Signal Slot Dispatcher and therefore it cannot dispatch classes.', $signalClassName, $signalName, $slotInformation['class']), 1298113624);
                    }
                } else {
                    $object = $this->objectManager->getClassNameByObjectName($slotInformation['class']);
                }
                $slotInformation['method'] = substr($slotInformation['method'], 2);
            } else {
                if (!isset($this->objectManager)) {
                    throw new Exception\InvalidSlotException(sprintf('Cannot dispatch %s::%s to class %s. The object manager is not yet available in the Signal Slot Dispatcher and therefore it cannot dispatch classes.', $signalClassName, $signalName, $slotInformation['class']), 1298113624);
                }
                if (!$this->objectManager->isRegistered($slotInformation['class'])) {
                    throw new Exception\InvalidSlotException('The given class "' . $slotInformation['class'] . '" is not a registered object.', 1245673367);
                }
                $object = $this->objectManager->get($slotInformation['class']);
            }
            if ($slotInformation['passSignalInformation'] === true) {
                $signalArguments[] = $signalClassName . '::' . $signalName;
            }
            if (!method_exists($object, $slotInformation['method'])) {
                throw new Exception\InvalidSlotException('The slot method ' . get_class($object) . '->' . $slotInformation['method'] . '() does not exist.', 1245673368);
            }
            call_user_func_array([$object, $slotInformation['method']], $signalArguments);
        }
    }

Usage Example

 /**
  * Emits a signal when an Advice is invoked
  *
  * The advice is not proxyable, so the signal is dispatched manually here.
  *
  * @param object $aspectObject
  * @param string $methodName
  * @param JoinPointInterface $joinPoint
  * @return void
  * @Flow\Signal
  */
 protected function emitAdviceInvoked($aspectObject, $methodName, $joinPoint)
 {
     if ($this->dispatcher === null) {
         $this->dispatcher = $this->objectManager->get(Dispatcher::class);
     }
     $this->dispatcher->dispatch(self::class, 'adviceInvoked', [$aspectObject, $methodName, $joinPoint]);
 }
All Usage Examples Of Neos\Flow\SignalSlot\Dispatcher::dispatch