org-puremvc-php-multicore
[ class tree: org-puremvc-php-multicore ] [ index: org-puremvc-php-multicore ] [ all elements ]

Source for file IMediator.php

Documentation is available at IMediator.php

  1. <?php
  2. /**
  3.  * PureMVC Multicore Port to PHP
  4.  *
  5.  * Partly based on PureMVC Port to PHP by:
  6.  * - Omar Gonzalez <omar@almerblank.com>
  7.  * - and Hasan Otuome <hasan@almerblank.com>
  8.  *
  9.  * Created on Jully 24, 2009
  10.  *
  11.  * @version 1.0
  12.  * @author Michel Chouinard <michel.chouinard@gmail.com>
  13.  * @copyright PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
  14.  * @license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0 Unported License
  15.  * @package org.puremvc.php.multicore
  16.  *
  17.  */
  18. /**
  19.  *
  20.  */
  21.  
  22. require_once 'org/puremvc/php/multicore/interfaces/INotifier.php';
  23. require_once 'org/puremvc/php/multicore/interfaces/INotification.php';
  24.  
  25. /**
  26.  * The interface definition for a PureMVC Mediator.
  27.  *
  28.  * In PureMVC, <b>IMediator</b> implementors assume these responsibilities:
  29.  *
  30.  * - Implement a common method which returns a list of all <b>INotification</b>s
  31.  *   the <b>IMediator</b> has interest in.
  32.  * - Implement a notification callback method.
  33.  * - Implement methods that are called when the IMediator is registered or removed from the View.
  34.  *
  35.  * Additionally, <b>IMediator</b>s typically:
  36.  *
  37.  * - Act as an intermediary between one or more view components such as text boxes or
  38.  *   list controls, maintaining references and coordinating their behavior.
  39.  * - This is often the place where event listeners are added to view
  40.  *   components, and their handlers implemented.
  41.  * - Respond to and generate <b>INotifications</b>, interacting with of
  42.  *   the rest of the PureMVC app.
  43.  *
  44.  * When an <b>IMediator</b> is registered with the <b>IView</b>,
  45.  * the <b>IView</b> will call the <b>IMediator</b>'s
  46.  * <b>listNotificationInterests</b> method. The <b>IMediator</b> will
  47.  * return an <b>Array</b> of <b>INotification</b> names which
  48.  * it wishes to be notified about.
  49.  *
  50.  * The <b>IView</b> will then create an <b>Observer</b> object encapsulating
  51.  * that <b>IMediator</b>'s (<b>handleNotification</b>) method and
  52.  * register it as an Observer for each <b>INotification</b> name
  53.  * returned by <b>listNotificationInterests</b>.
  54.  *
  55.  * A concrete IMediator implementor usually looks something like this:
  56.  *
  57.  * <code>
  58.  * <?php
  59.  * require_once 'org/puremvc/php/multicore/interfaces/IMediator.php';
  60.  * require_once 'org/puremvc/php/multicore/patterns/mediator/Mediator.php';
  61.  *
  62.  * class MyMediator extends Mediator implements IMediator
  63.  * {
  64.  *     const NAME = 'MyMediator';
  65.  *
  66.  *     public function __construct( $mediatorName, $viewComponent = null )
  67.  *     {
  68.  *         parent::__construct( MyMediator::NAME, $viewComponent );
  69.  *     }
  70.  *
  71.  *     public function listNotificationInterests()
  72.  *     {
  73.  *         return array( 'Hello', 'Bye' );
  74.  *     }
  75.  *
  76.  *     public function handleNotification( INotification $notification )
  77.  *     {
  78.  *         switch( $notification->getName() )
  79.  *         {
  80.  *             case 'hello':
  81.  *             case 'bye':
  82.  *                 $this->outputNotificationBody( $notification );
  83.  *                 break;
  84.  *         }
  85.  *     }
  86.  *
  87.  *     public function outputNotificationBody( $note )
  88.  *     {
  89.  *         print $note->body;
  90.  *     }
  91.  * }
  92.  * </code>
  93.  *
  94.  * @see INotification
  95.         org\puremvc\php\multicore\interfaces\INotification.php
  96.  * @package org.puremvc.php.multicore
  97.  *
  98.  */
  99. interface IMediator extends INotifier
  100. {
  101.  
  102.     /**
  103.      * Get Mediator Name
  104.      *
  105.      * Get the <b>IMediator</b> instance name
  106.      *
  107.      * @return string The <b>IMediator</b> instance name.
  108.      */
  109.     public function getMediatorName();
  110.  
  111.     /**
  112.      * Get View Component
  113.      *
  114.      * Get the <b>IMediator</b>'s view component.
  115.      *
  116.      * @return mixed The view component
  117.      */
  118.     public function getViewComponent();
  119.  
  120.     /**
  121.      * Set View Component
  122.      *
  123.      * Set the <b>IMediator</b>'s view component.
  124.      *
  125.      * @param mixed $viewComponent The view component.
  126.      * @return void 
  127.      */
  128.     public function setViewComponent$viewComponent );
  129.  
  130.     /**
  131.      * List Notifications Interests.
  132.      *
  133.      * List <b>INotification</b> interests.
  134.      *
  135.      * @return array An <b>Array</b> of the <b>INotification</b> names this <b>IMediator</b> has an interest in.
  136.      */
  137.     public function listNotificationInterests);
  138.  
  139.     /**
  140.      * Handle Notification
  141.      *
  142.      * Handle an <b>INotification</b>.
  143.      *
  144.      * @param INotification $notification The <b>INotification</b> to be handled.
  145.      * @return void 
  146.      */
  147.     public function handleNotificationINotification $notification );
  148.  
  149.     /**
  150.      * onRegister event
  151.      *
  152.      * Called by the <b>View</b> when the <b>Mediator</b> is registered.
  153.      *
  154.      * @return void 
  155.      */
  156.     public function onRegister();
  157.  
  158.     /**
  159.      * onRemove event
  160.      *
  161.      * Called by the <b>View</b> when the <b>Mediator</b> is removed.
  162.      *
  163.      * @return void; 
  164.      */
  165.     public function onRemove();
  166.  
  167. }

Documentation generated on Mon, 03 Aug 2009 04:57:55 +0000 by phpDocumentor 1.4.2