/** * Register an <code>IMediator</code> instance with the <code>View</code>. * * <P> * Registers the <code>IMediator</code> so that it can be retrieved by name, * and further interrogates the <code>IMediator</code> for its * <code>INotification</code> interests.</P> * <P> * If the <code>IMediator</code> returns any <code>INotification</code> * names to be notified about, an <code>Observer</code> is created encapsulating * the <code>IMediator</code> instance's <code>handleNotification</code> method * and registering it as an <code>Observer</code> for all <code>INotifications</code> the * <code>IMediator</code> is interested in.</p> * * @param mediatorName the name to associate with this <code>IMediator</code> instance * @param mediator a reference to the <code>IMediator</code> instance */ public function registerMediator(IMediator $mediator) { // do not allow re-registration (you must to removeMediator fist) if ($this->hasMediator($mediator->getMediatorName())) { return; } // Register the Mediator for retrieval by name $this->mediatorMap[$mediator->getMediatorName()] = $mediator; // Get Notification interests, if any. $interests = $mediator->listNotificationInterests(); if (count($interests) > 0) { // Create Observer $observer = new Observer("handleNotification", $mediator); // Register Mediator as Observer for its list of Notification interests foreach ($interests as $interest) { $this->registerObserver($interest, $observer); } } // Alert the Mediator that it has been registered $mediator->onRegister(); }
public function registerMediator(IMediator $mediator) { $this->mediatorMap[$mediator->getMediatorName()] = $mediator; $interests = $mediator->listNotificationInterests(); if (count($interests) > 0) { $observer = new Observer("handleNotification", $mediator); foreach ($interests as $interest) { $this->registerObserver($interest, $observer); } } $mediator->onRegister(); }
/** * Register Mediator * * Register an <b>IMediator</b> instance with the <b>View</b>. * * Registers the <b>IMediator</b> so that it can be retrieved by name, * and further interrogates the <b>IMediator</b> for its * <b>INotification</b> interests. * * If the <b>IMediator</b> returns any <b>INotification</b> * names to be notified about, an <b>Observer</b> is created encapsulating * the <b>IMediator</b> instance's <b>handleNotification</b> method * and registering it as an <b>Observer</b> for all <b>INotifications</b> the * <b>IMediator</b> is interested in. * * @param IMediator $mediator Reference to the <b>IMediator</b> instance. * @return void */ public function registerMediator(IMediator $mediator) { // do not allow re-registration (you must to removeMediator fist) if ($this->hasMediator($mediator->getMediatorName())) { return; } $mediator->initializeNotifier($this->multitonKey); // Register the Mediator for retrieval by name $this->mediatorMap[$mediator->getMediatorName()] = $mediator; // Get Notification interests, if any. $interests = array(); $interests = $mediator->listNotificationInterests(); // Register Mediator as an observer for each notification of interests if (count($interests) > 0) { // Create Observer referencing this mediator's handlNotification method $observer = new Observer("handleNotification", $mediator); // Register Mediator as Observer for its list of Notification interests for ($i = 0; $i < count($interests); $i++) { $this->registerObserver($interests[$i], $observer); } } // alert the mediator that it has been registered $mediator->onRegister(); }