[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/src/ -> lmbTestTreeFilePathNode.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  require_once(dirname(__FILE__) . '/lmbTestTreeNode.class.php');
  10  require_once(dirname(__FILE__) . '/lmbTestTreeShallowDirNode.class.php');
  11  require_once(dirname(__FILE__) . '/lmbTestTreeDirNode.class.php');
  12  require_once(dirname(__FILE__) . '/lmbTestTreeFileNode.class.php');
  13  
  14  /**

  15   * class lmbTestTreeFilePathNode.

  16   *

  17   * @package tests_runner

  18   * @version $Id: lmbTestTreeFilePathNode.class.php 6020 2007-06-27 15:12:32Z pachanga $

  19   */
  20  class lmbTestTreeFilePathNode extends lmbTestTreeNode
  21  {
  22    protected $file_path;
  23    protected $offset;
  24  
  25    function __construct($file_path, $offset = null)
  26    {
  27      if(!is_file($file_path) && !is_dir($file_path))
  28        throw new Exception("'$file_path' is not a valid file path!");
  29  
  30      $this->file_path = realpath($file_path);
  31      $this->offset = $offset;
  32    }
  33  
  34    function getFilePath()
  35    {
  36      return $this->file_path;
  37    }
  38  
  39    protected function _loadChildren()
  40    {
  41      $path_items = $this->_getPathItems();
  42      $total = count($path_items);
  43      $current = $this;
  44  
  45      for($i=0;$i<$total;$i++)
  46      {
  47        $item = $path_items[$i];
  48        if(is_dir($item))
  49        {
  50          if($i+1 == $total)//is last?
  51            $current->addChild($new = new lmbTestTreeDirNode($item));
  52          else
  53            $current->addChild($new = new lmbTestTreeShallowDirNode($item));
  54        }
  55        else
  56          $current->addChild($new = new lmbTestTreeFileNode($item));
  57  
  58        $current = $new;
  59      }
  60    }
  61  
  62    protected function _getPathItems()
  63    {
  64      $items = array();
  65      $current = $this->file_path;
  66      while(($new = dirname($current)) != $current)
  67      {
  68        $items[] = $current;
  69        $current = $new;
  70      }
  71  
  72      return $this->_applyOffset(array_reverse($items));
  73    }
  74  
  75    protected function _applyOffset($items)
  76    {
  77      $offset = $this->offset;
  78      if(is_null($offset))
  79        $offset = $this->_determineOptimalOffset($items);
  80  
  81      return array_slice($items, $offset);
  82    }
  83  
  84    protected function _determineOptimalOffset($items)
  85    {
  86      $offset = 0;
  87      $total = count($items);
  88      for($i=0;$i<$total;$i++)
  89      {
  90        $item = $items[$i];
  91        if(is_file($item) || lmbTestTreeShallowDirNode :: hasArtifacts($item))
  92          break;
  93        elseif(is_dir($item) && $i+1 == $total)//last dir should be added anyway
  94          break;
  95  
  96        $offset++;
  97      }
  98      return $offset;
  99    }
 100  }
 101  
 102  ?>


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