Пример #1
0
 public function addConverter(ConverterInterface $converter)
 {
     foreach ($converter->getSubscribedEvents() as $tag => $event) {
         $eventName = stripos($tag, 'convert.') === 0 ? $tag : "convert.{$tag}";
         if (is_string($event)) {
             $event = [$event];
         }
         $event = array_values($event);
         list($callbackName, $priority) = count($event) > 1 ? [$event[0], $event[1]] : [$event[0], EmitterInterface::P_NORMAL];
         $this->eventEmitter->addListener($eventName, [$converter, $callbackName], $priority);
     }
     return $this;
 }
Пример #2
0
 public function it_can_add_a_converter(ConverterInterface $converter, Emitter $emitter)
 {
     $pHigh = EmitterInterface::P_HIGH;
     $pNormal = EmitterInterface::P_NORMAL;
     $pLow = EmitterInterface::P_LOW;
     $converter->getSubscribedEvents()->shouldBeCalled()->willReturn(['img' => 'handleImg', 'convert.foo' => ['handleFoo', $pHigh], 'convert.bar' => ['handleBar', $pLow], 'convertfizz' => ['badFizzHandler'], 'convert..buzz' => ['badBuzzHandler']]);
     $emitter->addListener('convert.img', [$converter, 'handleImg'], $pNormal)->shouldBeCalled();
     $emitter->addListener('convert.foo', [$converter, 'handleFoo'], $pHigh)->shouldBeCalled();
     $emitter->addListener('convert.bar', [$converter, 'handleBar'], $pLow)->shouldBeCalled();
     $emitter->addListener('convert.convertfizz', [$converter, 'badFizzHandler'], $pNormal)->shouldBeCalled();
     $emitter->addListener('convert..buzz', [$converter, 'badBuzzHandler'], $pNormal)->shouldBeCalled();
     $this->addConverter($converter)->shouldReturn($this);
 }