public function work(GearmanJob $job) { $workload = $job->workload(); $json = json_decode($workload, true); if (!json_last_error()) { $workload = $json; } $eventManager = new CakeEventManager(); $eventManager->dispatch(new CakeEvent('Gearman.beforeWork', $this, $workload)); $data = call_user_func($this->_workers[$job->functionName()], $job, $workload); $eventManager->dispatch(new CakeEvent('Gearman.afterWork', $this, $workload)); return $data; }
/** * Syntactic sugar improving the readability for on* methods * * @param string $eventName * @param CakeWampAppServer $scope * @param array $params */ public function dispatchEvent($eventName, $scope, $params) { $event = new CakeEvent($eventName, $scope, $params); $this->outVerbose('Event begin: ' . $eventName); $this->_eventManager->dispatch($event); $this->outVerbose('Event end: ' . $eventName); return $event; }
/** * Triggers a Crud event by creating a new subject and filling it with $data * if $data is an instance of CrudSubject it will be reused as the subject * object for this event. * * If Event listeners return a CakeResponse object, the this method will throw an * exception and fill a 'response' property on it with a reference to the response * object. * * @param string $eventName * @param array $data * @throws Exception if any event listener return a CakeResponse object * @return CrudSubject */ public function trigger($eventName, $data = array()) { $subject = $data instanceof CrudSubject ? $data : $this->_getSubject($data); $event = new CakeEvent($this->config('eventPrefix') . '.' . $eventName, $subject); $this->_eventManager->dispatch($event); if ($event->result instanceof CakeResponse) { $exception = new Exception(); $exception->response = $event->result; throw $exception; } $subject->stopped = false; if ($event->isStopped()) { $subject->stopped = true; } return $subject; }
/** * Triggers a Crud event by creating a new subject and filling it with $data * if $data is an instance of CrudSubject it will be reused as the subject * object for this event. * * If Event listeners return a CakeResponse object, the this method will throw an * exception and fill a 'response' property on it with a reference to the response * object. * * @param string $eventName * @param array $data * @throws Exception if any event listener return a CakeResponse object. * @return CrudSubject */ public function trigger($eventName, $data = array()) { $eventName = $this->settings['eventPrefix'] . '.' . $eventName; $subject = $data instanceof CrudSubject ? $data : $this->getSubject($data); $subject->addEvent($eventName); if (!empty($this->settings['eventLogging'])) { $this->logEvent($eventName, $data); } $event = new CakeEvent($eventName, $subject); $this->_eventManager->dispatch($event); if ($event->result instanceof CakeResponse) { $exception = new Exception(); $exception->response = $event->result; throw $exception; } $subject->stopped = false; if ($event->isStopped()) { $subject->stopped = true; } return $subject; }
/** * Default callback entry point for API callbacks for payment processors * * @param null $token * @throws NotFoundException * @internal param string $processor * @return void */ public function callback($token = null) { $order = $this->Order->find('first', array('contain' => array(), 'conditions' => array('Order.token' => $token))); if (empty($order)) { throw new NotFoundException(__d('cart', 'Invalid payment token %s!', $token)); } try { $Processor = $this->_loadPaymentProcessor($order['Order']['processor']); $status = $Processor->notificationCallback($order); $transactionId = $Processor->getTransactionId(); if (empty($order['Order']['payment_reference']) && !empty($transactionId)) { $order['Order']['payment_reference'] = $transactionId; } $result = $this->Order->save(array('Order' => array('id' => $order['Order']['id'], 'payment_status' => $status, 'payment_reference' => $order['Order']['payment_reference'])), array('validate' => false, 'callbacks' => false)); } catch (Exception $e) { $this->log($e->getMessage(), 'payment-error'); $this->log($this->request, 'payment-error'); } $Event = new CakeEvent('Payment.callback', $this->request); CakeEventManager::dispatch($Event, $this, array($result)); $this->_stop(); }
/** * Tests that stopping an event will not notify the rest of the listeners * * @return void */ public function testStopPropagation() { $manager = new CakeEventManager(); $listener = new CakeEventTestListener(); $manager->attach(array($listener, 'listenerFunction'), 'fake.event'); $manager->attach(array($listener, 'stopListener'), 'fake.event', array('priority' => 8)); $manager->attach(array($listener, 'secondListenerFunction'), 'fake.event', array('priority' => 5)); $event = new CakeEvent('fake.event'); $manager->dispatch($event); $expected = array('secondListenerFunction'); $this->assertEquals($expected, $listener->callStack); }
/** * Test that events are dispatched properly when there are global and local * listeners at the same priority. * * @return void */ public function testDispatchWithGlobalAndLocalEvents() { $listener = new CustomTestEventListener(); CakeEventManager::instance()->attach($listener); $listener2 = new CakeEventTestListener(); $manager = new CakeEventManager(); $manager->attach(array($listener2, 'listenerFunction'), 'fake.event'); $manager->dispatch(new CakeEvent('fake.event', $this)); $this->assertEquals(array('listenerFunction'), $listener->callStack); $this->assertEquals(array('listenerFunction'), $listener2->callStack); }
public function dispatch($event) { $this->log[] = array('name' => $event->name(), 'subject' => $event->subject()); parent::dispatch($event); }