本文整理匯總了PHP中CakeEventManager::dispatch方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeEventManager::dispatch方法的具體用法?PHP CakeEventManager::dispatch怎麽用?PHP CakeEventManager::dispatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CakeEventManager
的用法示例。
在下文中一共展示了CakeEventManager::dispatch方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: work
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;
}
示例2: dispatchEvent
/**
* 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;
}
示例3: trigger
/**
* 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;
}
示例4: trigger
/**
* 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;
}
示例5: callback
/**
* 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();
}
示例6: testStopPropagation
/**
* 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);
}
示例7: testDispatchWithGlobalAndLocalEvents
/**
* 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);
}
示例8: dispatch
public function dispatch($event)
{
$this->log[] = array('name' => $event->name(), 'subject' => $event->subject());
parent::dispatch($event);
}