[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/core/src/ -> lmbMixable.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  /**

  11   * class lmbMixable.

  12   *

  13   * @package core

  14   * @version $Id$

  15   */
  16  class lmbMixable
  17  {
  18    protected $owner;
  19    protected $mixins = array();
  20    protected $mixins_loaded = false;
  21    protected $mixins_signatures = array();
  22  
  23    function mixin($mixin)
  24    {
  25      $this->mixins[] = $mixin;
  26    }
  27  
  28    function setOwner($owner)
  29    {
  30      $this->owner = $owner;
  31    }
  32  
  33    function __call($method, $args)
  34    {
  35      $this->_ensureSignatures();
  36  
  37      if(!isset($this->mixins_signatures[$method]))
  38        throw new lmbException('Mixable does not support method "' . $method . '" (no such signature)',
  39                                array('method' => $method));
  40  
  41  
  42      return call_user_func_array(array($this->mixins_signatures[$method], $method), $args);
  43    }
  44  
  45    function _get($name)
  46    {
  47      if(isset($this->$name))
  48        return $this->$name;
  49    }
  50  
  51    protected function _ensureSignatures()
  52    {
  53      if($this->mixins_loaded)
  54        return;
  55  
  56      $owner = $this->owner ? $this->owner : $this;
  57  
  58      foreach($this->mixins as $mixin)
  59      {
  60        if(is_object($mixin))
  61        {
  62          $obj = $mixin;
  63          $class = get_class($mixin);
  64        }
  65        else
  66        {
  67          $obj = new $mixin();
  68          $class = $mixin;
  69        }
  70        $obj->setOwner($owner);
  71  
  72        foreach(get_class_methods($class) as $method)
  73          $this->mixins_signatures[$method] = $obj;
  74      }
  75  
  76      $this->mixins_loaded = true;
  77    }
  78  }
  79  ?>


Generated: Tue Oct 7 05:02:03 2008 Cross-referenced by PHPXref 0.7