function testPrioritizedNotify() { $event = new Event("event"); $event->attach(new TestObserver("first"), 3); $event->attach(new TestObserver("second"), 2); $event->attach(new TestObserver("third"), 1); $event->notify(); $this->assertEquals("third: event\n" . "second: event\n" . "first: event\n", TestObserver::$logs); }
/** * Send this object on the event channel. * * @param string $eventId Event ID. * @param \Hoa\Event\Source $source Source. * @return void */ public function send($eventId, Source $source) { return Event::notify($eventId, $source, $this); }
public function addNewProduct($Data) { Db::getInstance()->beginTransaction(); try { $newProductId = $this->newProduct($Data); $this->addProductTranslation($Data, $newProductId); $this->addPhotoProduct($Data['photo'], $newProductId); $this->addWarrantyProduct($Data['warranty'], $newProductId); $this->addFileProduct($Data['file'], $newProductId); if ($Data['category'] > 0) { $this->addProductToCategoryGroup($Data['category'], $newProductId); } if (!empty($Data['variants'])) { $this->addAttributesProducts($Data['variants'], $newProductId); } if (!empty($Data['upsell'])) { $upsell['products'] = $Data['upsell']; App::getModel('upsell')->editRelated($upsell, $newProductId); } if (!empty($Data['similar'])) { $similar['products'] = $Data['similar']; App::getModel('similarproduct')->editRelated($similar, $newProductId); } if (!empty($Data['crosssell'])) { $crosssell['products'] = $Data['crosssell']; App::getModel('crosssell')->editRelated($crosssell, $newProductId); } $this->updateProductNew($Data, $newProductId); $this->updateProductStatuses($Data, $newProductId); $this->updateProductGroupPrices($Data, $newProductId); $this->updateProductAttributesetPricesAll(); $this->syncStock(); Event::notify($this, 'admin.product.model.save', array('id' => $newProductId, 'data' => $Data)); } catch (Exception $e) { throw new CoreException(_('ERR_PRODUCT_ADD'), 112, $e->getMessage()); } Db::getInstance()->commit(); App::getModel('category')->flushCache(); return true; }
class Event implements EventGenerator { var $observers = array(); function trigger() { echo 'this is event from class Event<br>'; } function addObserver(Observer $observer) { $this->observers[] = $observer; } function notify() { foreach ($this->observers as $key => $observer) { $observer->update(); } } } class Observer1 extends Observer { function update() { echo 'this is a logic in observer<br>'; } } $event = new Event(); $event->trigger(); $observer1 = new Observer1(); $event->addObserver($observer1); $event->notify();
public function editPaymentmethod($Data, $id, $model) { Db::getInstance()->beginTransaction(); try { $this->updatePaymentmethodTranslation($Data, $id); $this->updateDispatchmethodPaymentmethod($Data['dispatchmethod'], $id); $this->updatePaymentmethodView($Data['view'], $id); Event::notify($this, 'admin.paymentmethod.model.save', array('id' => $id, 'data' => $Data, 'model' => $model)); } catch (Exception $e) { throw new CoreException(_('ERR_DISPATCHMETHOD_EDIT'), 125, $e->getMessage()); } Db::getInstance()->commit(); return true; }