Skip to content

Commit c6dca35

Browse files
committed
ConsoleScript: fixed selective file compression not working
two problems affected this: - foreach on a phar built with buildFromIterator() does not work, necessitating creation of a new Phar object - we need a recursive iterator, otherwise the entries we see will be for the top-level directories and files only
1 parent 411fd5b commit c6dca35

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ConsoleScript.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,20 @@ function buildPhar(string $pharPath, string $basePath, array $includedPaths, arr
105105

106106
$count = count($phar->buildFromIterator($regexIterator, $basePath));
107107
yield "Added $count files";
108+
$phar->stopBuffering();
108109

109110
if($compression !== null){
110111
yield "Checking for compressible files...";
111-
foreach($phar as $file => $finfo){
112+
//foreach doesn't work properly when buildFromIterator was used, so we have to recreate the object
113+
$phar = new \Phar($pharPath);
114+
foreach(new \RecursiveIteratorIterator($phar) as $file => $finfo){
112115
/** @var \PharFileInfo $finfo */
113116
if($finfo->getSize() > (1024 * 512)){
114117
yield "Compressing " . $finfo->getFilename();
115118
$finfo->compress($compression);
116119
}
117120
}
118121
}
119-
$phar->stopBuffering();
120122

121123
yield "Done in " . round(microtime(true) - $start, 3) . "s";
122124
}

0 commit comments

Comments
 (0)