Пример #1
0
 protected function getListenerInfo(CallbackHandler $listener, $identifier = '*')
 {
     $info = array('class' => 'Unknown class', 'method' => 'Unknown method', 'identifier' => $identifier);
     $priority = $listener->getMetadatum('priority');
     if (null === $priority) {
         $priority = 1;
     } elseif (is_array($priority)) {
         $priority = array_shift($priority);
     }
     $info['priority'] = $priority;
     $callback = $listener->getCallback();
     if (is_array($callback)) {
         $info['class'] = is_object($callback[0]) ? get_class($callback[0]) : $callback[0];
         $info['method'] = $callback[1];
     } elseif ($callback instanceof \Closure) {
         $closureRef = new \ReflectionFunction($callback);
         if (method_exists($closureRef, 'getClosureThis')) {
             $info['class'] = get_class($closureRef->getClosureThis());
         } else {
             $info['class'] = $closureRef->getName();
         }
         $info['method'] = 'CLOSURE';
     } elseif (is_object($callback)) {
         $info['class'] = get_class($callback);
         $info['method'] = 'INVOKABLE';
     }
     return $info;
 }
Пример #2
0
 public function testStringCallbackResolvingToClassNameShouldCallViaInvoke()
 {
     $handler = new CallbackHandler('foo', '\\ZendTest\\Stdlib\\SignalHandlers\\Invokable');
     $this->assertEquals('__invoke', $handler->call(), var_export($handler->getCallback(), 1));
 }
Пример #3
0
 public function testCallbackShouldBeArrayIfHandlerPassedToConstructor()
 {
     $handler = new CallbackHandler(array('ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback', 'test'));
     $this->assertSame(array('ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback', 'test'), $handler->getCallback());
 }