Ejemplo n.º 1
0
 /**
  * _getFiles()
  *
  * @return array Array of files to load
  */
 protected function _getFiles()
 {
     $paths = \Zend\Loader::explodeIncludePath();
     // used for checking similarly named files
     $relativeItems = array();
     $files = array();
     $isZendTraversed = false;
     foreach ($paths as $path) {
         // default patterns to use
         $filterDenyDirectoryPattern = '.*(/|\\\\).svn';
         $filterAcceptFilePattern = '.*(?:Manifest|Provider)\\.php$';
         if (!file_exists($path) || $path[0] == '.') {
             continue;
         }
         $realIncludePath = realpath($path);
         // ensure that we only traverse a single version of Zend Framework on all include paths
         if (file_exists($realIncludePath . '/Zend/Tool/Framework/Loader/IncludePathLoader.php')) {
             if ($isZendTraversed === false) {
                 $isZendTraversed = true;
             } else {
                 // use the deny directory pattern that includes the path to 'Zend', it will not be accepted
                 $filterDenyDirectoryPattern = '.*((/|\\\\).svn|' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR) . 'Zend)';
             }
         }
         // create recursive directory iterator
         $rdi = new \RecursiveDirectoryIterator($path);
         // pass in the RecursiveDirectoryIterator & the patterns
         $filter = new RecursiveFilterIterator($rdi, $filterDenyDirectoryPattern, $filterAcceptFilePattern);
         // build the rii with the filter
         $iterator = new \RecursiveIteratorIterator($filter);
         // iterate over the accepted items
         foreach ($iterator as $item) {
             $file = (string) $item;
             if ($this->_fileIsBlacklisted($file)) {
                 continue;
             }
             // ensure that the same named file from separate include_paths is not loaded
             $relativeItem = preg_replace('#^' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR, '#') . '#', '', $item->getRealPath());
             // no links allowed here for now
             if ($item->isLink()) {
                 continue;
             }
             // no items that are relavitely the same are allowed
             if (in_array($relativeItem, $relativeItems)) {
                 continue;
             }
             $relativeItems[] = $relativeItem;
             $files[] = $item->getRealPath();
         }
     }
     return $files;
 }
 /**
  * _getZfPath()
  *
  * @return string|false
  */
 protected function _getZfPath()
 {
     foreach (\Zend\Loader::explodeIncludePath() as $includePath) {
         if (!file_exists($includePath) || $includePath[0] == '.') {
             continue;
         }
         if (realpath($checkedPath = rtrim($includePath, '\\/') . '/Zend/Loader.php') !== false && file_exists($checkedPath)) {
             return dirname($checkedPath);
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * @group ZF-7271
  */
 public function testExplodeIncludePathProperlyIdentifiesStreamSchemes()
 {
     if (PATH_SEPARATOR != ':') {
         $this->markTestSkipped();
     }
     $path = 'phar://zlt.phar:/var/www:.:filter://[a-z]:glob://*';
     $paths = Loader::explodeIncludePath($path);
     $this->assertSame(array('phar://zlt.phar', '/var/www', '.', 'filter://[a-z]', 'glob://*'), $paths);
 }
Ejemplo n.º 4
0
 /**
  * Find realpath of file based on include_path
  *
  * @param  string $fileName
  * @return string
  */
 public static function findRealpathInIncludePath($fileName)
 {
     $includePaths = \Zend\Loader::explodeIncludePath();
     while (count($includePaths) > 0) {
         $filePath = array_shift($includePaths) . DIRECTORY_SEPARATOR . $fileName;
         if (($foundRealpath = realpath($filePath)) !== false) {
             break;
         }
     }
     return $foundRealpath;
 }