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; }
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; }
/** * 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; }
/** * Returns the total number of items. * * Executes the {$countCallback}. * * @return int */ public function count() { return $this->countCallback->call(); }
public function run() { return $this->callback->call($this->params); }
public function testClosureCallbackShouldBeInvokedByCall() { $handler = new CallbackHandler(null, function () { return 'foo'; }); $this->assertEquals('foo', $handler->call()); }
public function __c_callback_handle($callback = null, array $metadata = array()) { $oCallbackHandle = new CallbackHandler($callback); return $oCallbackHandle->call($metadata); }
/** * 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; }