66 * file that was distributed with this source code.
77 */
88if (ini_get ('phar.readonly ' ) === '1 ' ) {
9- throw new \Exception ('Writing to phar files is disabled. Change your `php.ini` or append `-d phar.readonly=false` to the shebang, if supported by your `env` executable. ' );
9+ fwrite (STDERR , "Writing to phar files is disabled. Change your `php.ini` or use `-d phar.readonly=false`. \n" );
10+ exit (1 );
1011}
1112
1213define ('__ROOT__ ' , realpath (__DIR__ . '/.. ' ));
@@ -16,15 +17,15 @@ $opt = getopt('v:', ['nozip']);
1617
1718$ version = $ opt ['v ' ] ?? null ;
1819if (empty ($ version )) {
19- echo "Please, specify version as \"-v8.0.0 \". \n" ;
20+ fwrite ( STDERR , "Please, specify version as \"-v8.0.0 \". \n" ) ;
2021 exit (1 );
2122}
22- if (!preg_match ('/^\d+\.\d+\.\d+(\ -\w+(\.\d+)?)?$/ ' , $ version )) {
23- echo "Version must be \"7.0.0-beta.42 \". Got \"$ version \". \n" ;
23+ if (!preg_match ('/^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$/ ' , $ version )) {
24+ fwrite ( STDERR , "Version must be \"7.0.0-beta.42 \". Got \"$ version \". \n" ) ;
2425 exit (1 );
2526}
2627
27- echo ` set -x; composer install --no-dev --prefer-dist --optimize-autoloader` ;
28+ passthru ( ' composer install --no-dev --prefer-dist --optimize-autoloader ' ) ;
2829
2930$ pharName = "deployer.phar " ;
3031$ pharFile = __ROOT__ . '/ ' . $ pharName ;
@@ -41,58 +42,59 @@ $ignore = [
4142 '.php-cs-fixer.dist.php ' ,
4243];
4344
44- $ phar = new \Phar ($ pharFile , 0 , $ pharName );
45- $ phar ->setSignatureAlgorithm (\Phar::SHA1 );
45+ $ compress = !isset ($ opt ['nozip ' ]);
46+
47+ $ phar = new Phar ($ pharFile , 0 , $ pharName );
48+ $ phar ->setSignatureAlgorithm (Phar::SHA256 );
4649$ phar ->startBuffering ();
50+
4751$ iterator = new RecursiveDirectoryIterator (__ROOT__ , FilesystemIterator::SKIP_DOTS );
48- $ iterator = new RecursiveCallbackFilterIterator ($ iterator , function ( SplFileInfo $ fileInfo ) use ( $ ignore ) {
49- return !in_array ($ fileInfo ->getBasename (), $ ignore , true );
50- } );
52+ $ iterator = new RecursiveCallbackFilterIterator ($ iterator ,
53+ fn ( SplFileInfo $ fileInfo ) => !in_array ($ fileInfo ->getBasename (), $ ignore , true ),
54+ );
5155$ iterator = new RecursiveIteratorIterator ($ iterator );
52- $ iterator = new CallbackFilterIterator ($ iterator , function ( SplFileInfo $ fileInfo ) {
53- //'bash', 'fish', 'zsh' is a completion templates
54- return in_array ($ fileInfo ->getExtension (), ['php ' , 'exe ' , 'bash ' , 'fish ' , 'zsh ' ], true );
55- } );
56+ $ iterator = new CallbackFilterIterator ($ iterator ,
57+ // 'bash', 'fish', 'zsh' are completion templates
58+ fn ( SplFileInfo $ fileInfo ) => in_array ($ fileInfo ->getExtension (), ['php ' , 'exe ' , 'bash ' , 'fish ' , 'zsh ' ], true ),
59+ );
5660
5761foreach ($ iterator as $ fileInfo ) {
5862 $ file = str_replace (__ROOT__ , '' , $ fileInfo ->getRealPath ());
59- echo "+ " . $ file . " \n" ;
63+ echo "+ $ file \n" ;
6064 $ phar ->addFile ($ fileInfo ->getRealPath (), $ file );
6165
62- if (! array_key_exists ( ' nozip ' , $ opt ) ) {
66+ if ($ compress ) {
6367 $ phar [$ file ]->compress (Phar::GZ );
64-
6568 if (!$ phar [$ file ]->isCompressed ()) {
66- echo "Could not compress File : $ file \n" ;
69+ fwrite ( STDERR , "Could not compress: $ file \n" ) ;
6770 }
6871 }
6972}
7073
71- // Add Caddyfile
72- echo "+ /recipe/provision/Caddyfile \n" ;
73- $ phar ->addFile (realpath (__DIR__ . '/../recipe/provision/Caddyfile ' ), '/recipe/provision/Caddyfile ' );
74-
75- // Add 404.html
76- echo "+ /recipe/provision/404.html \n" ;
77- $ phar ->addFile (realpath (__DIR__ . '/../recipe/provision/404.html ' ), '/recipe/provision/404.html ' );
74+ // Add non-PHP files that the iterator skips.
75+ foreach ([
76+ '/recipe/provision/Caddyfile ' ,
77+ '/recipe/provision/404.html ' ,
78+ ] as $ extra ) {
79+ echo "+ $ extra \n" ;
80+ $ phar ->addFile (realpath (__ROOT__ . $ extra ), $ extra );
81+ }
7882
79- // Add bin/dep file
83+ // Add bin/dep with version baked in.
8084echo "+ /bin/dep \n" ;
8185$ depContent = file_get_contents (__ROOT__ . '/bin/dep ' );
8286$ depContent = str_replace ("#!/usr/bin/env php \n" , '' , $ depContent );
8387$ depContent = str_replace ('__FILE__ ' , 'str_replace("phar://", "", Phar::running()) ' , $ depContent );
8488$ depContent = preg_replace ("/run\('.+?'/ " , "run(' $ version' " , $ depContent );
8589$ phar ->addFromString ('bin/dep ' , $ depContent );
8690
87- $ phar ->setStub (
88- <<<STUB
89- #!/usr/bin/env php
90- <?php
91- Phar::mapPhar(' {$ pharName }');
92- require 'phar:// {$ pharName }/bin/dep';
93- __HALT_COMPILER();
94- STUB
95- );
91+ $ phar ->setStub (<<<STUB
92+ #!/usr/bin/env php
93+ <?php
94+ Phar::mapPhar(' {$ pharName }');
95+ require 'phar:// {$ pharName }/bin/dep';
96+ __HALT_COMPILER();
97+ STUB );
9698$ phar ->stopBuffering ();
9799unset($ phar );
98100
0 commit comments