[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/core/src/ -> lmbClassPath.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  lmb_require('limb/core/src/lmbHandle.class.php');
  10  
  11  /**

  12   * class lmbClassPath.

  13   *

  14   * @package core

  15   * @version $Id$

  16   */
  17  class lmbClassPath
  18  {
  19    protected $class_name;
  20    protected $raw_path;
  21  
  22    function __construct($raw_path)
  23    {
  24      if(is_string($raw_path))
  25        $this->raw_path = $this->_parseConstants($raw_path);
  26  
  27      $this->_initClassName();
  28    }
  29  
  30    function getClassName()
  31    {
  32      return $this->class_name;
  33    }
  34  
  35    static function create($path, $args = array())
  36    {
  37      $class_path = new lmbClassPath($path);
  38      return $class_path->createObject($args);
  39    }
  40  
  41    function import()
  42    {
  43      if(!class_exists($this->class_name))
  44      {
  45        if(!@include_once($this->raw_path . '.class.php'))
  46          throw new lmbException("Could not import class from '{$this->raw_path}.class.php'");
  47      }
  48    }
  49  
  50    function createHandle($args = array())
  51    {
  52      return new lmbHandle($this->raw_path, $args);
  53    }
  54  
  55    function createObject($args = array())
  56    {
  57      if(!class_exists($this->class_name))
  58        require_once($this->_getClassFileFullPath());
  59  
  60      $refl = new ReflectionClass($this->class_name);
  61      return call_user_func_array(array($refl, 'newInstance'),$args);
  62    }
  63  
  64    protected function _getClassFileFullPath()
  65    {
  66      return $this->raw_path . '.class.php';
  67    }
  68  
  69    protected function _parseConstants($value)
  70    {
  71      return preg_replace('~\{([^\}]+)\}~e', "constant('\\1')", $value);
  72    }
  73  
  74    protected function _initClassName()
  75    {
  76      if(!$this->raw_path)
  77        throw new lmbException("Invalid class path: {$this->raw_path}");
  78  
  79      $this->class_name = end(explode('/', $this->raw_path));
  80    }
  81  }
  82  
  83  ?>


Generated: Tue Oct 14 04:47:40 2008 Cross-referenced by PHPXref 0.7