PHP 8.5.0 Alpha 4 available for testing

Voting

: max(zero, eight)?
(Example: nine)

The Note You're Voting On

cbonnissent
10 years ago
The code in the first exemple doesn't work properly without the flag FilesystemIterator::SKIP_DOTS in the RecursiveDirectoryIterator (on a linux filesystem).

So, to build a tar with a phar, I do (with two level of iteration here) :

$pharTar = new \PharData($contentTar.".tar");
$firstLevelIterator = new \DirectoryIterator($this->inputPath);
foreach ($firstLevelIterator as $fileInfo) {
/* @var \SplFileInfo $fileInfo */
if (in_array($fileInfo->getFilename(), $allowedDirectory)) {
$recursiveDirectoryIterator = new \RecursiveDirectoryIterator(
$this->inputPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename(), \FilesystemIterator::SKIP_DOTS);
$pharTar->buildFromIterator(new \RecursiveIteratorIterator($recursiveDirectoryIterator), $this->inputPath);
}
}

<< Back to user notes page

To Top