[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/fs/src/ -> lmbFileLocator.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/fs/src/exception/lmbFileNotFoundException.class.php');
  10  lmb_require('limb/fs/src/lmbFs.class.php');
  11  
  12  /**

  13   * class lmbFileLocator.

  14   *

  15   * @package fs

  16   * @version $Id$

  17   */
  18  class lmbFileLocator
  19  {
  20    protected $locations;
  21  
  22    function __construct($locations)
  23    {
  24      $this->locations = $locations;
  25    }
  26  
  27    function locate($alias, $params = array())
  28    {
  29      if(lmbFs :: isPathAbsolute($alias))
  30      {
  31         if(file_exists($alias))
  32           return $alias;
  33         else
  34           $this->_handleNotResolvedAlias($alias);
  35      }
  36  
  37      $paths = $this->locations->getLocations($params);
  38      foreach($paths as $path)
  39      {
  40        if(file_exists($path . '/' . $alias))
  41          return $path . '/' . $alias;
  42      }
  43  
  44      $this->_handleNotResolvedAlias($alias);
  45    }
  46  
  47    function getFileLocations()
  48    {
  49      return $this->locations;
  50    }
  51  
  52    function locateAll($alias = '*')
  53    {
  54      $result = array();
  55  
  56      $paths = $this->locations->getLocations();
  57      foreach($paths as $path)
  58      {
  59        if($files = glob($path . '/' . $alias))
  60          $result = array_merge($result, $files);
  61      }
  62  
  63      return array_unique($result);
  64    }
  65  
  66    protected function _handleNotResolvedAlias($alias)
  67    {
  68      throw new lmbFileNotFoundException($alias, 'file alias not resolved');
  69    }
  70  }
  71  
  72  ?>


Generated: Sat Sep 6 04:46:52 2008 Cross-referenced by PHPXref 0.7