[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/web_app/src/controller/ -> lmbAbstractController.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  lmb_require('limb/core/src/lmbClassPath.class.php');
  11  lmb_require('limb/core/src/lmbMixable.class.php');
  12  
  13  /**

  14   * Base class for all controllers

  15   *

  16   * @version $Id: lmbAbstractController.class.php 5945 2007-06-06 08:31:43Z pachanga $

  17   * @package web_app
  18   */
  19  abstract class lmbAbstractController
  20  {
  21    /**

  22     * @var string name of the controller

  23     */
  24    protected $name;
  25    /**

  26     * @var string default action that will be performed by performAction() if no current_action was speficified

  27     */
  28    protected $default_action = 'display';
  29    /**

  30     * @var string

  31     */
  32    protected $current_action;
  33    /**

  34     * @var array array of mixins

  35     */
  36    protected $mixins = array();
  37    /**

  38     * @var object lmbMixable instance

  39     */
  40    protected $mixed;
  41  
  42    /**

  43     *  Constructor.

  44     *  Guesses controller {@link $name} if $name attribute is not defined

  45     */
  46    function __construct()
  47    {
  48      if(!$this->name)
  49       $this->name = $this->_guessName();
  50  
  51      $this->mixed = new lmbMixable();
  52      $this->mixed->setOwner($this);
  53      foreach($this->mixins as $mixin)
  54        $this->mixed->mixin($mixin);
  55    }
  56  
  57    /**

  58     * Using this hacky method mixins can access controller variables

  59     * @param string variable name

  60     * @return mixed

  61     */
  62    function _get($name)
  63    {
  64      if(isset($this->$name))
  65        return $this->$name;
  66    }
  67  
  68    protected function _guessName()
  69    {
  70      if($pos = strpos(get_class($this), 'Controller'))
  71        return lmb_under_scores(substr(get_class($this), 0, $pos));
  72    }
  73  
  74    function getDefaultAction()
  75    {
  76      return $this->default_action;
  77    }
  78  
  79    /**

  80     *  Returns {@link $name}

  81     *  @return string

  82     */
  83    function getName()
  84    {
  85      return $this->name;
  86    }
  87  
  88    function setCurrentAction($action)
  89    {
  90      $this->current_action = $action;
  91    }
  92  
  93    function getCurrentAction()
  94    {
  95      return $this->current_action;
  96    }
  97  
  98    abstract function performAction();
  99    abstract function actionExists($action);
 100  
 101    protected function _findTemplateForAction($action)
 102    {
 103      $template_path = $this->getName() . '/' . $action . '.html';
 104  
 105      $wact_locator = lmbToolkit :: instance()->getWactLocator();
 106  
 107      if($wact_locator->locateSourceTemplate($template_path))
 108        return $template_path;
 109      return null;
 110    }
 111  
 112    static function performCommand()
 113    {
 114      $args = func_get_args();
 115      $class_path = new lmbClassPath(array_shift($args));
 116      return $class_path->createObject($args)->perform();
 117    }
 118  }
 119  
 120  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7