3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder; /** * Extends \SplFileInfo to support relative paths. * * @author Fabien Potencier <fabien@symfony.com> */ class SplFileInfo extends \SplFileInfo { private $relativePath; private $relativePathname; /** * Constructor. * * @param string $file The file name * @param string $relativePath The relative path * @param string $relativePathname The relative path name */ public function __construct($file, $relativePath, $relativePathname) { parent::__construct($file); $this->relativePath = $relativePath; $this->relativePathname = $relativePathname; } /** * Returns the relative path. * * @return string the relative path */ public function getRelativePath() { return $this->relativePath; } /** * Returns the relative path name. * * @return string the relative path name */ public function getRelativePathname() { return $this->relativePathname; } /** * Returns the contents of the file. * * @return string the contents of the file * * @throws \RuntimeException */ public function getContents() { $level = error_reporting(0); $content = file_get_contents($this->getPathname()); error_reporting($level); if (false === $content) { $error = error_get_last(); throw new \RuntimeException($error['message']); } return $content; } } /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Iterator; use Symfony\Component\Finder\Exception\AccessDeniedException; use Symfony\Component\Finder\SplFileInfo; /** * Extends the \RecursiveDirectoryIterator to support relative paths. * * @author Victor Berchet <victor@suumit.com> */ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator { /** * @var bool */ private $ignoreUnreadableDirs; /** * @var bool */ private $rewindable; // these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations private $rootPath; private $subPath = false; private $directorySeparator = '/'; /** * Constructor. * * @param string $path * @param int $flags * @param bool $ignoreUnreadableDirs * * @throws \RuntimeException */ public function __construct($path, $flags, $ignoreUnreadableDirs = false) { if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) { throw new \RuntimeException('This iterator only support returning current as fileinfo.'); } parent::__construct($path, $flags); $this->ignoreUnreadableDirs = $ignoreUnreadableDirs; if ('/' !== DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) { $this->directorySeparator = DIRECTORY_SEPARATOR; } } /** * Return an instance of SplFileInfo with support for relative paths. * * @return SplFileInfo File information */ public function current() { // the logic here avoids redoing the same work in all iterations if (null === $this->rootPath) { $this->rootPath = $this->getPath(); } if (false === $subPathname = $this->subPath) { $subPathname = $this->subPath = $this->getSubPath(); } if ('' !== $subPathname) { $subPathname .= $this->directorySeparator; } $subPathname .= $this->getFilename(); return new SplFileInfo($this->rootPath.$this->directorySeparator.$subPathname, $this->subPath, $subPathname); } /** * @return \RecursiveIterator * * @throws AccessDeniedException */ public function getChildren() { try { $children = parent::getChildren(); if ($children instanceof self) { // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs; // performance optimization to avoid redoing the same work in all children $children->rewindable = &$this->rewindable; $children->rootPath = $this->rootPath; } return $children; } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { // If directory is unreadable and finder is set to ignore it, a fake empty content is returned. return new \RecursiveArrayIterator(array()); } else { throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } } } /** * Do nothing for non rewindable stream. */ public function rewind() { if (false === $this->isRewindable()) { return; } // @see https://bugs.php.net/bug.php?id=49104 parent::next(); parent::rewind(); } /** * Checks if the stream is rewindable. * * @return bool true when the stream is rewindable, false otherwise */ public function isRewindable() { if (null !== $this->rewindable) { return $this->rewindable; } if (false !== $stream = @opendir($this->getPath())) { $infos = stream_get_meta_data($stream); closedir($stream); if ($infos['seekable']) { return $this->rewindable = true; } } return $this->rewindable = false; } } $r = new RecursiveDirectoryIterator('./', 0); $r = new RecursiveIteratorIterator($r); var_dump(iterator_to_array($r));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Lg65
function name:  (null)
number of ops:  16
compiled vars:  !0 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  229     0  E >   NEW                                              $1      'Symfony%5CComponent%5CFinder%5CIterator%5CRecursiveDirectoryIterator'
          1        SEND_VAL_EX                                              '.%2F'
          2        SEND_VAL_EX                                              0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
  230     5        NEW                                              $4      'Symfony%5CComponent%5CFinder%5CIterator%5CRecursiveIteratorIterator'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $4
  232     9        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5CIterator%5Cvar_dump'
         10        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5CIterator%5Citerator_to_array'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $7      
         13        SEND_VAR_NO_REF_EX                                       $7
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

Class Symfony\Component\Finder\SplFileInfo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Lg65
function name:  __construct
number of ops:  11
compiled vars:  !0 = $file, !1 = $relativePath, !2 = $relativePathname
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   33     3        INIT_STATIC_METHOD_CALL                                  
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   34     6        ASSIGN_OBJ                                               'relativePath'
          7        OP_DATA                                                  !1
   35     8        ASSIGN_OBJ                                               'relativePathname'
          9        OP_DATA                                                  !2
   36    10      > RETURN                                                   null

End of function __construct

Function getrelativepath:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Lg65
function name:  getRelativePath
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   FETCH_OBJ_R                                      ~0      'relativePath'
          1      > RETURN                                                   ~0
   46     2*     > RETURN                                                   null

End of function getrelativepath

Function getrelativepathname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Lg65
function name:  getRelativePathname
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'relativePathname'
          1      > RETURN                                                   ~0
   56     2*     > RETURN                                                   null

End of function getrelativepathname

Function getcontents:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Lg65
function name:  getContents
number of ops:  26
compiled vars:  !0 = $level, !1 = $content, !2 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5Cerror_reporting'
          1        SEND_VAL_EX                                              0
          2        DO_FCALL                                      0  $3      
          3        ASSIGN                                                   !0, $3
   68     4        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5Cfile_get_contents'
          5        INIT_METHOD_CALL                                         'getPathname'
          6        DO_FCALL                                      0  $5      
          7        SEND_VAR_NO_REF_EX                                       $5
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !1, $6
   69    10        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5Cerror_reporting'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   70    13        TYPE_CHECK                                    4          !1
         14      > JMPZ                                                     ~9, ->24
   71    15    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5Cerror_get_last'
         16        DO_FCALL                                      0  $10     
         17        ASSIGN                                                   !2, $10
   72    18        NEW                                              $12     'RuntimeException'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $13     !2, 'message'
         21        SEND_FUNC_ARG                                            $13
         22        DO_FCALL                                      0          
         23      > THROW                                         0          $12
   75    24    > > RETURN                                                   !1
   76    25*     > RETURN                                                   null

End of function getcontents

End of class Symfony\Component\Finder\SplFileInfo.

Class Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 25
filename:       /in/8Lg65
function name:  __construct
number of ops:  30
compiled vars:  !0 = $path, !1 = $flags, !2 = $ignoreUnreadableDirs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  124     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
  126     3        FETCH_CLASS_CONSTANT                             ~3      'CURRENT_AS_PATHNAME'
          4        FETCH_CLASS_CONSTANT                             ~4      'CURRENT_AS_SELF'
          5        BW_OR                                            ~5      ~3, ~4
          6        BW_AND                                           ~6      !1, ~5
          7      > JMPZ                                                     ~6, ->12
  127     8    >   NEW                                              $7      'RuntimeException'
          9        SEND_VAL_EX                                              'This+iterator+only+support+returning+current+as+fileinfo.'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $7
  130    12    >   INIT_STATIC_METHOD_CALL                                  
         13        SEND_VAR_EX                                              !0
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
  131    16        ASSIGN_OBJ                                               'ignoreUnreadableDirs'
         17        OP_DATA                                                  !2
  132    18        FETCH_CONSTANT                                   ~11     'Symfony%5CComponent%5CFinder%5CIterator%5CDIRECTORY_SEPARATOR'
         19        IS_NOT_IDENTICAL                                 ~12     ~11, '%2F'
         20      > JMPZ_EX                                          ~12     ~12, ->25
         21    >   FETCH_CLASS_CONSTANT                             ~13     'UNIX_PATHS'
         22        BW_AND                                           ~14     !1, ~13
         23        BOOL_NOT                                         ~15     ~14
         24        BOOL                                             ~12     ~15
         25    > > JMPZ                                                     ~12, ->29
  133    26    >   FETCH_CONSTANT                                   ~17     'Symfony%5CComponent%5CFinder%5CIterator%5CDIRECTORY_SEPARATOR'
         27        ASSIGN_OBJ                                               'directorySeparator'
         28        OP_DATA                                                  ~17
  135    29    > > RETURN                                                   null

End of function __construct

Function current:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 16
Branch analysis from position: 7
filename:       /in/8Lg65
function name:  current
number of ops:  36
compiled vars:  !0 = $subPathname
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  146     0  E >   FETCH_OBJ_R                                      ~1      'rootPath'
          1        TYPE_CHECK                                    2          ~1
          2      > JMPZ                                                     ~2, ->7
  147     3    >   INIT_METHOD_CALL                                         'getPath'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN_OBJ                                               'rootPath'
          6        OP_DATA                                                  $4
  149     7    >   FETCH_OBJ_R                                      ~5      'subPath'
          8        ASSIGN                                           ~6      !0, ~5
          9        TYPE_CHECK                                    4          ~6
         10      > JMPZ                                                     ~7, ->16
  150    11    >   INIT_METHOD_CALL                                         'getSubPath'
         12        DO_FCALL                                      0  $9      
         13        ASSIGN_OBJ                                       ~8      'subPath'
         14        OP_DATA                                                  $9
         15        ASSIGN                                                   !0, ~8
  152    16    >   IS_NOT_IDENTICAL                                         !0, ''
         17      > JMPZ                                                     ~11, ->20
  153    18    >   FETCH_OBJ_R                                      ~12     'directorySeparator'
         19        ASSIGN_OP                                     8          !0, ~12
  155    20    >   INIT_METHOD_CALL                                         'getFilename'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN_OP                                     8          !0, $14
  157    23        NEW                                              $16     'Symfony%5CComponent%5CFinder%5CSplFileInfo'
         24        FETCH_OBJ_R                                      ~17     'rootPath'
         25        FETCH_OBJ_R                                      ~18     'directorySeparator'
         26        CONCAT                                           ~19     ~17, ~18
         27        CONCAT                                           ~20     ~19, !0
         28        SEND_VAL_EX                                              ~20
         29        CHECK_FUNC_ARG                                           
         30        FETCH_OBJ_FUNC_ARG                               $21     'subPath'
         31        SEND_FUNC_ARG                                            $21
         32        SEND_VAR_EX                                              !0
         33        DO_FCALL                                      0          
         34      > RETURN                                                   $16
  158    35*     > RETURN                                                   null

End of function current

Function getchildren:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Found catch point at position: 17
Branch analysis from position: 17
2 jumps found. (Code = 107) Position 1 = 18, Position 2 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/8Lg65
function name:  getChildren
number of ops:  36
compiled vars:  !0 = $children, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  168     0  E >   INIT_STATIC_METHOD_CALL                                  'getChildren'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
  170     3        INSTANCEOF                                               !0
          4      > JMPZ                                                     ~4, ->15
  172     5    >   FETCH_OBJ_R                                      ~6      'ignoreUnreadableDirs'
          6        ASSIGN_OBJ                                               !0, 'ignoreUnreadableDirs'
          7        OP_DATA                                                  ~6
  175     8        FETCH_OBJ_W                                      $8      'rewindable'
          9        MAKE_REF                                         $9      $8
         10        ASSIGN_OBJ_REF                                           !0, 'rewindable'
         11        OP_DATA                                                  $9
  176    12        FETCH_OBJ_R                                      ~11     'rootPath'
         13        ASSIGN_OBJ                                               !0, 'rootPath'
         14        OP_DATA                                                  ~11
  179    15    > > RETURN                                                   !0
         16*       JMP                                                      ->35
  180    17  E > > CATCH                                       last         'UnexpectedValueException'
  181    18    >   FETCH_OBJ_R                                      ~12     'ignoreUnreadableDirs'
         19      > JMPZ                                                     ~12, ->25
  183    20    >   NEW                                              $13     'RecursiveArrayIterator'
         21        SEND_VAL_EX                                              <array>
         22        DO_FCALL                                      0          
         23      > RETURN                                                   $13
         24*       JMP                                                      ->35
  185    25    >   NEW                                              $15     'Symfony%5CComponent%5CFinder%5CException%5CAccessDeniedException'
         26        INIT_METHOD_CALL                                         !1, 'getMessage'
         27        DO_FCALL                                      0  $16     
         28        SEND_VAR_NO_REF_EX                                       $16
         29        INIT_METHOD_CALL                                         !1, 'getCode'
         30        DO_FCALL                                      0  $17     
         31        SEND_VAR_NO_REF_EX                                       $17
         32        SEND_VAR_EX                                              !1
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $15
  188    35*     > RETURN                                                   null

End of function getchildren

Function rewind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Lg65
function name:  rewind
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  195     0  E >   INIT_METHOD_CALL                                         'isRewindable'
          1        DO_FCALL                                      0  $0      
          2        TYPE_CHECK                                    4          $0
          3      > JMPZ                                                     ~1, ->5
  196     4    > > RETURN                                                   null
  200     5    >   INIT_STATIC_METHOD_CALL                                  'next'
          6        DO_FCALL                                      0          
  202     7        INIT_STATIC_METHOD_CALL                                  'rewind'
          8        DO_FCALL                                      0          
  203     9      > RETURN                                                   null

End of function rewind

Function isrewindable:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/8Lg65
function name:  isRewindable
number of ops:  31
compiled vars:  !0 = $stream, !1 = $infos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  212     0  E >   FETCH_OBJ_R                                      ~2      'rewindable'
          1        TYPE_CHECK                                  1020          ~2
          2      > JMPZ                                                     ~3, ->5
  213     3    >   FETCH_OBJ_R                                      ~4      'rewindable'
          4      > RETURN                                                   ~4
  216     5    >   BEGIN_SILENCE                                    ~5      
          6        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5CIterator%5Copendir'
          7        INIT_METHOD_CALL                                         'getPath'
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR_NO_REF_EX                                       $6
         10        DO_FCALL                                      0  $7      
         11        END_SILENCE                                              ~5
         12        ASSIGN                                           ~8      !0, $7
         13        TYPE_CHECK                                  1018          ~8
         14      > JMPZ                                                     ~9, ->27
  217    15    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5CIterator%5Cstream_get_meta_data'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !1, $10
  218    19        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CFinder%5CIterator%5Cclosedir'
         20        SEND_VAR_EX                                              !0
         21        DO_FCALL                                      0          
  220    22        FETCH_DIM_R                                      ~13     !1, 'seekable'
         23      > JMPZ                                                     ~13, ->27
  221    24    >   ASSIGN_OBJ                                       ~14     'rewindable'
         25        OP_DATA                                                  <true>
         26      > RETURN                                                   ~14
  225    27    >   ASSIGN_OBJ                                       ~15     'rewindable'
         28        OP_DATA                                                  <false>
         29      > RETURN                                                   ~15
  226    30*     > RETURN                                                   null

End of function isrewindable

End of class Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.07 ms | 1416 KiB | 29 Q