Testing_DocTest
[ class tree: Testing_DocTest ] [ index: Testing_DocTest ] [ all elements ]

Source for file Default.php

Documentation is available at Default.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Testing_DocTest package.
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to the MIT license that is available
  11.  * through the world-wide-web at the following URI:
  12.  * http://opensource.org/licenses/mit-license.php
  13.  *
  14.  * @category  Testing
  15.  * @package   Testing_DocTest
  16.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  17.  * @copyright 2008 David JEAN LOUIS
  18.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  19.  * @version   CVS: $Id$
  20.  * @link      http://pear.php.net/package/Testing_DocTest
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * Include interface.
  27.  */
  28. require_once 'Testing/DocTest/FinderInterface.php';
  29.  
  30. /**
  31.  * DocTest Finder.
  32.  * The finder's job is to find all files given an array of pathes that can
  33.  * contains shell wildcards.
  34.  *
  35.  * <code>
  36.  * // flags: ELLIPSIS
  37.  * $finder = new Testing_DocTest_Finder_Default();
  38.  * $base   = is_dir('@php_dir@') ? '@php_dir@/Testing' : 'Testing';
  39.  * $files  = $finder->find(array(
  40.  *     $base . '/DocTest/Exception.php',
  41.  *     $base . '/D*.php'
  42.  * ));
  43.  * print_r($files);
  44.  * 
  45.  * // expects:
  46.  * // Array
  47.  * // (
  48.  * //     [0] => [...]Exception.php
  49.  * //     [1] => [...]DocTest.php
  50.  * // )
  51.  * </code>
  52.  *
  53.  * @category  Testing
  54.  * @package   Testing_DocTest
  55.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  56.  * @copyright 2008 David JEAN LOUIS
  57.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  58.  * @version   Release: @package_version@
  59.  * @link      http://pear.php.net/package/Testing_DocTest
  60.  * @see       Testing_DocTest_FinderInterface
  61.  * @since     Class available since release 0.1.0
  62.  */
  63. class Testing_DocTest_Finder_Default implements Testing_DocTest_FinderInterface
  64. {
  65.     // find() {{{
  66.  
  67.     /**
  68.      * Find all files matching the given files and/or directories and return an
  69.      * array of file pathes (pathes are absolute, using the realpath function).
  70.      *
  71.      * @param array $pathes an array of files and/or directories, glob syntax
  72.      *                       is supported, ie. you can pass arrays like this:
  73.      *                       array('file1.php', '{dir2,dir3}/*.php')
  74.      *
  75.      * @access public
  76.      * @return array an array of files with their realpathes
  77.      */
  78.     public function find(array $pathes)
  79.     {
  80.         $files   = array();
  81.         $pattern '*.{php,php5,inc,class}';
  82.         foreach ($pathes as $path{
  83.             $flag    defined('GLOB_BRACE'? GLOB_BRACE : null;
  84.             $matches $this->_recursiveGlob($path$pattern$flag);
  85.             if (is_array($matches)) {
  86.                 foreach ($matches as $file{
  87.                     $file realpath($file);
  88.                     if (!in_array($file$files)) {
  89.                         $files[$file;
  90.                     }
  91.                 }
  92.             }
  93.         }
  94.         return $files;
  95.     }
  96.  
  97.     // }}}
  98.     // _recursiveGlob() {{{
  99.  
  100.     /**
  101.      * Recursive version of glob
  102.      *
  103.      * @param string $path    Directory to start with.
  104.      * @param string $pattern Pattern to glob for.
  105.      * @param int    $flags   Flags sent to glob.
  106.      *
  107.      * @access private
  108.      * @return array containing all pattern-matched files.
  109.      */
  110.     private function _recursiveGlob($path$pattern='*'$flags=null)
  111.     {
  112.         if (!is_dir($path)) {
  113.             return glob($path$flags);
  114.         }
  115.         // Get the list of all matching files currently in the directory.
  116.         $files glob($path . DIRECTORY_SEPARATOR . $pattern$flags);
  117.         // Then get a list of all directories in this directory, and
  118.         // run ourselves on the resulting array.
  119.         foreach (glob($path.DIRECTORY_SEPARATOR.'*'GLOB_ONLYDIRas $sdir{
  120.             $sfiles $this->_recursiveGlob($sdir$pattern$flags);
  121.             $files  array_merge($files$sfiles);
  122.         }
  123.         return $files;
  124.     }
  125.     
  126.     // }}}
  127. }

Documentation generated on Mon, 11 Mar 2019 15:52:26 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.