Skip to content

Commit 11337e4

Browse files
committed
Runtime: More debug messages
1 parent 47dc387 commit 11337e4

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/Command/Compile.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ protected function initBuilder(string $main): self
9595
* @param string $directory The directory to scan for contents
9696
* @param ?string $extensions Filter on extension, may be "php" or "(php|phtml)"
9797
*
98+
* @return int The number of added files
9899
*/
99-
protected function addDirectory(string $directory, string $extensions = null)
100+
protected function addDirectory(string $directory, string $extensions = null): int
100101
{
101102
$filter = ($extensions) ? sprintf('/\.%s$/', $extensions) : '';
102103
$files = Directory::find($directory, $filter);
103104

104105
array_walk($files, function ($file) { $this->addFile($file); });
106+
107+
return count($files);
105108
}
106109

107110
/**
@@ -138,7 +141,9 @@ protected function addDirectories(array $dirs): self
138141
$wildcard = $extensions ? "*.$extensions" : 'all';
139142
$this->info("Scanning directory <strong>$directory</strong> for <strong>$wildcard</strong> files...");
140143

141-
$this->addDirectory($directory, $extensions);
144+
$count = $this->addDirectory($directory, $extensions);
145+
146+
$this->info("Added {$count} files.", 'grey');
142147
}
143148

144149
return $this;
@@ -212,8 +217,9 @@ protected function setNotice(string $banner = null): self
212217
*/
213218
protected function publish(string $output, bool $shebang, string $compression = 'GZ'): self
214219
{
215-
$this->info("Writing Phar archive to <strong>$output</strong>...");
216-
$this->builder->compile($output, $shebang, $compression);
220+
$this->info("Saving archive to <strong>$output</strong>...");
221+
$size = $this->builder->compile($output, $shebang, $compression);
222+
$this->info("{$size} bytes written.", 'grey');
217223

218224
return $this;
219225
}

src/PharBuilder.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ public function setBanner(string $banner): self
124124
* @param string $output Path to the final output file
125125
* @param bool $shebang Include a shebang directive line in the stub ?
126126
* @param string $compression Compression type - "GZ" or "BZ2" (defaults to "GZ")
127+
*
128+
* @return int The written file size in bytes
127129
*/
128-
public function compile(string $output, bool $shebang, string $compression = 'GZ')
130+
public function compile(string $output, bool $shebang, string $compression = 'GZ'): int
129131
{
130132
// Check that entrypoint script contents has been added to the archive before proceeding
131133
if (!$this->archive->has($this->main)) {
@@ -143,8 +145,12 @@ public function compile(string $output, bool $shebang, string $compression = 'GZ
143145
$this->archive->stopBuffering();
144146
// Make file executable
145147
chmod($this->pharname, 0755);
146-
//
148+
// Stat phar filesize
149+
$size = filesize($this->pharname);
150+
// Move temporary phar to final output
147151
rename($this->pharname, $output);
152+
153+
return $size;
148154
}
149155

150156
/**

0 commit comments

Comments
 (0)