Skip to content

Commit

Permalink
Merge pull request #696 from google/fix/612-prefix-dependencies
Browse files Browse the repository at this point in the history
Use PHP-Scoper to prefix production dependencies in a third-party directory
  • Loading branch information
felixarntz authored Oct 24, 2019
2 parents 6d344ce + 3b71ce2 commit 5ffb36c
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 128 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
bower_components
/vendor
vendor
/third-party
release
composer.lock
phpunit.xml
Expand Down
17 changes: 6 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ branches:

# Before install, failures in this section will result in build status 'errored'
before_install:
- npm install || exit 1
- docker run --rm -v "$PWD:/app" composer install
- |
if [[ "$PHP" == "1" ]] || [[ "$JS" == "1" ]] || [[ "$SNIFF" == "1" ]]; then
npm install -g gulp-cli
fi
- |
if [[ "$WP_VERSION" == "latest" ]]; then
curl -s http://api.wordpress.org/core/version-check/1.7/ > /tmp/wp-latest.json
Expand All @@ -47,17 +53,6 @@ before_install:
if [[ "$PHP" == "1" ]]; then
git clone --depth=1 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress
cp /tmp/wordpress/wp-tests-config-sample.php /tmp/wordpress/tests/phpunit/wp-tests-config.php
fi
before_script:
- npm install || exit 1
- composer install
- |
if [[ "$PHP" == "1" ]] || [[ "$JS" == "1" ]] || [[ "$SNIFF" == "1" ]]; then
npm install -g gulp-cli
fi
- |
if [[ "$PHP" == "1" ]]; then
export WP_DEVELOP_DIR=/tmp/wordpress
export WP_TESTS_DIR=/tmp/wordpress/tests/phpunit
bash tests/bin/install-wp-tests.sh wordpress_test root '' localhost
Expand Down
15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@
}
},
"scripts": {
"post-install-cmd": [
"@prefix-dependencies"
],
"post-update-cmd": [
"@prefix-dependencies"
],
"prefix-dependencies": [
"rm -rf php-scoper && mkdir php-scoper",
"cd php-scoper && composer init -q && composer config minimum-stability dev && composer config prefer-stable true && composer require humbug/php-scoper",
"php-scoper/vendor/bin/php-scoper add --output-dir=./third-party --force",
"cd includes && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json",
"cd third-party && echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > composer.json && composer dump-autoload --classmap-authoritative --no-interaction && rm composer.json",
"cp vendor/composer/autoload_files.php third-party/vendor/composer/autoload_files.php",
"rm -rf php-scoper"
],
"lint": "vendor/bin/phpcs",
"lint-fix": "vendor/bin/phpcbf"
}
Expand Down
32 changes: 3 additions & 29 deletions gulp-tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,9 @@ gulp.task( 'copy', () => {
'dist/assets/**/*',
'bin/**/*',
'includes/**/*',
'vendor/google/apiclient/**/*',
'vendor/google/auth/**/*',
'vendor/google/apiclient-services/src/Google/Service/Analytics.php',
'vendor/google/apiclient-services/src/Google/Service/Analytics/**/*',
'vendor/google/apiclient-services/src/Google/Service/AnalyticsReporting.php',
'vendor/google/apiclient-services/src/Google/Service/AnalyticsReporting/**/*',
'vendor/google/apiclient-services/src/Google/Service/AdSense.php',
'vendor/google/apiclient-services/src/Google/Service/AdSense/**/*',
'vendor/google/apiclient-services/src/Google/Service/Pagespeedonline.php',
'vendor/google/apiclient-services/src/Google/Service/Pagespeedonline/**/*',
'vendor/google/apiclient-services/src/Google/Service/Webmasters.php',
'vendor/google/apiclient-services/src/Google/Service/Webmasters/**/*',
'vendor/google/apiclient-services/src/Google/Service/SiteVerification.php',
'vendor/google/apiclient-services/src/Google/Service/SiteVerification/**/*',
'vendor/google/apiclient-services/src/Google/Service/TagManager.php',
'vendor/google/apiclient-services/src/Google/Service/TagManager/**/*',
'vendor/google/apiclient-services/src/Google/Service/PeopleService.php',
'vendor/google/apiclient-services/src/Google/Service/PeopleService/**/*',
'vendor/firebase/**/*',
'vendor/guzzlehttp/**/*',
'vendor/psr/**/*',
'vendor/monolog/**/*',
'vendor/symfony/**/*',
'vendor/react/**/*',
'vendor/ralouphie/**/*',
'vendor/composer/*',
'vendor/autoload.php',
'!vendor/**/**/{tests,Tests,doc?(s),examples}/**/*',
'!vendor/**/**/{*.md,*.yml,phpunit.*}',
'third-party/**/*',
'!third-party/**/**/{tests,Tests,doc?(s),examples}/**/*',
'!third-party/**/**/{*.md,*.yml,phpunit.*}',
'!**/*.map',
'!bin/local-env/**/*',
'!bin/local-env/',
Expand Down
12 changes: 6 additions & 6 deletions includes/Core/Authentication/Clients/Google_Proxy_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace Google\Site_Kit\Core\Authentication\Clients;

use Google_Client;
use Google\Auth\OAuth2;
use Google\Auth\HttpHandler\HttpHandlerFactory;
use Google\Auth\HttpHandler\HttpClientCache;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Request;
use Google\Site_Kit_Dependencies\Google_Client;
use Google\Site_Kit_Dependencies\Google\Auth\OAuth2;
use Google\Site_Kit_Dependencies\Google\Auth\HttpHandler\HttpHandlerFactory;
use Google\Site_Kit_Dependencies\Google\Auth\HttpHandler\HttpClientCache;
use Google\Site_Kit_Dependencies\GuzzleHttp\Psr7;
use Google\Site_Kit_Dependencies\GuzzleHttp\Psr7\Request;
use Exception;
use InvalidArgumentException;
use LogicException;
Expand Down
2 changes: 1 addition & 1 deletion includes/Core/Authentication/Clients/OAuth_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Google\Site_Kit\Core\Authentication\Credentials;
use Google\Site_Kit\Core\Authentication\Verification;
use Google\Site_Kit\Modules\Search_Console;
use Google_Client;
use Google\Site_Kit_Dependencies\Google_Client;
use Exception;

/**
Expand Down
3 changes: 2 additions & 1 deletion includes/Core/Authentication/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Google\Site_Kit\Helpers;
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Core\Authentication\Clients\OAuth_Client;
use Google\Site_Kit_Dependencies\Google_Service_PeopleService;

/**
* Class controlling the user's Google profile.
Expand Down Expand Up @@ -125,7 +126,7 @@ private function retrieve_google_profile_from_api() {
// Retrieve and store the user's Google profile data.
try {
$client = $this->auth_client->get_client();
$people_service = new \Google_Service_PeopleService( $client );
$people_service = new Google_Service_PeopleService( $client );
$profile = $people_service->people->get( 'people/me', array( 'personFields' => 'emailAddresses,photos' ) );

if ( isset( $profile['emailAddresses'][0]['value'] ) && isset( $profile['photos'][0]['url'] ) ) {
Expand Down
10 changes: 5 additions & 5 deletions includes/Core/Modules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Core\Storage\Cache;
use Google\Site_Kit\Core\Authentication\Authentication;
use Google_Client;
use Google_Service;
use Google_Service_Exception;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Google\Site_Kit_Dependencies\Google_Client;
use Google\Site_Kit_Dependencies\Google_Service;
use Google\Site_Kit_Dependencies\Google_Service_Exception;
use Google\Site_Kit_Dependencies\Psr\Http\Message\RequestInterface;
use Google\Site_Kit_Dependencies\Psr\Http\Message\ResponseInterface;
use WP_Error;
use Exception;

Expand Down
3 changes: 2 additions & 1 deletion includes/Core/REST_API/REST_Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Google\Site_Kit\Core\Authentication\Authentication;
use Google\Site_Kit\Core\Authentication\Clients\OAuth_Client;
use Google\Site_Kit\Core\Util\Reset;
use Google\Site_Kit_Dependencies\Google_Collection;
use WP_Post;
use WP_REST_Server;
use WP_REST_Request;
Expand Down Expand Up @@ -672,7 +673,7 @@ private function parse_google_response_data( $data ) {
return $data;
}

// There is an compatibility issue with \Google_Collection object and wp_json_encode in PHP 5.4 only.
// There is an compatibility issue with Google_Collection object and wp_json_encode in PHP 5.4 only.
// These lines will encode/decode to deep convert objects, ensuring all data is returned.
if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) {
$data = json_decode( json_encode( $data ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
Expand Down
4 changes: 3 additions & 1 deletion includes/Core/Storage/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Google\Site_Kit\Core\Storage;

use Google\Site_Kit_Dependencies\Google_Service_Exception;

/**
* Class providing a server side caching framework.
*
Expand Down Expand Up @@ -122,7 +124,7 @@ public function cache_batch_results( $batch_requests, $results ) {
$request_keys = wp_list_pluck( $batch_requests, 'key' );

foreach ( $results as $key => $result ) {
if ( $result instanceof \Exception || $result instanceof \Google_Service_Exception ) {
if ( $result instanceof \Exception || $result instanceof Google_Service_Exception ) {
continue;
}
$key = str_replace( 'response-', '', $key );
Expand Down
12 changes: 7 additions & 5 deletions includes/Modules/AdSense.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Google\Site_Kit\Core\Modules\Module_With_Screen_Trait;
use Google\Site_Kit\Core\Modules\Module_With_Scopes;
use Google\Site_Kit\Core\Modules\Module_With_Scopes_Trait;
use Google_Client;
use Psr\Http\Message\RequestInterface;
use Google\Site_Kit_Dependencies\Google_Client;
use Google\Site_Kit_Dependencies\Google_Service_AdSense;
use Google\Site_Kit_Dependencies\Google_Service_AdSense_Alert;
use Google\Site_Kit_Dependencies\Psr\Http\Message\RequestInterface;
use WP_Error;

/**
Expand Down Expand Up @@ -488,7 +490,7 @@ protected function create_data_request( $method, $datapoint, array $data = array
}
$alerts = array_filter(
$alerts,
function( \Google_Service_AdSense_Alert $alert ) {
function( Google_Service_AdSense_Alert $alert ) {
return 'SEVERE' === $alert->getSeverity();
}
);
Expand All @@ -501,7 +503,7 @@ function( \Google_Service_AdSense_Alert $alert ) {
/**
* First Alert
*
* @var \Google_Service_AdSense_Alert $alert
* @var Google_Service_AdSense_Alert $alert
*/
$alert = array_shift( $alerts );
return array(
Expand Down Expand Up @@ -852,7 +854,7 @@ protected function setup_info() {
*/
protected function setup_services( Google_Client $client ) {
return array(
'adsense' => new \Google_Service_AdSense( $client ),
'adsense' => new Google_Service_AdSense( $client ),
);
}
}
Loading

0 comments on commit 5ffb36c

Please sign in to comment.