/** */ public function testNotify() { $listener = new Listener('test', function () { return true; }); $this->assertTrue($listener->notify(new Event())); }
/** * @throws Exception * * @return bool */ public function send() : bool { if (!$this->getTo() && !$this->getCc() && !$this->getBcc()) { throw new Exception('Cannot send message without a destination address'); } $return = $this->mailer->send($this->message) > 0 ? true : false; self::$listener->sendLog(); return $return; }
/** * @param Listener $listener * @return $this */ public function addListener(Listener $listener) { $eventName = $listener->getEventName(); if (!isset($this->listeners[$eventName])) { $this->listeners[$eventName] = []; } $this->listeners[$eventName][] = $listener; return $this; }
/** * Add a listener for a WP hook. * * @since 0.1.0 * * @param string $hook Hook to create listener for. * @param \Wplog\Events\Listener $listener The closure that creates the event for * the hook. * * @return void */ public function addListener(string $hook, Listener $listener) { // Create a callback wrapper to let the world outside the hook know about it. $cb = function (...$args) use($listener) { $event = $listener->onHookTrigger(current_filter(), $args); if ($event instanceof Event) { $this->listenerEvents[] = $event; } }; add_action($hook, $cb, 999, 10); }
public function addListener(Listener $callback) { $type = $callback->getType(); $id = $callback->getId(); if (!isset($this->listeners[$type])) { $this->listeners[$type] = ['id' => [], 'global' => []]; } if ($id) { if (!isset($this->listeners[$type]['id'][$id])) { $this->listeners[$type]['id'][$id] = []; } $this->listeners[$type]['id'][$id][] = $callback; } else { $this->listeners[$type]['global'][] = $callback; } }
/** * Listen for API actions */ function listen_for_actions() { $listener = new Listener(EDD_HELPSCOUT_API_PATH); $action = $listener->listen($_SERVER['REQUEST_URI']); if (!empty($action)) { /** * Perform an API action. Request is unauthorized at this point, so make sure to perform auth checks in your action callback. * * The dynamic portion of the hook, `$action`, refers to the name of the action. * * @see authorize_request * @see verify_request_signature */ do_action('edd_helpscout_' . $action); } }
public function run($args) { $logger = LoggerFactory::getFileLogger('check_processes'); $logger->log(__METHOD__ . ' Start checkprocesses command.'); $criteria = new CDbCriteria(); $criteria->compare('stopped', 0); $connections = Listener::model()->findAll($criteria); $logger->log(__METHOD__ . ' Found ' . count($connections) . ' connections.'); foreach ($connections as $connection) { $logger->log(__METHOD__ . ' Listener info:', array('process_pid' => $connection->process_pid, 'listener_id' => $connection->listener_id, 'source' => $connection->source)); if (ProcessPid::isActiveProcess($connection->process_pid) === false) { ListenerProcess::addComment($connection->listener_id, 'comment', 'System found out that process is not active any more. Process will be re-run right now.'); Listener::stopConnection($connection->listener_id, time()); Listener::runConnection($connection->source, $connection->additional_param, 'auto'); } } // ProcessPid::killProcess(12376); $synchronization = new Synchronization(); if ($synchronization->isProcessed() && ProcessPid::isActiveProcess($synchronization->getTcpServerPid()) === false) { $synchronization->startTcpServer(); } if ($synchronization->isProcessed() && ProcessPid::isActiveProcess($synchronization->getTcpClientPid()) === false) { $synchronization->startTcpClient(); } }
private function listen($id) { if (!isset($id)) { return 401; } else { $listener = new Listener(array("type" => CONVERSATION)); $response = $listener->listen(); if (is_array($response)) { $output_array = array(); foreach ($response as $v) { if (is_array($v) && array_key_exists("thread", $v)) { if ($v["thread"] == $id) { array_push($output_array, $v); } } } return $output_array; } else { return $response; } } }
public function bind(Listener $listener) { if (!$this->_listeners[$listener->getId()]) { $this->_listeners[$listener->getId()] = []; } $pos = count($this->_listeners[$listener->getId()]); foreach ($this->_listeners[$listener->getId()] as $k => $v) { if ($v->priority > $listener->getPriority()) { $pos = $k; break; } } array_splice($this->_listeners[$listener->getId()], $pos, 0, [$listener]); return $this; }
/** * @param RegisteredListener|Listener|Plugin $object */ public function unregister($object) { if ($object instanceof Plugin or $object instanceof Listener) { $changed = false; foreach ($this->handlerSlots as $priority => $list) { foreach ($list as $hash => $listener) { if ($object instanceof Plugin and $listener->getPlugin() === $object or $object instanceof Listener and $listener->getListener() === $object) { unset($this->handlerSlots[$priority][$hash]); $changed = true; } } } if ($changed === true) { $this->handlers = null; } } elseif ($object instanceof RegisteredListener) { if (isset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)])) { unset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)]); $this->handlers = null; } } }
private function _end_document() { $this->_listener->end_document(); $this->_state = self::STATE_DONE; }
/** * @todo this should use a request target * @param Identifier $page * @return type */ public function urlForListener(Listener $listener) { $target; $page = $this->getPage(); $behaviour = null; if ($listener instanceof Behaviour) { $behaviour = $listener->getBehaviourId(); } if ($page->isPageStateless()) { $target = new PageRequestWithListenerTarget($page::getIdentifier(), $this->getComponentPath(), $behaviour); } else { $target = new ListenerRequestTarget($this->getPage(), $this->getComponentPath(), $behaviour); } return $this->getRequestCycle()->generateUrl($target); }
public function startTcpServer() { $source = 'TCP:' . $this->forwarding_messages_ip . ":" . $this->tcp_server_command_port; $last_connection = Listener::getLastConnectionInfoForSynch($source); if ($last_connection && !$last_connection['stopped']) { } else { $command = Yii::app()->params['applications']['php_exe_path'] . ' -f ' . Yii::app()->params['applications']['console_app_path'] . ' tcpserver '; It::runAsynchCommand($command); } }
private function endDocument() { $this->listener->onDocumentEnd(); $this->state = self::STATE_DONE; }
public function actionGetStatus() { if (!$_REQUEST['source']) { echo json_encode(array('errors' => array('Unknown connection type'))); Yii::app()->end(); } $return = array(); $source = strtoupper($_REQUEST['source']); $last_connection = Listener::getLastConnectionInfo($source); $return = array('listener_id' => $last_connection ? $last_connection['listener_id'] : 0, 'started_show' => $last_connection ? $last_connection['started_show'] : '', 'stopped_show' => $last_connection ? $last_connection['stopped_show'] : '', 'duration' => $last_connection ? $last_connection['duration'] : 0, 'duration_formatted' => $last_connection['duration_formatted']); echo json_encode($return); Yii::app()->end(); }
public function run(array $stack, array $context, Listener $listener) { $stack = array_merge($stack, [$this]); $err = null; $listener->before($stack); try { apply_by_name($this->implementation, $context); } catch (\Exception $err) { // fall through } $listener->after($stack, $err); }
public function run() { $this->_logger->log(__CLASS__ . ' ' . __METHOD__); $this->_recognizeHardware(); switch ($this->hardware) { case 'com': new ProcessListenCom($this->_logger, $this->source, $this->by, $this->listener); break; case 'client': new ProcessListenClient($this->_logger, $this->source, $this->by, $this->listener); break; case 'poller': new ProcessListenPolling($this->_logger, $this->source, $this->by, $this->listener); break; case 'server': new ProcessListenServer($this->_logger, $this->source, $this->by, $this->listener); break; } ListenerProcess::addComment($this->listener->listener_id, 'stopped', 'Script execution was completed'); Listener::stopConnection($this->listener->listener_id); }
$return; switch ($lib) { case "item": $library = new Item($_GET); $return = $library->run(); break; case "user": $library = new User($_GET); $return = $library->run(false); break; case "login": $library = new Login($_GET); $return = $library->run(); break; case "listener": $library = new Listener($_GET); $return = $library->listen(); break; case "messenger": $library = new Messenger($_GET); $return = $library->run(); break; case "exchange": $library = new Exchange($_GET); $return = $library->run(); break; case "feed": $library = new Feed($_GET); $return = $library->run(); break; default:
public function endVCal(VCal $VCal) { if (count($this->filters) === 0) { return parent::endVCal($VCal); } $out = array(); foreach ($VCal->container->elements as $element) { $keep = true; if ($element instanceof Container && $element->is(Container::EVENT)) { foreach ($this->filters as $name => $pattern) { $prop = $element->getFirst($name); if ($prop !== null && preg_match($pattern, $prop->value)) { $keep = false; break; } } } if ($keep) { $out[] = $element; } } return $VCal->withElements($out); }
public static function stopConnection($listener_id, $time = 0) { $time = $time ? $time : time(); Listener::model()->updateByPk($listener_id, array('stopped' => $time)); ListenerProcess::addComment($listener_id, 'comment', 'Stop time was saved'); return true; }
public function free($name, Listener $listener = null, $onlyClear = false) { if (null === $listener) { /** @var \Aurora\Event\Listener $listener */ foreach ($this->listeners->get($name) as $listener) { if (!$onlyClear) { $listener->delete(); } } $this->listeners->remove($name); } else { if (!$onlyClear) { $listener->delete(); } $this->listeners->removeSub($name, $listener); } }
$t->is($dispatcher->getListeners('bar'), array('listenToBar', 'listenToBarBar'), '->connect() can connect several listeners for the same event name'); $dispatcher->connect('barbar', 'listenToBarBar'); $dispatcher->disconnect('bar', 'listenToBarBar'); $t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->disconnect() disconnects a listener for an event name'); $t->is($dispatcher->getListeners('barbar'), array('listenToBarBar'), '->disconnect() disconnects a listener for an event name'); $t->ok($dispatcher->disconnect('foobar', 'listen') === false, '->disconnect() returns false if the listener does not exist'); // ->getListeners() ->hasListeners() $t->diag('->getListeners() ->hasListeners()'); $t->is($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener'); $dispatcher->connect('foo', 'listenToFoo'); $t->is($dispatcher->hasListeners('foo'), true, '->hasListeners() returns true if the event has some listeners'); $dispatcher->disconnect('foo', 'listenToFoo'); $t->is($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener'); $t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->getListeners() returns an array of listeners connected to the given event name'); $t->is($dispatcher->getListeners('foobar'), array(), '->getListeners() returns an empty array if no listener are connected to the given event name'); $listener = new Listener(); // ->notify() $t->diag('->notify()'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $e = $dispatcher->notify($event = new Event(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFoolistenToFooBis', '->notify() notifies all registered listeners in order'); $t->is($e, $event, '->notify() returns the event object'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->notify(new Event(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFooBislistenToFoo', '->notify() notifies all registered listeners in order');
private function prepareListenerInserts($limit_timestamp) { $result_sql = ""; $sql = "SELECT * \n FROM `" . Listener::model()->tableName() . "`\n WHERE `created` <= '" . $limit_timestamp . "' \n LIMIT 0, 50"; $res = Yii::app()->db->createCommand($sql)->queryAll(); $total = count($res); $ids = array(); if ($res) { $fields = array(); foreach ($res[0] as $key2 => $value2) { $fields[] = $key2; } $sql_header = "INSERT IGNORE INTO `" . Listener::model()->tableName() . "` (`" . implode('`,`', $fields) . "`) VALUES "; $result_sql = $sql_header; foreach ($res as $key => $value) { $ids[] = $value['listener_id']; $result_sql .= "('" . implode("','", $value) . "')"; if ($key + 1 < $total) { $result_sql .= ", "; } } $this->addBackupLog("Prepared " . count($ids) . " inserts for listener"); } return array($ids, $result_sql); }