note 125220 added to class.globiterator

From: Date: Tue, 28 Jul 2020 12:10:23 +0000
Subject: note 125220 added to class.globiterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-214902@lists.php.net to get a copy of this message
Fix problem with braces in template: <?php class GlobStreamWrapper { private $generator; protected function createGenerator(array $paths): Generator { return yield from $paths; } public function dir_opendir(string $pattern, int $options = 0): bool { $pattern = substr($pattern, 7); // crop 'glob://' prefix $pattern = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $pattern); $paths = (array) glob($pattern, GLOB_BRACE | GLOB_NOSORT); $this->generator = $this->createGenerator($paths); return $this->generator->valid(); } public function dir_readdir(): string { $path = $this->generator->current() ?: ''; $this->generator->next(); return $path; } public function dir_rewinddir(): bool { $this->generator->rewind(); return $this->generator->valid(); } public function dir_closedir(): bool { $this->generator = null; return true; } } ?> Replace glob wrapper: <?php stream_wrapper_unregister('glob'); stream_wrapper_register('glob', 'GlobStreamWrapper'); ?> Example: <?php $iterator = new GlobIterator(__DIR__ . '/{application,system}/src/*.php'); while ($iterator->valid()) { echo $iterator->current()->getFilename() . '</br>'; $iterator->next(); } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 103.51.166.36 (proxied: 31.129.215.166) ---- Manual Page -- http://php.net/manual/en/class.globiterator.php Edit -- https://master.php.net/note/edit/125220 Del: integrated -- https://master.php.net/note/delete/125220/integrated Del: useless -- https://master.php.net/note/delete/125220/useless Del: bad code -- https://master.php.net/note/delete/125220/bad+code Del: spam -- https://master.php.net/note/delete/125220/spam Del: non-english -- https://master.php.net/note/delete/125220/non-english Del: in docs -- https://master.php.net/note/delete/125220/in+docs Del: other reasons-- https://master.php.net/note/delete/125220 Reject -- https://master.php.net/note/reject/125220 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214902) next »