Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • CustomFilterIterator
  • DateRangeFilterIterator
  • DepthRangeFilterIterator
  • ExcludeDirectoryFilterIterator
  • FilecontentFilterIterator
  • FilenameFilterIterator
  • FilePathsIterator
  • FileTypeFilterIterator
  • FilterIterator
  • MultiplePcreFilterIterator
  • PathFilterIterator
  • RecursiveDirectoryIterator
  • SizeRangeFilterIterator
  • SortableIterator
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  1: <?php
  2: 
  3: /*
  4:  * This file is part of the Symfony package.
  5:  *
  6:  * (c) Fabien Potencier <fabien@symfony.com>
  7:  *
  8:  * For the full copyright and license information, please view the LICENSE
  9:  * file that was distributed with this source code.
 10:  */
 11: 
 12: namespace Symfony\Component\Finder\Iterator;
 13: 
 14: use Symfony\Component\Finder\SplFileInfo;
 15: 
 16: /**
 17:  * Iterate over shell command result.
 18:  *
 19:  * @author Jean-François Simon <contact@jfsimon.fr>
 20:  */
 21: class FilePathsIterator extends \ArrayIterator
 22: {
 23:     /**
 24:      * @var string
 25:      */
 26:     private $baseDir;
 27: 
 28:     /**
 29:      * @var int
 30:      */
 31:     private $baseDirLength;
 32: 
 33:     /**
 34:      * @var string
 35:      */
 36:     private $subPath;
 37: 
 38:     /**
 39:      * @var string
 40:      */
 41:     private $subPathname;
 42: 
 43:     /**
 44:      * @var SplFileInfo
 45:      */
 46:     private $current;
 47: 
 48:     /**
 49:      * @param array  $paths   List of paths returned by shell command
 50:      * @param string $baseDir Base dir for relative path building
 51:      */
 52:     public function __construct(array $paths, $baseDir)
 53:     {
 54:         $this->baseDir       = $baseDir;
 55:         $this->baseDirLength = strlen($baseDir);
 56: 
 57:         parent::__construct($paths);
 58:     }
 59: 
 60:     /**
 61:      * @param string $name
 62:      * @param array  $arguments
 63:      *
 64:      * @return mixed
 65:      */
 66:     public function __call($name, array $arguments)
 67:     {
 68:         return call_user_func_array(array($this->current(), $name), $arguments);
 69:     }
 70: 
 71:     /**
 72:      * Return an instance of SplFileInfo with support for relative paths.
 73:      *
 74:      * @return SplFileInfo File information
 75:      */
 76:     public function current()
 77:     {
 78:         return $this->current;
 79:     }
 80: 
 81:     /**
 82:      * @return string
 83:      */
 84:     public function key()
 85:     {
 86:         return $this->current->getPathname();
 87:     }
 88: 
 89:     public function next()
 90:     {
 91:         parent::next();
 92:         $this->buildProperties();
 93:     }
 94: 
 95:     public function rewind()
 96:     {
 97:         parent::rewind();
 98:         $this->buildProperties();
 99:     }
100: 
101:     /**
102:      * @return string
103:      */
104:     public function getSubPath()
105:     {
106:         return $this->subPath;
107:     }
108: 
109:     /**
110:      * @return string
111:      */
112:     public function getSubPathname()
113:     {
114:         return $this->subPathname;
115:     }
116: 
117:     private function buildProperties()
118:     {
119:         $absolutePath = parent::current();
120: 
121:         if ($this->baseDir === substr($absolutePath, 0, $this->baseDirLength)) {
122:             $this->subPathname = ltrim(substr($absolutePath, $this->baseDirLength), '/\\');
123:             $dir = dirname($this->subPathname);
124:             $this->subPath = '.' === $dir ? '' : $dir;
125:         } else {
126:             $this->subPath = $this->subPathname = '';
127:         }
128: 
129:         $this->current = new SplFileInfo(parent::current(), $this->subPath, $this->subPathname);
130:     }
131: }
132: 
php-coveralls API documentation generated by ApiGen 2.8.0