File indexing completed on 2025-01-26 05:30:00

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Tool
0017  * @subpackage Framework
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Tool_Framework_Loader_Abstract
0025  */
0026 // require_once 'Zend/Tool/Framework/Loader/Abstract.php';
0027 
0028 /**
0029  * @see Zend_Tool_Framework_Loader_IncludePathLoader_RecursiveFilterIterator
0030  */
0031 // require_once 'Zend/Tool/Framework/Loader/IncludePathLoader/RecursiveFilterIterator.php';
0032 
0033 /**
0034  * @category   Zend
0035  * @package    Zend_Tool
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Tool_Framework_Loader_IncludePathLoader extends Zend_Tool_Framework_Loader_Abstract
0040 {
0041 
0042     /**
0043      * _getFiles()
0044      *
0045      * @return array Array of files to load
0046      */
0047     protected function _getFiles()
0048     {
0049         // require_once 'Zend/Loader.php';
0050         $paths = Zend_Loader::explodeIncludePath();
0051 
0052         // used for checking similarly named files
0053         $relativeItems   = array();
0054         $files           = array();
0055         $isZendTraversed = false;
0056 
0057         foreach ($paths as $path) {
0058 
0059             // default patterns to use
0060             $filterDenyDirectoryPattern = '.*(/|\\\\).svn';
0061             $filterAcceptFilePattern    = '.*(?:Manifest|Provider)\.php$';
0062 
0063             if (!file_exists($path) || $path[0] == '.') {
0064                 continue;
0065             }
0066 
0067             $realIncludePath = realpath($path);
0068 
0069             // ensure that we only traverse a single version of Zend Framework on all include paths
0070             if (file_exists($realIncludePath . '/Zend/Tool/Framework/Loader/IncludePathLoader.php')) {
0071                 if ($isZendTraversed === false) {
0072                     $isZendTraversed = true;
0073                 } else {
0074                     // use the deny directory pattern that includes the path to 'Zend', it will not be accepted
0075                     $filterDenyDirectoryPattern = '.*((/|\\\\).svn|' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR) . 'Zend)';
0076                 }
0077             }
0078 
0079             // create recursive directory iterator
0080             $rdi = new RecursiveDirectoryIterator($path);
0081 
0082             // pass in the RecursiveDirectoryIterator & the patterns
0083             $filter = new Zend_Tool_Framework_Loader_IncludePathLoader_RecursiveFilterIterator(
0084                 $rdi,
0085                 $filterDenyDirectoryPattern,
0086                 $filterAcceptFilePattern
0087                 );
0088 
0089             // build the rii with the filter
0090             $iterator = new RecursiveIteratorIterator($filter);
0091 
0092             // iterate over the accepted items
0093             foreach ($iterator as $item) {
0094                 $file = (string)$item;
0095                 if($this->_fileIsBlacklisted($file)) {
0096                     continue;
0097                 }
0098 
0099                 // ensure that the same named file from separate include_paths is not loaded
0100                 $relativeItem = preg_replace('#^' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR, '#') . '#', '', $item->getRealPath());
0101 
0102                 // no links allowed here for now
0103                 if ($item->isLink()) {
0104                     continue;
0105                 }
0106 
0107                 // no items that are relavitely the same are allowed
0108                 if (in_array($relativeItem, $relativeItems)) {
0109                     continue;
0110                 }
0111 
0112                 $relativeItems[] = $relativeItem;
0113                 $files[] = $item->getRealPath();
0114             }
0115         }
0116 
0117         return $files;
0118     }
0119 
0120     /**
0121      *
0122      * @param  string $file
0123      * @return bool
0124      */
0125     protected function _fileIsBlacklisted($file)
0126     {
0127         $blacklist = array(
0128             "PHPUnit".DIRECTORY_SEPARATOR."Framework",
0129             "Zend".DIRECTORY_SEPARATOR."OpenId".DIRECTORY_SEPARATOR."Provider"
0130         );
0131 
0132         foreach($blacklist AS $blacklitedPattern) {
0133             if(strpos($file, $blacklitedPattern) !== false) {
0134                 return true;
0135             }
0136         }
0137         return false;
0138     }
0139 }