Skip to content

Commit 4061a20

Browse files
committed
first pass at creating a Phar archive
1 parent e2fbdb2 commit 4061a20

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/vendor
55
/composer.lock
66
/phpunit.xml
7+
/wp-cli.phar

‎php/boot-phar.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
define( 'WP_CLI_ROOT', 'phar://wp-cli.phar/php/' );
4+
5+
include WP_CLI_ROOT . 'wp-cli.php';
6+

‎utils/make-phar.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
// php -dphar.readonly=0 utils/make-phar.php
4+
5+
$iterator = new \RecursiveIteratorIterator(
6+
new \RecursiveDirectoryIterator( './php', FilesystemIterator::SKIP_DOTS )
7+
);
8+
9+
$phar = new Phar( 'wp-cli.phar', 0, 'wp-cli.phar' );
10+
11+
$phar->startBuffering();
12+
13+
foreach ( $iterator as $path ) {
14+
if ( !preg_match( '/\.php$/', $path ) )
15+
continue;
16+
17+
$key = str_replace( './', '', $path );
18+
19+
echo "$key - $path\n";
20+
21+
$phar[ $key ] = file_get_contents( $path );
22+
}
23+
24+
$phar->setStub( <<<EOB
25+
<?php
26+
Phar::mapPhar();
27+
include 'phar://wp-cli.phar/php/boot-phar.php';
28+
__HALT_COMPILER();
29+
?>
30+
EOB
31+
);
32+
33+
$phar->stopBuffering();
34+
35+
echo "Generated wp-cli.phar.\n";
36+

0 commit comments

Comments
 (0)