22
33define ( 'WP_CLI_ROOT ' , dirname ( dirname ( __FILE__ ) ) );
44
5- require WP_CLI_ROOT . '/vendor/autoload.php ' ;
5+ if ( file_exists ( WP_CLI_ROOT . '/vendor/autoload.php ' ) ) {
6+ define ( 'WP_CLI_BASE_PATH ' , WP_CLI_ROOT );
7+ define ( 'WP_CLI_VENDOR_DIR ' , WP_CLI_ROOT . '/vendor ' );
8+ } elseif ( file_exists ( dirname ( dirname ( WP_CLI_ROOT ) ) . '/autoload.php ' ) ) {
9+ define ( 'WP_CLI_BASE_PATH ' , dirname ( dirname ( dirname ( WP_CLI_ROOT ) ) ) );
10+ define ( 'WP_CLI_VENDOR_DIR ' , dirname ( dirname ( WP_CLI_ROOT ) ) );
11+ } else {
12+ echo 'Missing vendor/autoload.php ' ;
13+ exit (1 );
14+ }
15+ require WP_CLI_VENDOR_DIR . '/autoload.php ' ;
616require WP_CLI_ROOT . '/php/utils.php ' ;
717
818use Symfony \Component \Finder \Finder ;
3646}
3747
3848function add_file ( $ phar , $ path ) {
39- $ key = str_replace ( WP_CLI_ROOT , '' , $ path );
49+ $ key = str_replace ( WP_CLI_BASE_PATH , '' , $ path );
4050
4151 if ( !BE_QUIET )
4252 echo "$ key - $ path \n" ;
@@ -45,7 +55,7 @@ function add_file( $phar, $path ) {
4555}
4656
4757function set_file_contents ( $ phar , $ path , $ content ) {
48- $ key = str_replace ( WP_CLI_ROOT , '' , $ path );
58+ $ key = str_replace ( WP_CLI_BASE_PATH , '' , $ path );
4959
5060 if ( !BE_QUIET )
5161 echo "$ key - $ path \n" ;
@@ -65,17 +75,17 @@ function set_file_contents( $phar, $path, $content ) {
6575 ->name ('*.php ' )
6676 ->in (WP_CLI_ROOT . '/php ' )
6777 ->in (WP_CLI_ROOT . '/features ' )
68- ->in (WP_CLI_ROOT . '/vendor /wp-cli ' )
69- ->in (WP_CLI_ROOT . '/vendor /mustache ' )
70- ->in (WP_CLI_ROOT . '/vendor /rmccue/requests ' )
71- ->in (WP_CLI_ROOT . '/vendor /composer ' )
72- ->in (WP_CLI_ROOT . '/vendor /psr ' )
73- ->in (WP_CLI_ROOT . '/vendor /seld ' )
74- ->in (WP_CLI_ROOT . '/vendor /symfony ' )
75- ->in (WP_CLI_ROOT . '/vendor /nb/oxymel ' )
76- ->in (WP_CLI_ROOT . '/vendor /ramsey/array_column ' )
77- ->in (WP_CLI_ROOT . '/vendor /mustangostang ' )
78- ->in (WP_CLI_ROOT . '/vendor /justinrainbow/json-schema ' )
78+ ->in (WP_CLI_VENDOR_DIR . '/wp-cli ' )
79+ ->in (WP_CLI_VENDOR_DIR . '/mustache ' )
80+ ->in (WP_CLI_VENDOR_DIR . '/rmccue/requests ' )
81+ ->in (WP_CLI_VENDOR_DIR . '/composer ' )
82+ ->in (WP_CLI_VENDOR_DIR . '/psr ' )
83+ ->in (WP_CLI_VENDOR_DIR . '/seld ' )
84+ ->in (WP_CLI_VENDOR_DIR . '/symfony ' )
85+ ->in (WP_CLI_VENDOR_DIR . '/nb/oxymel ' )
86+ ->in (WP_CLI_VENDOR_DIR . '/ramsey/array_column ' )
87+ ->in (WP_CLI_VENDOR_DIR . '/mustangostang ' )
88+ ->in (WP_CLI_VENDOR_DIR . '/justinrainbow/json-schema ' )
7989 ->exclude ('test ' )
8090 ->exclude ('tests ' )
8191 ->exclude ('Test ' )
@@ -87,6 +97,27 @@ function set_file_contents( $phar, $path, $content ) {
8797 add_file ( $ phar , $ file );
8898}
8999
100+ // Include base project files, because the autoloader will load them
101+ if ( WP_CLI_BASE_PATH !== WP_CLI_ROOT ) {
102+ $ finder = new Finder ();
103+ $ finder
104+ ->files ()
105+ ->ignoreVCS (true )
106+ ->name ('*.php ' )
107+ ->in (WP_CLI_BASE_PATH . '/src ' )
108+ ->exclude ('test ' )
109+ ->exclude ('tests ' )
110+ ->exclude ('Test ' )
111+ ->exclude ('Tests ' );
112+ foreach ( $ finder as $ file ) {
113+ add_file ( $ phar , $ file );
114+ }
115+ // Any PHP files in the project root
116+ foreach ( glob ( WP_CLI_BASE_PATH . '/*.php ' ) as $ file ) {
117+ add_file ( $ phar , $ file );
118+ }
119+ }
120+
90121// other files
91122$ finder = new Finder ();
92123$ finder
@@ -100,20 +131,21 @@ function set_file_contents( $phar, $path, $content ) {
100131 add_file ( $ phar , $ file );
101132}
102133
103- add_file ( $ phar , WP_CLI_ROOT . '/vendor /autoload.php ' );
134+ add_file ( $ phar , WP_CLI_VENDOR_DIR . '/autoload.php ' );
104135add_file ( $ phar , WP_CLI_ROOT . '/ci/behat-tags.php ' );
105- add_file ( $ phar , WP_CLI_ROOT . '/vendor /composer/ca-bundle/res/cacert.pem ' );
106- add_file ( $ phar , WP_CLI_ROOT . '/vendor /composer/composer/LICENSE ' );
107- add_file ( $ phar , WP_CLI_ROOT . '/vendor /composer/composer/res/composer-schema.json ' );
108- add_file ( $ phar , WP_CLI_ROOT . '/vendor /rmccue/requests/library/Requests/Transport/cacert.pem ' );
136+ add_file ( $ phar , WP_CLI_VENDOR_DIR . '/composer/ca-bundle/res/cacert.pem ' );
137+ add_file ( $ phar , WP_CLI_VENDOR_DIR . '/composer/composer/LICENSE ' );
138+ add_file ( $ phar , WP_CLI_VENDOR_DIR . '/composer/composer/res/composer-schema.json ' );
139+ add_file ( $ phar , WP_CLI_VENDOR_DIR . '/rmccue/requests/library/Requests/Transport/cacert.pem ' );
109140
110141set_file_contents ( $ phar , WP_CLI_ROOT . '/VERSION ' , $ current_version );
111142
143+ $ phar_boot = str_replace ( WP_CLI_BASE_PATH , '' , WP_CLI_ROOT . '/php/boot-phar.php ' );
112144$ phar ->setStub ( <<<EOB
113145#!/usr/bin/env php
114146<?php
115147Phar::mapPhar();
116- include 'phar://wp-cli.phar/php/boot-phar.php ';
148+ include 'phar://wp-cli.phar/ { $ phar_boot } ';
117149__HALT_COMPILER();
118150?>
119151EOB
0 commit comments