From 97618d8fadec1ce31274fe9b5d70f921491abdae Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Mon, 21 Sep 2020 16:20:18 +0200 Subject: [PATCH] Reintroduce the League's Container package, and prefix it. All the classes in the package are re-namespaced from "Leage\Container" to "Automattic\WooCommerce\Vendor\League\Container" to prevent conflicts with extensions using the same plugin. The re-namespacing is done by using a simple text substitution on all the code files (see prefix-vendor-namespaces.sh), for this particular case this approach is enough. --- bin/output.sh | 16 ++++ bin/package-update.sh | 15 +--- bin/prefix-vendor-namespaces.sh | 8 ++ composer.json | 8 +- composer.lock | 129 ++++++++++++++++++++++++++++---- 5 files changed, 146 insertions(+), 30 deletions(-) create mode 100644 bin/output.sh create mode 100755 bin/prefix-vendor-namespaces.sh diff --git a/bin/output.sh b/bin/output.sh new file mode 100644 index 00000000000..a225de4164c --- /dev/null +++ b/bin/output.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Output colorized strings +# +# Color codes: +# 0 - black +# 1 - red +# 2 - green +# 3 - yellow +# 4 - blue +# 5 - magenta +# 6 - cian +# 7 - white +output() { + echo "$(tput setaf "$1")$2$(tput sgr0)" +} diff --git a/bin/package-update.sh b/bin/package-update.sh index f3bb1137f81..616d16ea330 100755 --- a/bin/package-update.sh +++ b/bin/package-update.sh @@ -1,19 +1,6 @@ #!/bin/sh -# Output colorized strings -# -# Color codes: -# 0 - black -# 1 - red -# 2 - green -# 3 - yellow -# 4 - blue -# 5 - magenta -# 6 - cian -# 7 - white -output() { - echo "$(tput setaf "$1")$2$(tput sgr0)" -} +. $(dirname "$0")/output.sh if [ ! -d "packages/" ]; then output 1 "./packages doesn't exist!" diff --git a/bin/prefix-vendor-namespaces.sh b/bin/prefix-vendor-namespaces.sh new file mode 100755 index 00000000000..8787aa33889 --- /dev/null +++ b/bin/prefix-vendor-namespaces.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +. $(dirname "$0")/output.sh + +output 6 "Prefixing the appropriate vendor namespaces with Automattic\WooCommerce\Vendor" + +find vendor/league/container -type f -name "*.php" -print0 | \ +xargs -0 sed -i '' -E -e 's/^[[:space:]]*(use|namespace)[[:space:]]*(League\\Container)/\1 Automattic\\WooCommerce\\Vendor\\\2/g' diff --git a/composer.json b/composer.json index cf764aa6345..40fea539063 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "psr/container": "1.0.0", "woocommerce/action-scheduler": "3.1.6", "woocommerce/woocommerce-admin": "1.6.0-rc.3", - "woocommerce/woocommerce-blocks": "3.4.0" + "woocommerce/woocommerce-blocks": "3.4.0", + "league/container": "3.3.1" }, "require-dev": { "phpunit/phpunit": "7.5.20", @@ -43,7 +44,8 @@ "includes/rest-api" ], "psr-4": { - "Automattic\\WooCommerce\\": "src/" + "Automattic\\WooCommerce\\": "src/", + "Automattic\\WooCommerce\\Vendor\\League\\Container\\": "vendor/league/container/" } }, "autoload-dev": { @@ -57,9 +59,11 @@ }, "scripts": { "post-install-cmd": [ + "sh ./bin/prefix-vendor-namespaces.sh", "sh ./bin/package-update.sh" ], "post-update-cmd": [ + "sh ./bin/prefix-vendor-namespaces.sh", "sh ./bin/package-update.sh" ], "test": [ diff --git a/composer.lock b/composer.lock index 25a47e73e88..b4b024f39eb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dcf828ebdcdcecfa605e7d3516f6e769", + "content-hash": "986b5e9610f1651459f114d9f534e431", "packages": [ { "name": "automattic/jetpack-autoloader", @@ -195,6 +195,78 @@ ], "time": "2019-08-12T15:00:31+00:00" }, + { + "name": "league/container", + "version": "3.3.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/container.git", + "reference": "93238f74ff5964aee27a78508cdfbdba1cd338f6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/container/zipball/93238f74ff5964aee27a78508cdfbdba1cd338f6", + "reference": "93238f74ff5964aee27a78508cdfbdba1cd338f6", + "shasum": "" + }, + "require": { + "php": "^7.0", + "psr/container": "^1.0" + }, + "provide": { + "psr/container-implementation": "^1.0" + }, + "replace": { + "orno/di": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-3.x": "3.x-dev", + "dev-2.x": "2.x-dev", + "dev-1.x": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Container\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Phil Bennett", + "email": "philipobenito@gmail.com", + "homepage": "http://www.philipobenito.com", + "role": "Developer" + } + ], + "description": "A fast and intuitive dependency injection container.", + "homepage": "https://github.com/thephpleague/container", + "keywords": [ + "container", + "dependency", + "di", + "injection", + "league", + "provider", + "service" + ], + "funding": [ + { + "url": "https://github.com/philipobenito", + "type": "github" + } + ], + "time": "2020-05-18T08:20:23+00:00" + }, { "name": "maxmind-db/reader", "version": "v1.6.0", @@ -429,6 +501,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-03-16T08:31:04+00:00" }, { @@ -875,8 +961,8 @@ }, "type": "library", "autoload": { - "psr-0": { - "Mustache": "src/" + "psr-4": { + "Mustache\\": "src/Mustache/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1778,8 +1864,8 @@ }, "type": "library", "autoload": { - "psr-0": { - "Requests": "library/" + "psr-4": { + "Requests\\": "library/Requests/" } }, "notification-url": "https://packagist.org/downloads/", @@ -2469,7 +2555,21 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2020-09-02T16:06:40+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-02-14T07:34:21+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2786,12 +2886,12 @@ }, "type": "library", "autoload": { - "psr-0": { - "cli": "lib/" - }, "files": [ "lib/cli/cli.php" - ] + ], + "psr-4": { + "cli\\": "lib/cli/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2863,9 +2963,9 @@ } }, "autoload": { - "psr-0": { - "WP_CLI": "php" - } + "classmap": [ + "php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2937,5 +3037,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.1" - } + }, + "plugin-api-version": "1.1.0" }