Example #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;
 }
Example #2
0
 public function runAs($role, $callback, $args = array())
 {
     if (!$callback instanceof CallbackHandler) {
         $callback = new CallbackHandler($callback);
     }
     $this->setTempRole($role);
     //execute
     $ret = $callback->call($args);
     $this->rollbackTempRole();
     return $ret;
 }
Example #3
0
 /**
  * Unsubscribe a handler from an event
  * 
  * @param  CallbackHandler $handler 
  * @return bool Returns true if event and handle found, and unsubscribed; returns false if either event or handle not found
  */
 public function detach(CallbackHandler $handler)
 {
     $event = $handler->getEvent();
     if (empty($this->events[$event])) {
         return false;
     }
     $return = $this->events[$event]->remove($handler);
     if (!$return) {
         return false;
     }
     if (!count($this->events[$event])) {
         unset($this->events[$event]);
     }
     return true;
 }
Example #4
0
 /**
  * Returns the total number of items.
  *
  * Executes the {$countCallback}.
  *
  * @return int
  */
 public function count()
 {
     return $this->countCallback->call();
 }
Example #5
0
 public function run()
 {
     return $this->callback->call($this->params);
 }
 public function testClosureCallbackShouldBeInvokedByCall()
 {
     $handler = new CallbackHandler(null, function () {
         return 'foo';
     });
     $this->assertEquals('foo', $handler->call());
 }
Example #7
0
File: C.php Project: yuwenyu/SoJo
 public function __c_callback_handle($callback = null, array $metadata = array())
 {
     $oCallbackHandle = new CallbackHandler($callback);
     return $oCallbackHandle->call($metadata);
 }
Example #8
0
 /**
  * Unsubscribe a listener from an event
  *
  * @param  CallbackHandler $listener
  * @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
  */
 public function detach(CallbackHandler $listener)
 {
     $event = $listener->getMetadatum('event');
     if (!$event || empty($this->events[$event])) {
         return false;
     }
     $return = $this->events[$event]->remove($listener);
     if (!$return) {
         return false;
     }
     if (!count($this->events[$event])) {
         unset($this->events[$event]);
     }
     return true;
 }