web/lib/Zend/Tool/Framework/Loader/IncludePathLoader.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Tool
       
    17  * @subpackage Framework
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: IncludePathLoader.php 20904 2010-02-04 16:18:18Z matthew $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Tool_Framework_Loader_Abstract
       
    25  */
       
    26 require_once 'Zend/Tool/Framework/Loader/Abstract.php';
       
    27 
       
    28 /**
       
    29  * @see Zend_Tool_Framework_Loader_IncludePathLoader_RecursiveFilterIterator
       
    30  */
       
    31 require_once 'Zend/Tool/Framework/Loader/IncludePathLoader/RecursiveFilterIterator.php';
       
    32 
       
    33 /**
       
    34  * @category   Zend
       
    35  * @package    Zend_Tool
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 class Zend_Tool_Framework_Loader_IncludePathLoader extends Zend_Tool_Framework_Loader_Abstract
       
    40 {
       
    41 
       
    42     /**
       
    43      * _getFiles()
       
    44      *
       
    45      * @return array Array of files to load
       
    46      */
       
    47     protected function _getFiles()
       
    48     {
       
    49         require_once 'Zend/Loader.php';
       
    50         $paths = Zend_Loader::explodeIncludePath();
       
    51 
       
    52         // used for checking similarly named files
       
    53         $relativeItems   = array();
       
    54         $files           = array();
       
    55         $isZendTraversed = false;
       
    56 
       
    57         foreach ($paths as $path) {
       
    58 
       
    59             // default patterns to use
       
    60             $filterDenyDirectoryPattern = '.*(/|\\\\).svn';
       
    61             $filterAcceptFilePattern    = '.*(?:Manifest|Provider)\.php$';
       
    62 
       
    63             if (!file_exists($path) || $path[0] == '.') {
       
    64                 continue;
       
    65             }
       
    66 
       
    67             $realIncludePath = realpath($path);
       
    68 
       
    69             // ensure that we only traverse a single version of Zend Framework on all include paths
       
    70             if (file_exists($realIncludePath . '/Zend/Tool/Framework/Loader/IncludePathLoader.php')) {
       
    71                 if ($isZendTraversed === false) {
       
    72                     $isZendTraversed = true;
       
    73                 } else {
       
    74                     // use the deny directory pattern that includes the path to 'Zend', it will not be accepted
       
    75                     $filterDenyDirectoryPattern = '.*((/|\\\\).svn|' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR) . 'Zend)';
       
    76                 }
       
    77             }
       
    78 
       
    79             // create recursive directory iterator
       
    80             $rdi = new RecursiveDirectoryIterator($path);
       
    81 
       
    82             // pass in the RecursiveDirectoryIterator & the patterns
       
    83             $filter = new Zend_Tool_Framework_Loader_IncludePathLoader_RecursiveFilterIterator(
       
    84                 $rdi,
       
    85                 $filterDenyDirectoryPattern,
       
    86                 $filterAcceptFilePattern
       
    87                 );
       
    88 
       
    89             // build the rii with the filter
       
    90             $iterator = new RecursiveIteratorIterator($filter);
       
    91 
       
    92             // iterate over the accepted items
       
    93             foreach ($iterator as $item) {
       
    94                 $file = (string)$item;
       
    95                 if($this->_fileIsBlacklisted($file)) {
       
    96                     continue;
       
    97                 }
       
    98 
       
    99                 // ensure that the same named file from separate include_paths is not loaded
       
   100                 $relativeItem = preg_replace('#^' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR, '#') . '#', '', $item->getRealPath());
       
   101 
       
   102                 // no links allowed here for now
       
   103                 if ($item->isLink()) {
       
   104                     continue;
       
   105                 }
       
   106 
       
   107                 // no items that are relavitely the same are allowed
       
   108                 if (in_array($relativeItem, $relativeItems)) {
       
   109                     continue;
       
   110                 }
       
   111 
       
   112                 $relativeItems[] = $relativeItem;
       
   113                 $files[] = $item->getRealPath();
       
   114             }
       
   115         }
       
   116 
       
   117         return $files;
       
   118     }
       
   119 
       
   120     /**
       
   121      *
       
   122      * @param  string $file
       
   123      * @return bool
       
   124      */
       
   125     protected function _fileIsBlacklisted($file)
       
   126     {
       
   127         $blacklist = array(
       
   128             "PHPUnit".DIRECTORY_SEPARATOR."Framework",
       
   129             "Zend".DIRECTORY_SEPARATOR."OpenId".DIRECTORY_SEPARATOR."Provider"
       
   130         );
       
   131 
       
   132         foreach($blacklist AS $blacklitedPattern) {
       
   133             if(strpos($file, $blacklitedPattern) !== false) {
       
   134                 return true;
       
   135             }
       
   136         }
       
   137         return false;
       
   138     }
       
   139 }