Skip to content

Commit 2c35c38

Browse files
committed
fix: phar package build error, add test build on ci tests
1 parent 7611aba commit 2c35c38

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

.github/workflows/php.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ jobs:
5353
# Docs: https://getcomposer.org/doc/articles/scripts.md
5454

5555
- name: Run unit tests
56-
run: phpunit -v --debug
56+
run: |
57+
phpunit -v --debug
58+
59+
- name: Test build PHAR
60+
run: |
61+
php -d phar.readonly=0 examples/app phar pack -o=myapp.phar
62+
php myapp.phar -h

src/BuiltIn/PharController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class PharController extends Controller
3939
protected static string $description = 'Pack a project directory to phar or unpack phar to directory';
4040

4141
/**
42-
* @var Closure
42+
* @var Closure|null
4343
*/
44-
private Closure $compilerConfiger;
44+
private ?Closure $compilerConfiger = null;
4545

4646
/**
4747
* @var string

src/Component/PharCompiler.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use SplQueue;
2727
use Toolkit\FsUtil\File;
2828
use Toolkit\Sys\Sys;
29+
use Traversable;
2930
use UnexpectedValueException;
3031
use function array_merge;
3132
use function basename;
@@ -89,10 +90,12 @@ class PharCompiler
8990
private $key;
9091

9192
/** @var int */
92-
private int $signatureType;
93+
private int $signatureType = Phar::SHA256;
9394

9495
/**
95-
* @var int compress Mode @see \Phar::NONE, \Phar::GZ, \Phar::BZ2
96+
* compress Mode @see \Phar::NONE, \Phar::GZ, \Phar::BZ2
97+
*
98+
* @var int
9699
*/
97100
private int $compressMode = 0;
98101

@@ -154,9 +157,9 @@ class PharCompiler
154157
private array $events = [];
155158

156159
/**
157-
* @var Closure Maybe you not want strip all files.
160+
* @var Closure|null Maybe you not want strip all files.
158161
*/
159-
private Closure $stripFilter;
162+
private ?Closure $stripFilter = null;
160163

161164
/**
162165
* @var bool Whether strip comments
@@ -181,9 +184,9 @@ class PharCompiler
181184
private string $lastVersion = '';
182185

183186
/**
184-
* @var DateTime
187+
* @var DateTime|null
185188
*/
186-
private DateTime $versionDate;
189+
private ?DateTime $versionDate = null;
187190

188191
/**
189192
* 记录上面三个信息的文件, 相对于basePath
@@ -211,22 +214,23 @@ class PharCompiler
211214
/**
212215
* @var string Phar file path. e.g '/some/path/app.phar'
213216
*/
214-
private string $pharFile;
217+
private string $pharFile = '';
215218

216219
/**
217220
* @var string Phar file name. eg 'app.phar'
218221
*/
219-
private string $pharName;
222+
private string $pharName = '';
220223

221224
/**
222-
* @var Closure File filter
225+
* @var Closure|null File filter
223226
*/
224-
private Closure $fileFilter;
227+
private ?Closure $fileFilter = null;
225228

226229
/**
227-
* @var array|Iterator The modifies files list. if not empty, will skip find dirs.
230+
* The modifies files list. if not empty, will skip find dirs.
231+
* @var array|Traversable
228232
*/
229-
private array|Iterator $modifies;
233+
private array|Traversable $modifies;
230234

231235
/**
232236
* @var SplQueue
@@ -430,11 +434,11 @@ public function in(array|string $dirs): self
430434
}
431435

432436
/**
433-
* @param Iterator|array $modifies
437+
* @param Traversable|array $modifies
434438
*
435439
* @return PharCompiler
436440
*/
437-
public function setModifies(Iterator|array $modifies): self
441+
public function setModifies(Traversable|array $modifies): self
438442
{
439443
$this->modifies = $modifies;
440444
return $this;

0 commit comments

Comments
 (0)