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

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

One slot can be connected with multiple signals by calling this method multiple times.
public connect ( string $signalClassName, string $signalName, mixed $slotClassNameOrObject, string $slotMethodName = '', boolean $passSignalInformation = true ) : void
$signalClassName string Name of the class containing the signal
$signalName string Name of the signal
$slotClassNameOrObject mixed Name of the class containing the slot or the instantiated class or a Closure object
$slotMethodName string Name of the method to be used as a slot. If $slotClassNameOrObject is a Closure object, this parameter is ignored
$passSignalInformation boolean If set to TRUE, the last argument passed to the slot will be information about the signal (EmitterClassName::signalName)
Результат void
    public function connect($signalClassName, $signalName, $slotClassNameOrObject, $slotMethodName = '', $passSignalInformation = true)
    {
        $class = null;
        $object = null;
        if (strpos($signalName, 'emit') === 0) {
            $possibleSignalName = lcfirst(substr($signalName, strlen('emit')));
            throw new \InvalidArgumentException('The signal should not be connected with the method name ("' . $signalName . '"). Try "' . $possibleSignalName . '" for the signal name.', 1314016630);
        }
        if (is_object($slotClassNameOrObject)) {
            $object = $slotClassNameOrObject;
            $method = $slotClassNameOrObject instanceof \Closure ? '__invoke' : $slotMethodName;
        } else {
            if ($slotMethodName === '') {
                throw new \InvalidArgumentException('The slot method name must not be empty (except for closures).', 1229531659);
            }
            $class = $slotClassNameOrObject;
            $method = $slotMethodName;
        }
        $this->slots[$signalClassName][$signalName][] = ['class' => $class, 'method' => $method, 'object' => $object, 'passSignalInformation' => $passSignalInformation === true];
    }

Usage Example

 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function connectWithSignalNameStartingWithEmitShouldNotBeAllowed()
 {
     $mockSignal = $this->getMockBuilder('stdClass')->setMethods(['emitSomeSignal'])->getMock();
     $mockSlot = $this->getMockBuilder('stdClass')->setMethods(['someSlotMethod'])->getMock();
     $dispatcher = new Dispatcher();
     $dispatcher->connect(get_class($mockSignal), 'emitSomeSignal', get_class($mockSlot), 'someSlotMethod', false);
 }