mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Rafactor remove Mozart isolation.
This commit is contained in:
parent
429232f60f
commit
939424a56a
152 changed files with 195 additions and 5400 deletions
|
@ -5,9 +5,9 @@
|
|||
* @package WooCommerce\PayPalCommerce
|
||||
*/
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Package;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties\PluginProperties;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Package;
|
||||
use Inpsyde\Modularity\Properties\PluginProperties;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return function (
|
||||
string $root_dir,
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"psr/container": "^1.0",
|
||||
"dhii/module-interface": "^0.2 || ^0.3",
|
||||
"container-interop/service-provider": "^0.4.0",
|
||||
"dhii/containers": "^0.1.0-alpha1",
|
||||
"woocommerce/woocommerce-sniffs": "^0.1.0",
|
||||
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
|
||||
"brain/monkey": "^2.4",
|
||||
|
@ -30,8 +27,7 @@
|
|||
"autoload": {
|
||||
"psr-4": {
|
||||
"WooCommerce\\PayPalCommerce\\": "src",
|
||||
"WooCommerce\\PayPalCommerce\\Common\\": "lib/common/",
|
||||
"WooCommerce\\PayPalCommerce\\Vendor\\": "lib/packages/"
|
||||
"WooCommerce\\PayPalCommerce\\Common\\": "lib/common/"
|
||||
},
|
||||
"files": [
|
||||
"api/order-functions.php"
|
||||
|
@ -69,19 +65,6 @@
|
|||
"pre-commit": [
|
||||
"vendor/bin/phpcbf"
|
||||
]
|
||||
},
|
||||
"mozart": {
|
||||
"dep_namespace": "WooCommerce\\PayPalCommerce\\Vendor\\",
|
||||
"dep_directory": "/lib/packages/",
|
||||
"classmap_directory": "/lib/classes/",
|
||||
"classmap_prefix": "PCPP_",
|
||||
"packages": [
|
||||
"psr/container",
|
||||
"dhii/containers",
|
||||
"dhii/module-interface",
|
||||
"inpsyde/modularity"
|
||||
],
|
||||
"delete_vendor_directories": true
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
|
145
composer.lock
generated
145
composer.lock
generated
|
@ -4,24 +4,24 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "5c45654af6d2f3addad4a089950e515f",
|
||||
"content-hash": "72adeb3f3018c694415c0d25b5deb0ec",
|
||||
"packages": [
|
||||
{
|
||||
"name": "container-interop/service-provider",
|
||||
"version": "v0.4.0",
|
||||
"version": "v0.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/container-interop/service-provider.git",
|
||||
"reference": "4969b9e49460690b7430b3f1a87cab07be61418a"
|
||||
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/4969b9e49460690b7430b3f1a87cab07be61418a",
|
||||
"reference": "4969b9e49460690b7430b3f1a87cab07be61418a",
|
||||
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/e04441ca21ef03e10dce70b0af29269281eec6dc",
|
||||
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"psr/container": "^1.0"
|
||||
"psr/container": "^1.0 || ^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -37,9 +37,9 @@
|
|||
"homepage": "https://github.com/container-interop/service-provider",
|
||||
"support": {
|
||||
"issues": "https://github.com/container-interop/service-provider/issues",
|
||||
"source": "https://github.com/container-interop/service-provider/tree/master"
|
||||
"source": "https://github.com/container-interop/service-provider/tree/v0.4.1"
|
||||
},
|
||||
"time": "2017-09-20T14:13:36+00:00"
|
||||
"time": "2023-12-14T14:50:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dhii/human-readable-interface",
|
||||
|
@ -364,20 +364,20 @@
|
|||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/container.git",
|
||||
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf"
|
||||
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf",
|
||||
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf",
|
||||
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
|
||||
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.0"
|
||||
"php": ">=7.4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -406,9 +406,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-fig/container/issues",
|
||||
"source": "https://github.com/php-fig/container/tree/1.1.1"
|
||||
"source": "https://github.com/php-fig/container/tree/1.1.2"
|
||||
},
|
||||
"time": "2021-03-05T17:36:06+00:00"
|
||||
"time": "2021-11-05T16:50:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
|
@ -1347,121 +1347,6 @@
|
|||
},
|
||||
"time": "2022-02-04T12:51:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dhii/collections-interface",
|
||||
"version": "v0.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Dhii/collections-interface.git",
|
||||
"reference": "74464a969b340d16889eacd9eadc9817f7e7f47a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Dhii/collections-interface/zipball/74464a969b340d16889eacd9eadc9817f7e7f47a",
|
||||
"reference": "74464a969b340d16889eacd9eadc9817f7e7f47a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1 | ^8.0",
|
||||
"psr/container": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
|
||||
"slevomat/coding-standard": "^6.0",
|
||||
"vimeo/psalm": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-develop": "0.3.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dhii\\Collection\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Dhii Team",
|
||||
"email": "development@dhii.co"
|
||||
},
|
||||
{
|
||||
"name": "Anton Ukhanev",
|
||||
"email": "xedin.unknown@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A highly ISP-compliant collection of interfaces that represent maps and lists.",
|
||||
"support": {
|
||||
"issues": "https://github.com/Dhii/collections-interface/issues",
|
||||
"source": "https://github.com/Dhii/collections-interface/tree/v0.3.0"
|
||||
},
|
||||
"time": "2021-10-06T10:56:09+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dhii/containers",
|
||||
"version": "v0.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Dhii/containers.git",
|
||||
"reference": "42ab24683183fa0dc155f26c6a470ef697bbdc9a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Dhii/containers/zipball/42ab24683183fa0dc155f26c6a470ef697bbdc9a",
|
||||
"reference": "42ab24683183fa0dc155f26c6a470ef697bbdc9a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"container-interop/service-provider": "^0.4",
|
||||
"dhii/collections-interface": "^0.3.0-alpha4",
|
||||
"php": "^7.1 | ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"gmazzap/andrew": "^1.1",
|
||||
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
|
||||
"psr/container": "^1.0",
|
||||
"psr/simple-cache": "^1.0",
|
||||
"slevomat/coding-standard": "^6.0",
|
||||
"vimeo/psalm": "^4.0",
|
||||
"wildwolf/psr-memory-cache": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-develop": "0.1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dhii\\Container\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Dhii Team",
|
||||
"email": "development@dhii.co"
|
||||
}
|
||||
],
|
||||
"description": "A selection of PSR-11 containers for utility, simplicity, and ease.",
|
||||
"keywords": [
|
||||
"PSR-11",
|
||||
"container"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Dhii/containers/issues",
|
||||
"source": "https://github.com/Dhii/containers/tree/v0.1.4"
|
||||
},
|
||||
"time": "2021-10-06T11:13:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dnoegel/php-xdg-base-dir",
|
||||
"version": "v0.1.1",
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
interface ClearableContainerInterface extends PsrContainerInterface
|
||||
{
|
||||
/**
|
||||
* Removes all members from this container.
|
||||
*
|
||||
* @psalm-suppress InvalidThrow In PSR-11, this interface does not extend `Throwable`.
|
||||
* @throws ContainerExceptionInterface If problem removing.
|
||||
*/
|
||||
public function clear(): void;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Creates containers based on data maps.
|
||||
*/
|
||||
interface ContainerFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates a container based on data.
|
||||
*
|
||||
* @param array<string, mixed> $data The data for the container.
|
||||
*
|
||||
* @return ContainerInterface The new container.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function createContainerFromArray(array $data): ContainerInterface;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as BaseContainerInterface;
|
||||
|
||||
/**
|
||||
* Something that can retrieve and determine the existence of a value by key.
|
||||
*/
|
||||
interface ContainerInterface extends
|
||||
HasCapableInterface,
|
||||
BaseContainerInterface
|
||||
{
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Traversable;
|
||||
use Countable;
|
||||
|
||||
/**
|
||||
* A list that can be counted.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface CountableListInterface extends
|
||||
/* @since 0.2 */
|
||||
Traversable,
|
||||
/* @since 0.2 */
|
||||
Countable
|
||||
{
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
/**
|
||||
* A countable map.
|
||||
*
|
||||
* @since 0.2
|
||||
*
|
||||
* @psalm-suppress UnusedClass
|
||||
*/
|
||||
interface CountableMapInterface extends
|
||||
/* @since 0.2 */
|
||||
CountableListInterface,
|
||||
/* @since 0.2 */
|
||||
MapInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
/**
|
||||
* A countable list that can be checked for a key.
|
||||
*
|
||||
* @since 0.2
|
||||
*
|
||||
* @psalm-suppress UnusedClass
|
||||
*/
|
||||
interface CountableSetInterface extends
|
||||
/* @since 0.2 */
|
||||
CountableListInterface,
|
||||
/* @since 0.2 */
|
||||
SetInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
|
||||
/**
|
||||
* Something that can determine the existence of a key.
|
||||
*/
|
||||
interface HasCapableInterface
|
||||
{
|
||||
/**
|
||||
* Determines whether this instance has the specified key.
|
||||
*
|
||||
* @param string $key The key to check for.
|
||||
*
|
||||
* @return bool True if the key exists; false otherwise.
|
||||
*
|
||||
* @throws ContainerExceptionInterface If problem determining.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
* @psalm-suppress InvalidThrow
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
|
||||
*/
|
||||
public function has($key);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Something that can check for the existence of an item.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface HasItemCapableInterface
|
||||
{
|
||||
/**
|
||||
* Checks whether this instance has the given item.
|
||||
*
|
||||
* @since 0.2
|
||||
*
|
||||
* @param mixed $item The item to check for.
|
||||
*
|
||||
* @return bool True if the item exists; false otherwise.
|
||||
*
|
||||
* @throws RuntimeException If the existence of the item could not be verified.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function hasItem($item): bool;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as BaseContainerInterface;
|
||||
|
||||
/**
|
||||
* A factory that can create maps.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface MapFactoryInterface extends ContainerFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates a map based on data in an array.
|
||||
*
|
||||
* @param array<string, mixed> $data The data to base the map on.
|
||||
*
|
||||
* @return MapInterface The new map.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*/
|
||||
public function createContainerFromArray(array $data): BaseContainerInterface;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* A traversable container.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface MapInterface extends
|
||||
/* @since 0.2 */
|
||||
Traversable,
|
||||
/* @since 0.2 */
|
||||
ContainerInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* A container that can have mappings added and removed.
|
||||
*
|
||||
* @psalm-suppress UnusedClass
|
||||
*/
|
||||
interface MutableContainerInterface extends ContainerInterface
|
||||
{
|
||||
/**
|
||||
* Maps the given value to the specified key.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The key to map the value to.
|
||||
* @param mixed $value The value to map to the key.
|
||||
*
|
||||
* @throws ContainerExceptionInterface If problem mapping.
|
||||
* @psalm-suppress InvalidThrow
|
||||
*/
|
||||
public function set(string $key, $value): void;
|
||||
|
||||
/**
|
||||
* Unmaps the value from the specified key.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The key to unmap the value from.
|
||||
*
|
||||
* @throws NotFoundExceptionInterface If key not found.
|
||||
* @throws ContainerExceptionInterface If problem unmapping.
|
||||
* @psalm-suppress InvalidThrow
|
||||
*/
|
||||
public function unset(string $key): void;
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* A factory that can create sets.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
interface SetFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates a set based on data in a list.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param array<mixed> $list The list to base the set on.
|
||||
*
|
||||
* @return SetInterface The new set.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function createSetFromList(array $list): SetInterface;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* A list that can be checked for a key.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface SetInterface extends
|
||||
/* @since 0.2 */
|
||||
Traversable,
|
||||
/* @since 0.2 */
|
||||
HasItemCapableInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* A map that can create a writable container.
|
||||
*/
|
||||
interface WritableContainerFactoryInterface extends ContainerFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return WritableContainerInterface The new container.
|
||||
*/
|
||||
public function createContainerFromArray(array $data): ContainerInterface;
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* A container that can be written to.
|
||||
*/
|
||||
interface WritableContainerInterface extends ContainerInterface
|
||||
{
|
||||
/**
|
||||
* Creates a new instance with the specified mappings.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param array<string, mixed> $mappings A map of keys to values.
|
||||
*
|
||||
* @return static A new instance of this class with only the specified key-value mappings.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function withMappings(array $mappings): WritableContainerInterface;
|
||||
|
||||
/**
|
||||
* Creates a new instance with the specified mappings added to existing ones.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param array<string, mixed> $mappings A map of keys to values.
|
||||
*
|
||||
* @return static A new instance of this class with the specified key-value mappings added to existing ones.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function withAddedMappings(array $mappings): WritableContainerInterface;
|
||||
|
||||
/**
|
||||
* Creates a new instance with the specified keys not present.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param array<string> $keys The keys to exclude.
|
||||
*
|
||||
* @return static A new instance of this class which does not contain the specified keys.
|
||||
*
|
||||
* @throws Exception If problem instantiating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function withoutKeys(array $keys): WritableContainerInterface;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as BaseContainerInterface;
|
||||
|
||||
/**
|
||||
* Creates writable maps.
|
||||
*
|
||||
* @psalm-suppress UnusedClass
|
||||
*/
|
||||
interface WritableMapFactoryInterface extends WritableContainerFactoryInterface, MapFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return WritableMapInterface The new map.
|
||||
*/
|
||||
public function createContainerFromArray(array $data): BaseContainerInterface;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
/**
|
||||
* A map that can have a value set for a key.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
interface WritableMapInterface extends MapInterface, WritableContainerInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
/**
|
||||
* Creates writable sets.
|
||||
*
|
||||
* @psalm-suppress UnusedClass
|
||||
*/
|
||||
interface WritableSetFactoryInterface extends SetFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @return WritableSetInterface The new writable set.
|
||||
*/
|
||||
public function createSetFromList(array $list): SetInterface;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Collection;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* A set that can have items added.
|
||||
*
|
||||
* @psalm-suppress UnusedClass
|
||||
*/
|
||||
interface WritableSetInterface extends SetInterface
|
||||
{
|
||||
/**
|
||||
* Creates a new instance with the given items only.
|
||||
*
|
||||
* @param array|mixed[] $items A list of items for the set.
|
||||
*
|
||||
* @return static A new instance of this class with only the given items.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function withItems(array $items);
|
||||
|
||||
/**
|
||||
* Creates a new instance with the given items added to existing ones.
|
||||
*
|
||||
* @param array|mixed[] $items A list of items to add.
|
||||
*
|
||||
* @return static A new instance of this class with the given items added to existing ones.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function withAddedItems(array $items): WritableSetInterface;
|
||||
|
||||
/**
|
||||
* Creates a new instance with the given items not present.
|
||||
*
|
||||
* @param array|mixed[] $items A list of items to exclude.
|
||||
*
|
||||
* @return static An instance of this class without the given items.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedMethod
|
||||
*/
|
||||
public function withoutItems(array $items): WritableSetInterface;
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* A container implementation that wraps around an inner container to alias its keys, so consumers can use the aliases
|
||||
* to fetch data from the inner container.
|
||||
*/
|
||||
class AliasingContainer implements ContainerInterface
|
||||
{
|
||||
/* @since [*next-version*] */
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var array<array-key, string>
|
||||
*/
|
||||
protected $aliases;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $inner The container whose keys to alias.
|
||||
* @param array<array-key, string> $aliases A mapping of aliases to their original container key counterparts.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $inner, array $aliases)
|
||||
{
|
||||
$this->inner = $inner;
|
||||
$this->aliases = $aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return $this->inner->get($this->getInnerKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return $this->inner->has($this->getInnerKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the key to use for the inner container.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The outer key.
|
||||
*
|
||||
* @return string The inner key.
|
||||
*/
|
||||
protected function getInnerKey(string $key): string
|
||||
{
|
||||
if (array_key_exists($key, $this->aliases)) {
|
||||
return $this->aliases[$key];
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* Caches entries from an internal container.
|
||||
*
|
||||
* @package Dhii\Container1
|
||||
*/
|
||||
class CachingContainer implements ContainerInterface
|
||||
{
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/** @var array<array-key, mixed> */
|
||||
protected $cache;
|
||||
|
||||
/** @var PsrContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @param PsrContainerInterface $container The container to cache entries from.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->cache = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
/** @psalm-suppress RedundantCastGivenDocblockType
|
||||
* @psalm-suppress RedundantCast
|
||||
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
|
||||
*/
|
||||
$key = (string) $key;
|
||||
|
||||
/**
|
||||
* @psalm-suppress InvalidCatch
|
||||
* The base interface does not extend Throwable, but in fact everything that is possible
|
||||
* in theory to catch will be Throwable, and PSR-11 exceptions will implement this interface
|
||||
*/
|
||||
try {
|
||||
/**
|
||||
* @psalm-suppress MissingClosureReturnType
|
||||
* Unable to specify mixed before PHP 8.
|
||||
*/
|
||||
$value = $this->getCached($key, function () use ($key) {
|
||||
return $this->container->get($key);
|
||||
});
|
||||
} catch (NotFoundExceptionInterface $e) {
|
||||
throw new NotFoundException($this->__('Key "%1$s" not found in inner container', [$key]), 0, $e);
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(
|
||||
$this->__('Could not retrieve value for key "%1$s from inner container', [$key]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
/** @psalm-suppress RedundantCastGivenDocblockType
|
||||
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
|
||||
*/
|
||||
$key = (string) $key;
|
||||
|
||||
/**
|
||||
* @psalm-suppress InvalidCatch
|
||||
* The base interface does not extend Throwable, but in fact everything that is possible
|
||||
* in theory to catch will be Throwable, and PSR-11 exceptions will implement this interface
|
||||
*/
|
||||
try {
|
||||
if ($this->hasCached($key)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException($this->__('Could not check cache for key "%1$s"', [$key]), 0, $e);
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->container->has($key)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(
|
||||
$this->__('Could not check inner container for key "%1$s"', [$key]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value by key from cache, creating it if it does not exist.
|
||||
*
|
||||
* @param string $key The key to get.
|
||||
* @param callable $generator Creates the value.
|
||||
*
|
||||
* @return mixed The cached value.
|
||||
*
|
||||
* @throws Exception If problem caching.
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
|
||||
*/
|
||||
protected function getCached(string $key, callable $generator)
|
||||
{
|
||||
if (!array_key_exists($key, $this->cache)) {
|
||||
$value = $this->invokeGenerator($generator);
|
||||
$this->cache[$key] = $value;
|
||||
}
|
||||
|
||||
return $this->cache[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the cache for the specified key.
|
||||
*
|
||||
* @param string $key The key to check for.
|
||||
*
|
||||
* @return bool True if cache contains the value; false otherwise.
|
||||
*
|
||||
* @throws Exception If problem checking.
|
||||
*/
|
||||
protected function hasCached(string $key): bool
|
||||
{
|
||||
return array_key_exists($key, $this->cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a value by invoking the generator.
|
||||
*
|
||||
* @param callable $generator Generates a value.
|
||||
*
|
||||
* @return mixed The generated result.
|
||||
*
|
||||
* @throws Exception If problem generating.
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
|
||||
*/
|
||||
protected function invokeGenerator(callable $generator)
|
||||
{
|
||||
$result = $generator();
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
/**
|
||||
* A service provider that aggregates service definitions from other providers.
|
||||
*/
|
||||
class CompositeCachingServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var iterable<ServiceProviderInterface>
|
||||
*/
|
||||
protected $providers;
|
||||
|
||||
/**
|
||||
* @var ?iterable<callable>
|
||||
*/
|
||||
protected $factories;
|
||||
|
||||
/**
|
||||
* @var ?iterable<callable>
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @param iterable<ServiceProviderInterface> $providers
|
||||
*/
|
||||
public function __construct(iterable $providers)
|
||||
{
|
||||
$this->providers = $providers;
|
||||
$this->factories = null;
|
||||
$this->extensions = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @psalm-suppress InvalidNullableReturnType
|
||||
* It isn't actually going to return null ever, because $factories will be filled during indexing.
|
||||
*/
|
||||
public function getFactories()
|
||||
{
|
||||
if (!is_array($this->factories)) {
|
||||
$this->indexProviderDefinitions($this->providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress NullableReturnStatement
|
||||
* Not going to be null because will be populated by indexing
|
||||
*/
|
||||
return $this->factories;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @psalm-suppress InvalidNullableReturnType
|
||||
* It isn't actually going to return null ever, because $factories will be filled during indexing.
|
||||
*/
|
||||
public function getExtensions()
|
||||
{
|
||||
if (!is_array($this->extensions)) {
|
||||
$this->indexProviderDefinitions($this->providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress NullableReturnStatement
|
||||
* Not going to be null because will be populated by indexing
|
||||
*/
|
||||
return $this->extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes definitions in the specified service providers.
|
||||
*
|
||||
* Caches them internally.
|
||||
*
|
||||
* @param iterable|ServiceProviderInterface[] $providers The providers to index.
|
||||
*/
|
||||
protected function indexProviderDefinitions(iterable $providers): void
|
||||
{
|
||||
$factories = [];
|
||||
$extensions = [];
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
$factories = $this->mergeFactories($factories, $provider->getFactories());
|
||||
$extensions = $this->mergeExtensions($extensions, $provider->getExtensions());
|
||||
}
|
||||
|
||||
$this->factories = $factories;
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two maps of factories.
|
||||
*
|
||||
* @param callable[] $defaults The factory map to merge into.
|
||||
* @param callable[] $definitions The factory map to merge. Values from here will override defaults.
|
||||
*
|
||||
* @return callable[] The merged factories.
|
||||
*/
|
||||
protected function mergeFactories(array $defaults, array $definitions): array
|
||||
{
|
||||
return array_merge($defaults, $definitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merged service extensions.
|
||||
*
|
||||
* @param callable[] $defaults
|
||||
* @param iterable<callable> $extensions
|
||||
*
|
||||
* @return callable[] The merged extensions.
|
||||
*/
|
||||
protected function mergeExtensions(array $defaults, iterable $extensions): array
|
||||
{
|
||||
$merged = [];
|
||||
|
||||
foreach ($extensions as $key => $extension) {
|
||||
if (isset($defaults[$key])) {
|
||||
$default = $defaults[$key];
|
||||
/**
|
||||
* @psalm-suppress MissingClosureReturnType
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
* Unable to specify mixed before PHP 8.
|
||||
*/
|
||||
$merged[$key] = function (PsrContainerInterface $c, $previous = null) use ($default, $extension) {
|
||||
$result = $default($c, $previous);
|
||||
$result = $extension($c, $result);
|
||||
|
||||
return $result;
|
||||
};
|
||||
|
||||
unset($defaults[$key]);
|
||||
} else {
|
||||
$merged[$key] = $extension;
|
||||
}
|
||||
}
|
||||
|
||||
$merged = $this->mergeFactories($defaults, $merged);
|
||||
|
||||
return $merged;
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
use Traversable;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class CompositeContainer implements ContainerInterface
|
||||
{
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/**
|
||||
* @var iterable<PsrContainerInterface>
|
||||
*/
|
||||
protected $containers;
|
||||
|
||||
/**
|
||||
* @param iterable<PsrContainerInterface> $containers The list of containers.
|
||||
*/
|
||||
public function __construct(iterable $containers)
|
||||
{
|
||||
$this->containers = $containers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
/** @psalm-suppress RedundantCastGivenDocblockType
|
||||
* @psalm-suppress RedundantCast
|
||||
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
|
||||
*/
|
||||
$key = (string) $key;
|
||||
|
||||
foreach ($this->containers as $index => $container) {
|
||||
/**
|
||||
* @psalm-suppress InvalidCatch
|
||||
* The base interface does not extend Throwable, but in fact everything that is possible
|
||||
* in theory to catch will be Throwable, and PSR-11 exceptions will implement this interface
|
||||
*/
|
||||
try {
|
||||
if ($container->has($key)) {
|
||||
return $container->get($key);
|
||||
}
|
||||
} catch (NotFoundExceptionInterface $e) {
|
||||
throw new NotFoundException(
|
||||
$this->__('Failed to retrieve value for key "%1$s" from container at index "%2$s"', [$key, $index]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(
|
||||
$this->__('Failed check for key "%1$s" on container at index "%2$s"', [$key, $index]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundException(
|
||||
$this->__('Key "%1$s" not found in any of the containers', [$key]),
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
/** @psalm-suppress RedundantCastGivenDocblockType
|
||||
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
|
||||
*/
|
||||
$key = (string) $key;
|
||||
|
||||
foreach ($this->containers as $index => $container) {
|
||||
try {
|
||||
if ($container->has($key)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(
|
||||
$this->__('Failed check for key "%1$s" on container at index "%2$s"', [$key, $index]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapFactoryInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
class DataStructureBasedFactory implements DataStructureBasedFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @var WritableMapFactoryInterface
|
||||
*/
|
||||
protected $containerFactory;
|
||||
public function __construct(WritableMapFactoryInterface $containerFactory)
|
||||
{
|
||||
$this->containerFactory = $containerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createContainerFromArray(array $structure): ContainerInterface
|
||||
{
|
||||
$map = [];
|
||||
foreach ($structure as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
$value = get_object_vars($value);
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $this->createContainerFromArray($value);
|
||||
}
|
||||
|
||||
$map[$key] = $value;
|
||||
}
|
||||
|
||||
$container = $this->containerFactory->createContainerFromArray($map);
|
||||
return $container;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapFactoryInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapInterface;
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as BaseContainerInterface;
|
||||
|
||||
/**
|
||||
* Creates a container hierarchy based on a traditional data structure.
|
||||
*/
|
||||
interface DataStructureBasedFactoryInterface extends WritableMapFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Based on a traditional data structure, creates a container hierarchy.
|
||||
*
|
||||
* @param mixed[] $structure The traditional data structure representation.
|
||||
*
|
||||
* @return WritableMapInterface A hierarchy of writable maps that reflects the data structure.
|
||||
*
|
||||
* @throws Exception If problem creating.
|
||||
*/
|
||||
public function createContainerFromArray(array $structure): BaseContainerInterface;
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class DelegatingContainer implements ContainerInterface
|
||||
{
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/**
|
||||
* @var ServiceProviderInterface
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* @var PsrContainerInterface|null
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
*/
|
||||
public function __construct(ServiceProviderInterface $provider, PsrContainerInterface $parent = null)
|
||||
{
|
||||
$this->provider = $provider;
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$provider = $this->provider;
|
||||
$services = $provider->getFactories();
|
||||
|
||||
if (!array_key_exists($id, $services)) {
|
||||
throw new NotFoundException(
|
||||
$this->__('Service not found for key "%1$s"', [$id]),
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
$service = $services[$id];
|
||||
|
||||
try {
|
||||
$service = $this->invokeFactory($service);
|
||||
} catch (UnexpectedValueException $e) {
|
||||
throw new ContainerException(
|
||||
$this->__('Could not create service "%1$s"', [$id]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
$extensions = $provider->getExtensions();
|
||||
|
||||
if (!array_key_exists($id, $extensions)) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
$extension = $extensions[$id];
|
||||
|
||||
try {
|
||||
$service = $this->invokeExtension($extension, $service);
|
||||
} catch (UnexpectedValueException $e) {
|
||||
throw new ContainerException(
|
||||
$this->__('Could not extend service "%1$s"', [$id]),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function has($id)
|
||||
{
|
||||
$services = $this->provider->getFactories();
|
||||
|
||||
return array_key_exists($id, $services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a service by invoking its factory.
|
||||
*
|
||||
* @param callable $factory The factory to invoke.
|
||||
*
|
||||
* @return mixed The service created by the factory.
|
||||
*
|
||||
* @throws UnexpectedValueException If factory could not be invoked.
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
|
||||
*/
|
||||
protected function invokeFactory(callable $factory)
|
||||
{
|
||||
if (!is_callable($factory)) {
|
||||
throw new UnexpectedValueException(
|
||||
$this->__('Factory could not be invoked'),
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
$baseContainer = $this->getBaseContainer();
|
||||
$service = $factory($baseContainer);
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends the service by invoking the extension with it.
|
||||
*
|
||||
* @param callable $extension The extension to invoke.
|
||||
* @param mixed $service The service to extend.
|
||||
*
|
||||
* @return mixed The extended service.
|
||||
*
|
||||
* @throws UnexpectedValueException If extension cannot be invoked.
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
|
||||
*/
|
||||
protected function invokeExtension(callable $extension, $service)
|
||||
{
|
||||
if (!is_callable($extension)) {
|
||||
throw new UnexpectedValueException(
|
||||
$this->__('Factory could not be invoked'),
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
$baseContainer = $this->getBaseContainer();
|
||||
$service = $extension($baseContainer, $service);
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the container to be used for definitions and extensions.
|
||||
*
|
||||
* @return PsrContainerInterface The parent container, if set. Otherwise, this instance.
|
||||
*/
|
||||
protected function getBaseContainer(): PsrContainerInterface
|
||||
{
|
||||
return $this->parent instanceof PsrContainerInterface
|
||||
? $this->parent
|
||||
: $this;
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* A container implementation that wraps around an inner container to automatically add prefixes to keys during
|
||||
* fetching and look up, allowing consumers to omit them.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class DeprefixingContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $strict;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $container The container whose keys to deprefix.
|
||||
* @param string $prefix The prefix to remove from the container's keys.
|
||||
* @param bool $strict Whether or not to fallback to prefixed keys if an un-prefixed key does
|
||||
* not exist in the inner container.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $container, string $prefix, bool $strict = true)
|
||||
{
|
||||
$this->inner = $container;
|
||||
$this->prefix = $prefix;
|
||||
$this->strict = $strict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
/**
|
||||
* @psalm-suppress InvalidCatch
|
||||
* The base interface does not extend Throwable, but in fact everything that is possible
|
||||
* in theory to catch will be Throwable, and PSR-11 exceptions will implement this interface
|
||||
*/
|
||||
try {
|
||||
return $this->inner->get($this->getInnerKey($key));
|
||||
} catch (NotFoundExceptionInterface $nfException) {
|
||||
if ($this->strict || !$this->inner->has($key)) {
|
||||
throw $nfException;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->inner->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return $this->inner->has($this->getInnerKey($key)) || (!$this->strict && $this->inner->has($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the key to use for the inner container.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The outer key.
|
||||
*
|
||||
* @return string The inner key.
|
||||
*/
|
||||
protected function getInnerKey(string $key): string
|
||||
{
|
||||
return $this->prefix . $key;
|
||||
}
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use ArrayIterator;
|
||||
use Traversable;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use IteratorAggregate;
|
||||
use RangeException;
|
||||
|
||||
/**
|
||||
* A simple mutable dictionary, i.e. an enumerable key-value map.
|
||||
*/
|
||||
class Dictionary implements
|
||||
IteratorAggregate,
|
||||
WritableMapInterface
|
||||
{
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/** @var array<array-key, mixed> */
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $data The key-value map of data.
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!array_key_exists($key, $this->data)) {
|
||||
throw new NotFoundException(
|
||||
$this->__('Dictionary does not have key "%1$s"', [$key]),
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
$isHas = array_key_exists($key, $this->data);
|
||||
|
||||
return $isHas;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @psalm-suppress MoreSpecificReturnType
|
||||
* Psalm complains that the declared return type is more specific than inferred.
|
||||
* This is not true, as it promises to return the interface.
|
||||
*/
|
||||
public function withMappings(array $mappings): WritableContainerInterface
|
||||
{
|
||||
$dictionary = $this->cloneMe();
|
||||
$dictionary->data = $mappings;
|
||||
|
||||
/**
|
||||
* @psalm-suppress LessSpecificReturnStatement
|
||||
* Looks like this needs to be suppressed until able to hint return type `self`.
|
||||
*/
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @psalm-suppress MoreSpecificReturnType
|
||||
* Psalm complains that the declared return type is more specific than inferred.
|
||||
* This is not true, as it promises to return the interface.
|
||||
*/
|
||||
public function withAddedMappings(array $mappings): WritableContainerInterface
|
||||
{
|
||||
$dictionary = $this->cloneMe();
|
||||
$dictionary->data = $mappings + $this->data;
|
||||
|
||||
/**
|
||||
* @psalm-suppress LessSpecificReturnStatement
|
||||
* Looks like this needs to be suppressed until able to hint return type `self`.
|
||||
*/
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @psalm-suppress MoreSpecificReturnType
|
||||
* Psalm complains that the declared return type is more specific than inferred.
|
||||
* This is not true, as it promises to return the interface.
|
||||
*/
|
||||
public function withoutKeys(array $keys): WritableContainerInterface
|
||||
{
|
||||
$dictionary = $this->cloneMe();
|
||||
|
||||
foreach ($keys as $i => $key) {
|
||||
/** @psalm-suppress DocblockTypeContradiction Still want to enforce string */
|
||||
if (!is_string($key)) {
|
||||
throw new RangeException($this->__('Key at index %1$d is not a string', [$i]));
|
||||
}
|
||||
unset($dictionary->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress LessSpecificReturnStatement
|
||||
* Looks like this needs to be suppressed until able to hint return type `self`.
|
||||
*/
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of this instance
|
||||
*
|
||||
* @return Dictionary The new instance
|
||||
*/
|
||||
protected function cloneMe(): Dictionary
|
||||
{
|
||||
return clone $this;
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapFactoryInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
class DictionaryFactory implements WritableMapFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createContainerFromArray(array $data): ContainerInterface
|
||||
{
|
||||
return new Dictionary($data);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception;
|
||||
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Basic implementation of container exception.
|
||||
*
|
||||
* @package Dhii\Di
|
||||
*/
|
||||
class ContainerException extends Exception implements ContainerExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface|null
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @param string $message The exception message.
|
||||
* @param int $code The exception code.
|
||||
* @param Throwable|null $previous The inner exception, if any.
|
||||
*/
|
||||
public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
class NotFoundException extends ContainerException implements NotFoundExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @param string $message The error message.
|
||||
* @param int $code The error code.
|
||||
* @param Throwable|null $previous The inner error, if any.
|
||||
*/
|
||||
public function __construct(
|
||||
string $message = '',
|
||||
int $code = 0,
|
||||
Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ClearableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\MutableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
|
||||
/**
|
||||
* A container for data that is accessible once per init.
|
||||
*
|
||||
* The {@see init()} method copies data from the internal container into memory,
|
||||
* then clears it. The data is still accessible from memory,
|
||||
* but no longer from internal container.
|
||||
*
|
||||
* This is useful for flash data, i.e. data that should only be accessible
|
||||
* once per request. If a session-specific persistent container is used
|
||||
* as storage, this will become session-based flash data.
|
||||
*/
|
||||
class FlashContainer implements
|
||||
MutableContainerInterface,
|
||||
ClearableContainerInterface
|
||||
{
|
||||
/** @var MutableContainerInterface */
|
||||
protected $data;
|
||||
/** @var string */
|
||||
protected $dataKey;
|
||||
/** @var array<array-key, scalar> */
|
||||
protected $flashData = [];
|
||||
|
||||
/**
|
||||
* @param MutableContainerInterface $data The storage.
|
||||
* @param string $dataKey The key to be used to store data in the storage.
|
||||
*/
|
||||
public function __construct(MutableContainerInterface $data, string $dataKey)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->dataKey = $dataKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare storage before use.
|
||||
*
|
||||
* Should be called once before accessing data through this class.
|
||||
* Will clear the data for the configured key from the storage.
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->flashData = $this->data->has($this->dataKey)
|
||||
? $this->data->get($this->dataKey)
|
||||
: [];
|
||||
|
||||
$this->purgePersistentData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return array_key_exists($key, $this->flashData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Retrieves the value for the specified key from memory.
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!array_key_exists($key, $this->flashData)) {
|
||||
throw new NotFoundException(sprintf('Flash data not found for key "%1$s"', $key));
|
||||
}
|
||||
|
||||
return $this->flashData[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Assigns the given value to the specified key in memory, and persists this change in storage.
|
||||
*/
|
||||
public function set(string $key, $value): void
|
||||
{
|
||||
$this->flashData[$key] = $value;
|
||||
$this->persist($this->flashData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Removes the specified key from memory, and persists this change in storage.
|
||||
*/
|
||||
public function unset(string $key): void
|
||||
{
|
||||
if (!array_key_exists($key, $this->flashData)) {
|
||||
throw new NotFoundException(sprintf('Flash data not found for key "%1$s"', $key));
|
||||
}
|
||||
|
||||
unset($this->flashData[$key]);
|
||||
$this->persist($this->flashData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Clears all of this instance's data from memory.
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
$this->flashData = [];
|
||||
$this->persist($this->flashData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear data from internal storage.
|
||||
*/
|
||||
protected function purgePersistentData(): void
|
||||
{
|
||||
$this->data->set($this->dataKey, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist this instance's data from memory into storage.
|
||||
*
|
||||
* @param array<array-key, scalar> $data The data to persist.
|
||||
*/
|
||||
protected function persist(array $data): void
|
||||
{
|
||||
$this->data->set($this->dataKey, $data);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* A container implementation that provides access to hierarchical data in the form a container tree.
|
||||
*
|
||||
* This implementation dynamically transforms hierarchical data into a tree of containers, on-demand. The transformation
|
||||
* is performed "in-place", converting internal array and object values into containers without producing a copy or
|
||||
* internal cache, making this implementation very memory-friendly.
|
||||
*
|
||||
* **Example usage:**
|
||||
*
|
||||
* ```php
|
||||
* $data = [
|
||||
* 'config' => [
|
||||
* 'db' => [
|
||||
* 'host' => 'localhost',
|
||||
* 'port' => 3306,
|
||||
* ],
|
||||
* ]
|
||||
* ];
|
||||
*
|
||||
* $container = new HierarchicalContainer($data);
|
||||
* $container->get('config')->get('db')->get('host'); // "localhost"
|
||||
* ```
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see PathContainer For an implementation that compliments this one by allowing container trees to be accessed using
|
||||
* path-like keys.
|
||||
* @see SegmentingContainer For an implementation that achieves a similar effect but for flat hierarchies.
|
||||
*/
|
||||
class HierarchyContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param mixed[] $data The hierarchical data for which to create the container tree.
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!array_key_exists($key, $this->data)) {
|
||||
throw new NotFoundException("Key '{$key}' does not exist", 0, null);
|
||||
}
|
||||
|
||||
$value = $this->data[$key];
|
||||
|
||||
if ($value instanceof stdClass) {
|
||||
$value = get_object_vars($value);
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $this->data[$key] = new self($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return array_key_exists($key, $this->data);
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
/**
|
||||
* A container implementation that can map results from another container using a callback.
|
||||
*
|
||||
* **Example usage**:
|
||||
*
|
||||
* ```php
|
||||
* $container = new Container([
|
||||
* 'first' => 'Paul',
|
||||
* 'second' => 'JC',
|
||||
* 'third' => 'Alex',
|
||||
* ]);
|
||||
*
|
||||
* $mContainer = new MappingContainer($container, function ($name) {
|
||||
* return $name . ' Denton';
|
||||
* });
|
||||
*
|
||||
* $mContainer->get('first'); // "Paul Denton"
|
||||
* $mContainer->get('second'); // "JC Denton"
|
||||
*
|
||||
* // We don't talk about Alex
|
||||
* ```
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class MappingContainer implements ContainerInterface
|
||||
{
|
||||
/* @since [*next-version*] */
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $inner The container instance to decorate.
|
||||
* @param callable $callback The callback to invoke on get. It will be passed 3 parameters:
|
||||
* * The inner container's value for the key being fetched.
|
||||
* * The key being fetched.
|
||||
* * A reference to this container instance.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $inner, callable $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
$this->inner = $inner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return ($this->callback)($this->inner->get($key), $key, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return $this->inner->has($key);
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* An implementation of a container that wraps around another to selectively expose or mask certain keys.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class MaskingContainer implements ContainerInterface
|
||||
{
|
||||
/* @since [*next-version*] */
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/**
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* @var bool[]
|
||||
*/
|
||||
protected $mask;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $defMask;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $inner The container whose entries to mask.
|
||||
* @param bool $defaultMask The default mask. If true, all inner keys are exposed. If false, all
|
||||
* inner keys are hidden. Any keys specified in the $mask parameter will
|
||||
* naturally override this setting.
|
||||
* @param bool[] $mask A mapping of keys to booleans, such that `true` exposes the mapped key
|
||||
* and `false` hides the mapped key.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $inner, bool $defaultMask, array $mask)
|
||||
{
|
||||
$this->inner = $inner;
|
||||
$this->defMask = $defaultMask;
|
||||
$this->mask = $mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!$this->isExposed($key)) {
|
||||
throw new NotFoundException(
|
||||
$this->__('Inner key "%1$s" is not exposed', [$key]),
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
return $this->inner->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return $this->isExposed($key) && $this->inner->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a key is exposed through the mask.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The key to check.
|
||||
*
|
||||
* @return bool True if the key is exposed, false if the key is hidden.
|
||||
*/
|
||||
protected function isExposed(string $key): bool
|
||||
{
|
||||
return array_key_exists($key, $this->mask)
|
||||
? $this->mask[$key] !== false
|
||||
: $this->defMask;
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use ArrayIterator;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ClearableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\MutableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* A container that does nothing.
|
||||
*
|
||||
* This can be used if an actual implementation is not available,
|
||||
* without extra checks or nullables - just as if it was a real one.
|
||||
*/
|
||||
class NoOpContainer implements
|
||||
MutableContainerInterface,
|
||||
IteratorAggregate,
|
||||
WritableMapInterface,
|
||||
ClearableContainerInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
throw new NotFoundException('NoOp container cannot have values');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function has($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function set(string $key, $value): void
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function unset(string $key): void
|
||||
{
|
||||
throw new ContainerException('NoOp container cannot have values');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withMappings(array $mappings): WritableContainerInterface
|
||||
{
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withAddedMappings(array $mappings): WritableContainerInterface
|
||||
{
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withoutKeys(array $keys): WritableContainerInterface
|
||||
{
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator([]);
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* A container implementation that decorates a hierarchy of {@link ContainerInterface} instances to allow path-like
|
||||
* access to deep containers or data.
|
||||
*
|
||||
* **Example usage**
|
||||
*
|
||||
* Consider the below hierarchy of containers:
|
||||
*
|
||||
* ```php
|
||||
* $container = new Container([
|
||||
* 'config' => new Container([
|
||||
* 'db' => new Container([
|
||||
* 'host' => 'localhost',
|
||||
* 'port' => 3306
|
||||
* ])
|
||||
* ])
|
||||
* ]);
|
||||
* ```
|
||||
*
|
||||
* A {@link PathContainer} can decorate the `$container` to substitute this:
|
||||
*
|
||||
* ```php
|
||||
* $host = $container->get('config')->get('db')->get('port');
|
||||
* ```
|
||||
*
|
||||
* With this:
|
||||
*
|
||||
* ```php
|
||||
* $pContainer = new PathContainer($container, '.');
|
||||
* $pContainer->get('config.db.port');
|
||||
* ```
|
||||
*
|
||||
* Note that this implementation DOES NOT create containers for hierarchical _values_. Each segment in a given path
|
||||
* must correspond to a child {@link ContainerInterface} instance.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see SegmentingContainer For an implementation that achieves the opposite effect.
|
||||
*/
|
||||
class PathContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var non-empty-string
|
||||
*/
|
||||
protected $delimiter;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $inner The container instance to decorate.
|
||||
* @param non-empty-string $delimiter The path delimiter to use.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $inner, string $delimiter = '/')
|
||||
{
|
||||
$this->inner = $inner;
|
||||
$this->delimiter = $delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$tKey = (strpos($key, $this->delimiter) === 0)
|
||||
? substr($key, strlen($this->delimiter))
|
||||
: $key;
|
||||
|
||||
$delimiter = $this->delimiter;
|
||||
if (!strlen($delimiter)) {
|
||||
throw new ContainerException('Cannot use empty delimiter');
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress PossiblyFalseArgument
|
||||
* Result of explode() will never be false, because delimiter is never empty - see above.
|
||||
*/
|
||||
$path = array_filter(explode($this->delimiter, $tKey));
|
||||
|
||||
if (empty($path)) {
|
||||
throw new NotFoundException('The path is empty');
|
||||
}
|
||||
|
||||
$current = $this->inner;
|
||||
$head = $path[0];
|
||||
|
||||
while (!empty($path)) {
|
||||
if (!($current instanceof PsrContainerInterface)) {
|
||||
$tail = implode($this->delimiter, $path);
|
||||
throw new NotFoundException(sprintf('Key "%1$s" does not exist at path "%2$s"', $head, $tail));
|
||||
}
|
||||
|
||||
$head = array_shift($path);
|
||||
$current = $current->get($head);
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
/**
|
||||
* @psalm-suppress InvalidCatch
|
||||
* The base interface does not extend Throwable, but in fact everything that is possible
|
||||
* in theory to catch will be Throwable, and PSR-11 exceptions will implement this interface
|
||||
*/
|
||||
try {
|
||||
$this->get($key);
|
||||
|
||||
return true;
|
||||
} catch (NotFoundExceptionInterface $exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* A container implementation that wraps around an inner container and prefixes its keys, requiring consumers to
|
||||
* include them when fetching or looking up data.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
class PrefixingContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $strict;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $container The container whose keys to prefix.
|
||||
* @param string $prefix The prefix to apply to the container's keys.
|
||||
* @param bool $strict Whether or not to fallback to un-prefixed keys if a prefixed key does not
|
||||
* exist in the inner container.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $container, string $prefix, bool $strict = true)
|
||||
{
|
||||
$this->inner = $container;
|
||||
$this->prefix = $prefix;
|
||||
$this->strict = $strict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!$this->isPrefixed($key) && $this->strict) {
|
||||
throw new NotFoundException(sprintf('Key "%s" does not exist', $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress InvalidCatch
|
||||
* The base interface does not extend Throwable, but in fact everything that is possible
|
||||
* in theory to catch will be Throwable, and PSR-11 exceptions will implement this interface
|
||||
*/
|
||||
try {
|
||||
return $this->inner->get($this->unprefix($key));
|
||||
} catch (NotFoundExceptionInterface $nfException) {
|
||||
if ($this->strict) {
|
||||
throw $nfException;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->inner->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
if (!$this->isPrefixed($key) && $this->strict) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->inner->has($this->unprefix($key)) || (!$this->strict && $this->inner->has($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the key to use for the inner container.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The outer key.
|
||||
*
|
||||
* @return string The inner key.
|
||||
*/
|
||||
protected function unprefix(string $key): string
|
||||
{
|
||||
return $this->isPrefixed($key)
|
||||
? substr($key, strlen($this->prefix))
|
||||
: $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the key is prefixed.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $key The key to check.
|
||||
*
|
||||
* @return bool True if the key is prefixed, false if not.
|
||||
*/
|
||||
protected function isPrefixed(string $key): bool
|
||||
{
|
||||
return strlen($this->prefix) > 0 && strpos($key, $this->prefix) === 0;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util\StringTranslatingTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as BaseContainerInterface;
|
||||
|
||||
/**
|
||||
* A proxy for another container, and nothing more.
|
||||
*
|
||||
* The advantage is that its setter can be used at any point after construction,
|
||||
* which solves the chicken-egg problem of two co-dependent containers.
|
||||
*/
|
||||
class ProxyContainer implements BaseContainerInterface
|
||||
{
|
||||
use StringTranslatingTrait;
|
||||
|
||||
/**
|
||||
* @var ?BaseContainerInterface
|
||||
*/
|
||||
protected $innerContainer;
|
||||
|
||||
/**
|
||||
* @param BaseContainerInterface|null $innerContainer The inner container, if any.
|
||||
* May also be set later with {@see setInnerContainer()}.
|
||||
*/
|
||||
public function __construct(BaseContainerInterface $innerContainer = null)
|
||||
{
|
||||
$this->innerContainer = $innerContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!($this->innerContainer instanceof BaseContainerInterface)) {
|
||||
throw new ContainerException($this->__('Inner container not set'));
|
||||
}
|
||||
|
||||
return $this->innerContainer->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
if (!($this->innerContainer instanceof BaseContainerInterface)) {
|
||||
/** @psalm-suppress MissingThrowsDocblock The exception class implements declared thrown interface */
|
||||
throw new ContainerException($this->__('Inner container not set'));
|
||||
}
|
||||
|
||||
return $this->innerContainer->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns an inner container tot his proxy.
|
||||
*
|
||||
* Calls to `has()` and `get()` will be forwarded to this inner container.
|
||||
*
|
||||
* @param BaseContainerInterface $innerContainer The inner container to proxy.
|
||||
*/
|
||||
public function setInnerContainer(BaseContainerInterface $innerContainer): void
|
||||
{
|
||||
$this->innerContainer = $innerContainer;
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
use function array_filter;
|
||||
use function ltrim;
|
||||
|
||||
/**
|
||||
* This container implementation decorates another to provide nested container access even when the decorated
|
||||
* container's internal data is flat.
|
||||
*
|
||||
* Segmenting containers are intended to be used with keys that contain segments, i.e. keys that use a delimiter to
|
||||
* indicate hierarchy. For example: "some/test/key" or "some.deep.config.value". The delimiter can be configured during
|
||||
* construction of a segmenting container.
|
||||
*
|
||||
* A segmenting container can yield 2 different kinds of results when {@link SegmentingContainer::get()} is called:
|
||||
*
|
||||
* **Values**
|
||||
*
|
||||
* If the inner container has a value for the given key, that value is returned.
|
||||
*
|
||||
* **Segments**
|
||||
*
|
||||
* If the inner container has no value for the given key, a new {@link SegmentingContainer} instance is returned. This
|
||||
* segmenting container will be aware of the key that resulted in its creation, and will automatically prepend that key
|
||||
* to parameter keys given in `get()`.
|
||||
*
|
||||
* **Example usage:**
|
||||
*
|
||||
* Consider the below data and a regular `$container` that provides access to it:
|
||||
*
|
||||
* ```php
|
||||
* $data = [
|
||||
* 'config.db.host' => 'localhost',
|
||||
* 'config.db.post' => '3306',
|
||||
* ];
|
||||
* ```
|
||||
*
|
||||
* A segmenting container can be created that provides access to the "host" and "port":
|
||||
*
|
||||
* ```php
|
||||
* $segmented = new SegmentingContainer($container, '.');
|
||||
* $dbConfig = $config->get('config')->get('db');
|
||||
* $dbConfig->get("host"); // "localhost"
|
||||
* $dbConfig->get("port"); // 3306
|
||||
* ```
|
||||
*
|
||||
* @since [*next-version*]
|
||||
* @see PathContainer For an implementation that achieves the opposite effect.
|
||||
*/
|
||||
class SegmentingContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var PsrContainerInterface
|
||||
*/
|
||||
protected $inner;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $root;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $delimiter;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param PsrContainerInterface $inner The container to decorate.
|
||||
* @param string $delimiter The path delimiter.
|
||||
*/
|
||||
public function __construct(PsrContainerInterface $inner, string $delimiter = '/')
|
||||
{
|
||||
$this->inner = $inner;
|
||||
$this->root = '';
|
||||
$this->delimiter = $delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$tKey = ltrim($key, $this->delimiter);
|
||||
$tRoot = rtrim($this->root, $this->delimiter);
|
||||
// Implode to glue together the key and root, and array_filter to ignore them if they're empty
|
||||
$fullKey = implode($this->delimiter, array_filter([$tRoot, $tKey]));
|
||||
|
||||
if ($this->inner->has($fullKey)) {
|
||||
return $this->inner->get($fullKey);
|
||||
}
|
||||
|
||||
$instance = clone $this;
|
||||
$instance->root = $fullKey;
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return $this->inner->has($key);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* A value object capable of providing services.
|
||||
*
|
||||
* @package Dhii\Di
|
||||
*/
|
||||
class ServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var callable[]
|
||||
*/
|
||||
protected $factories;
|
||||
/**
|
||||
* @var callable[]
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @param callable[] $factories A map of service name to service factory.
|
||||
* @param callable[] $extensions A map of service name to service extension.
|
||||
*/
|
||||
public function __construct(array $factories, array $extensions)
|
||||
{
|
||||
$this->factories = $factories;
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getFactories()
|
||||
{
|
||||
return $this->factories;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getExtensions()
|
||||
{
|
||||
return $this->extensions;
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\ClearableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\MutableContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\ContainerException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Exception\NotFoundException;
|
||||
use Exception;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
class SimpleCacheContainer implements
|
||||
MutableContainerInterface,
|
||||
ClearableContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $storage;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $ttl;
|
||||
|
||||
public function __construct(CacheInterface $storage, int $ttl)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
$this->ttl = $ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
try {
|
||||
if (!$storage->has($id)) {
|
||||
return new NotFoundException(sprintf('Key "%1$s" not found', $id));
|
||||
}
|
||||
|
||||
$value = $storage->get($id);
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(sprintf('Could not retrieve value for key "%1$s"', $id), 0, $e);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function has($id)
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
try {
|
||||
$has = $storage->has($id);
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(sprintf('Could not check for key "%1$s"', $id), 0, $e);
|
||||
}
|
||||
|
||||
return $has;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function set(string $key, $value): void
|
||||
{
|
||||
$storage = $this->storage;
|
||||
$ttl = $this->ttl;
|
||||
|
||||
try {
|
||||
$storage->set($key, $value, $ttl);
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(sprintf('Could not set key "%1$s" with value "%2$s"', $key, $value), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function unset(string $key): void
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
try {
|
||||
$storage->delete($key);
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(sprintf('Could not unset key "%1$s"', $key), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
$storage = $this->storage;
|
||||
|
||||
try {
|
||||
$storage->clear();
|
||||
} catch (Exception $e) {
|
||||
throw new ContainerException(sprintf('Could not clear container'), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Util;
|
||||
|
||||
/**
|
||||
* Methods for classes which can translate.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*/
|
||||
trait StringTranslatingTrait
|
||||
{
|
||||
/**
|
||||
* Translates a string, and replaces placeholders.
|
||||
*
|
||||
* The translation itself is delegated to another method.
|
||||
*
|
||||
* @see sprintf()
|
||||
* @see _translate()
|
||||
*
|
||||
* @param string $string The format string to translate.
|
||||
* @param list<scalar> $args Placeholder values to replace in the string.
|
||||
* @param mixed $context The context for translation.
|
||||
*
|
||||
* @return string The translated string.
|
||||
*/
|
||||
protected function __(string $string, array $args = array(), $context = null): string
|
||||
{
|
||||
$string = $this->_translate($string, $context);
|
||||
array_unshift($args, $string);
|
||||
return call_user_func_array('sprintf', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string.
|
||||
*
|
||||
* A no-op implementation.
|
||||
*
|
||||
* @since [*next-version*]
|
||||
*
|
||||
* @param string $string The string to translate.
|
||||
* @param string $context The context to translate the string in.
|
||||
*
|
||||
* @return string The translated string.
|
||||
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
|
||||
*/
|
||||
protected function _translate(string $string, string $context = null): string
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\Exception;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleAwareInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Represents an exception that is thrown in relation to a module.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface ModuleExceptionInterface extends
|
||||
Throwable,
|
||||
ModuleAwareInterface
|
||||
{
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module;
|
||||
|
||||
/**
|
||||
* Something that can have a module instance retrieved.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface ModuleAwareInterface
|
||||
{
|
||||
/**
|
||||
* Retrieves the module that is associated with this instance.
|
||||
*
|
||||
* @since 0.2
|
||||
*
|
||||
* @return ModuleInterface|null The module, if applicable; otherwise, null.
|
||||
*/
|
||||
public function getModule(): ?ModuleInterface;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\Exception\ModuleExceptionInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Something that represents an application module.
|
||||
*
|
||||
* @since 0.2
|
||||
*/
|
||||
interface ModuleInterface
|
||||
{
|
||||
/**
|
||||
* Performs module-specific setup and provides a service provider.
|
||||
*
|
||||
* This method SHOULD be called at least once before {@link ModuleInterface::run()} may be invoked for a particular
|
||||
* module instance. The returned service provider instance SHOULD be incorporated by the application into the
|
||||
* container instance that is then given to this module's {@link ModuleInterface::run()} method.
|
||||
*
|
||||
* The application MAY also incorporate the service provider into the container instance given to other modules,
|
||||
* but this is not required. As such, services factories in the returned service provider should not assume the
|
||||
* existence of other module's services. Use proxy services together with {@link ContainerInterface::has()} for
|
||||
* optionally integrating with other modules.
|
||||
*
|
||||
* @since 0.2
|
||||
*
|
||||
* @return ServiceProviderInterface A service provider instance for this module's services.
|
||||
*
|
||||
* @throws ModuleExceptionInterface If module setup failed and/or a service provider instance could not be returned.
|
||||
*/
|
||||
public function setup(): ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* Runs the module.
|
||||
*
|
||||
* This method MUST be called after the module has been set up using {@link ModuleInterface::setup()}. A services
|
||||
* container MUST be given to this method, and MUST incorporate the services from the service provider returned
|
||||
* by the same module's {@link ModuleInterface::setup()} method. This container instance is not guaranteed to be
|
||||
* the same instance given to other modules. As such, it is strongly advised to assume it is not, and to avoid
|
||||
* referencing services from other modules.
|
||||
*
|
||||
* @since 0.2
|
||||
*
|
||||
* @param ContainerInterface $c A services container instance.
|
||||
*
|
||||
* @throws ModuleExceptionInterface If the module failed to run.
|
||||
*/
|
||||
public function run(ContainerInterface $c): void;
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
class ContainerConfigurator
|
||||
{
|
||||
/**
|
||||
* @var array<string, callable(ContainerInterface $container):mixed>
|
||||
*/
|
||||
private $services = [];
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $factoryIds = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array<callable(mixed $service, ContainerInterface $container):mixed>>
|
||||
*/
|
||||
private $extensions = [];
|
||||
|
||||
/**
|
||||
* @var ContainerInterface[]
|
||||
*/
|
||||
private $containers = [];
|
||||
|
||||
/**
|
||||
* @var null|ContainerInterface
|
||||
*/
|
||||
private $compiledContainer;
|
||||
|
||||
/**
|
||||
* ContainerConfigurator constructor.
|
||||
*
|
||||
* @param ContainerInterface[] $containers
|
||||
*/
|
||||
public function __construct(array $containers = [])
|
||||
{
|
||||
array_map([$this, 'addContainer'], $containers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowing to add child containers.
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
*/
|
||||
public function addContainer(ContainerInterface $container): void
|
||||
{
|
||||
$this->containers[] = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param callable(ContainerInterface $container):mixed $factory
|
||||
*/
|
||||
public function addFactory(string $id, callable $factory): void
|
||||
{
|
||||
$this->addService($id, $factory);
|
||||
// We're using a hash table to detect later
|
||||
// via isset() if a Service as a Factory.
|
||||
$this->factoryIds[$id] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param callable(ContainerInterface $container):mixed $service
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addService(string $id, callable $service): void
|
||||
{
|
||||
/*
|
||||
* We are being intentionally permissive here,
|
||||
* allowing a simple workflow for *intentional* overrides
|
||||
* while accepting the (small?) risk of *accidental* overrides
|
||||
* that could be hard to notice and debug.
|
||||
*
|
||||
* Clear a factory flag in case it was a factory.
|
||||
* If needs be, it will get re-added after this function completes.
|
||||
*/
|
||||
unset($this->factoryIds[$id]);
|
||||
|
||||
$this->services[$id] = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasService(string $id): bool
|
||||
{
|
||||
if (array_key_exists($id, $this->services)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->containers as $container) {
|
||||
if ($container->has($id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param callable(mixed $service, ContainerInterface $container):mixed $extender
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addExtension(string $id, callable $extender): void
|
||||
{
|
||||
if (!isset($this->extensions[$id])) {
|
||||
$this->extensions[$id] = [];
|
||||
}
|
||||
|
||||
$this->extensions[$id][] = $extender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasExtension(string $id): bool
|
||||
{
|
||||
return isset($this->extensions[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a read only version of this Container.
|
||||
*
|
||||
* @return ContainerInterface
|
||||
*/
|
||||
public function createReadOnlyContainer(): ContainerInterface
|
||||
{
|
||||
if (!$this->compiledContainer) {
|
||||
$this->compiledContainer = new ReadOnlyContainer(
|
||||
$this->services,
|
||||
$this->factoryIds,
|
||||
$this->extensions,
|
||||
$this->containers
|
||||
);
|
||||
}
|
||||
|
||||
return $this->compiledContainer;
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Package;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerExceptionInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
class PackageProxyContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var Package
|
||||
*/
|
||||
private $package;
|
||||
|
||||
/**
|
||||
* @var ContainerInterface|null
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* @param Package $package
|
||||
*/
|
||||
public function __construct(Package $package)
|
||||
{
|
||||
$this->package = $package;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(string $id)
|
||||
{
|
||||
$this->assertPackageBooted($id);
|
||||
|
||||
return $this->container->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function has(string $id): bool
|
||||
{
|
||||
return $this->tryContainer() && $this->container->has($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
* @psalm-assert-if-true ContainerInterface $this->container
|
||||
*/
|
||||
private function tryContainer(): bool
|
||||
{
|
||||
if ($this->container) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** TODO: We need a better way to deal with status checking besides equality */
|
||||
if (
|
||||
$this->package->statusIs(Package::STATUS_READY)
|
||||
|| $this->package->statusIs(Package::STATUS_BOOTED)
|
||||
) {
|
||||
$this->container = $this->package->container();
|
||||
}
|
||||
|
||||
return (bool)$this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @psalm-assert ContainerInterface $this->container
|
||||
*/
|
||||
private function assertPackageBooted(string $id): void
|
||||
{
|
||||
if ($this->tryContainer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $this->package->name();
|
||||
$status = $this->package->statusIs(Package::STATUS_FAILED)
|
||||
? 'is errored'
|
||||
: 'is not ready yet';
|
||||
|
||||
throw new class ("Error retrieving service {$id} because package {$name} {$status}.")
|
||||
extends \Exception
|
||||
implements ContainerExceptionInterface {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class ReadOnlyContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, callable(\WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container):mixed>
|
||||
*/
|
||||
private $services;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $factoryIds;
|
||||
|
||||
/**
|
||||
* @var array<string, array<callable(mixed, ContainerInterface $container):mixed>>
|
||||
*/
|
||||
private $extensions;
|
||||
|
||||
/**
|
||||
* Resolved factories.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private $resolvedServices = [];
|
||||
|
||||
/**
|
||||
* @var ContainerInterface[]
|
||||
*/
|
||||
private $containers;
|
||||
|
||||
/**
|
||||
* ReadOnlyContainer constructor.
|
||||
*
|
||||
* @param array<string, callable(ContainerInterface $container):mixed> $services
|
||||
* @param array<string, bool> $factoryIds
|
||||
* @param array<string, array<callable(mixed, ContainerInterface $container):mixed>> $extensions
|
||||
* @param ContainerInterface[] $containers
|
||||
*/
|
||||
public function __construct(
|
||||
array $services,
|
||||
array $factoryIds,
|
||||
array $extensions,
|
||||
array $containers
|
||||
) {
|
||||
$this->services = $services;
|
||||
$this->factoryIds = $factoryIds;
|
||||
$this->extensions = $extensions;
|
||||
$this->containers = $containers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $id)
|
||||
{
|
||||
if (array_key_exists($id, $this->resolvedServices)) {
|
||||
return $this->resolvedServices[$id];
|
||||
}
|
||||
|
||||
if (array_key_exists($id, $this->services)) {
|
||||
$service = $this->services[$id]($this);
|
||||
$resolved = $this->resolveExtensions($id, $service);
|
||||
|
||||
if (!isset($this->factoryIds[$id])) {
|
||||
$this->resolvedServices[$id] = $resolved;
|
||||
unset($this->services[$id]);
|
||||
}
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
foreach ($this->containers as $container) {
|
||||
if ($container->has($id)) {
|
||||
$service = $container->get($id);
|
||||
|
||||
return $this->resolveExtensions($id, $service);
|
||||
}
|
||||
}
|
||||
|
||||
throw new class ("Service with ID {$id} not found.")
|
||||
extends \Exception
|
||||
implements NotFoundExceptionInterface {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $id): bool
|
||||
{
|
||||
if (array_key_exists($id, $this->services)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (array_key_exists($id, $this->resolvedServices)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->containers as $container) {
|
||||
if ($container->has($id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param mixed $service
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function resolveExtensions(string $id, $service)
|
||||
{
|
||||
if (!isset($this->extensions[$id])) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
foreach ($this->extensions[$id] as $extender) {
|
||||
$service = $extender($service, $this);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
interface ExecutableModule extends Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Perform actions with objects retrieved from the container. Usually, adding WordPress hooks.
|
||||
* Return true to signal a success, false to signal a failure.
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
*
|
||||
* @return bool true when successfully booted, otherwise false.
|
||||
*/
|
||||
public function run(ContainerInterface $container): bool;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module;
|
||||
|
||||
interface ExtendingModule extends Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Return application services' extensions.
|
||||
*
|
||||
* Array keys will be services' IDs in the container, array values are callback that
|
||||
* accepts as parameters the original service and a PSR-11 container and return an instance of
|
||||
* the extended service.
|
||||
*
|
||||
* It is possible to explicitly extend extensions made by other modules.
|
||||
* That is done by using as ID (array key in the `extensions` method) the target module ID
|
||||
* and the service ID.
|
||||
*
|
||||
* @return array<string, callable(mixed $service, \WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container):mixed>
|
||||
*/
|
||||
public function extensions(): array;
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module;
|
||||
|
||||
interface FactoryModule extends Module
|
||||
{
|
||||
/**
|
||||
* Return application factories.
|
||||
*
|
||||
* Similar to `services`, but object created by given factories are not "cached", but a *new*
|
||||
* instance is returned everytime `get()` is called in the container.
|
||||
*
|
||||
* @return array<string, callable(\WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container):mixed>
|
||||
*/
|
||||
public function factories(): array;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module;
|
||||
|
||||
/**
|
||||
* @package WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module
|
||||
*/
|
||||
interface Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Unique identifier for your Module.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function id(): string;
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module;
|
||||
|
||||
/**
|
||||
* Trait ModuleClassNameIdTrait
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module
|
||||
*/
|
||||
trait ModuleClassNameIdTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @see Module::id()
|
||||
*/
|
||||
public function id(): string
|
||||
{
|
||||
return __CLASS__;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module;
|
||||
|
||||
interface ServiceModule extends Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Return application services' factories.
|
||||
*
|
||||
* Array keys will be services' IDs in the container, array values are callback that
|
||||
* accepts a PSR-11 container as parameter and return an instance of the service.
|
||||
* Services are "cached", so the given factory is called once the first time `get()` is called
|
||||
* in the container, and on subsequent `get()` the same instance is returned again and again.
|
||||
*
|
||||
* @return array<string, callable(\WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container):mixed>
|
||||
*/
|
||||
public function services(): array;
|
||||
}
|
|
@ -1,727 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ContainerConfigurator;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\PackageProxyContainer;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\FactoryModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\Module;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties\Properties;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
class Package
|
||||
{
|
||||
/**
|
||||
* All the hooks fired in this class use this prefix.
|
||||
* @var string
|
||||
*/
|
||||
private const HOOK_PREFIX = 'inpsyde.modularity.';
|
||||
|
||||
/**
|
||||
* Identifier to access Properties in Container.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
* $package->boot();
|
||||
*
|
||||
* $container = $package->container();
|
||||
* $container->has(Package::PROPERTIES);
|
||||
* $container->get(Package::PROPERTIES);
|
||||
* </code>
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const PROPERTIES = 'properties';
|
||||
|
||||
/**
|
||||
* Custom action to be used to add Modules to the package.
|
||||
* It might also be used to access package properties.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
*
|
||||
* add_action(
|
||||
* $package->hookName(Package::ACTION_INIT),
|
||||
* $callback
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
public const ACTION_INIT = 'init';
|
||||
|
||||
/**
|
||||
* Custom action which is triggered after the application
|
||||
* is booted to access container and properties.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
*
|
||||
* add_action(
|
||||
* $package->hookName(Package::ACTION_READY),
|
||||
* $callback
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
public const ACTION_READY = 'ready';
|
||||
|
||||
/**
|
||||
* Custom action which is triggered when a failure happens during the building stage.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
*
|
||||
* add_action(
|
||||
* $package->hookName(Package::ACTION_FAILED_BUILD),
|
||||
* $callback
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
public const ACTION_FAILED_BUILD = 'failed-build';
|
||||
|
||||
/**
|
||||
* Custom action which is triggered when a failure happens during the booting stage.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
*
|
||||
* add_action(
|
||||
* $package->hookName(Package::ACTION_FAILED_BOOT),
|
||||
* $callback
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
public const ACTION_FAILED_BOOT = 'failed-boot';
|
||||
|
||||
/**
|
||||
* Custom action which is triggered when a package is connected.
|
||||
*/
|
||||
public const ACTION_PACKAGE_CONNECTED = 'package-connected';
|
||||
|
||||
/**
|
||||
* Custom action which is triggered when a package cannot be connected.
|
||||
*/
|
||||
public const ACTION_FAILED_CONNECTION = 'failed-connection';
|
||||
|
||||
/**
|
||||
* Module states can be used to get information about your module.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
* $package->moduleIs(SomeModule::class, Package::MODULE_ADDED); // false
|
||||
* $package->boot(new SomeModule());
|
||||
* $package->moduleIs(SomeModule::class, Package::MODULE_ADDED); // true
|
||||
* </code>
|
||||
*/
|
||||
public const MODULE_ADDED = 'added';
|
||||
public const MODULE_NOT_ADDED = 'not-added';
|
||||
public const MODULE_REGISTERED = 'registered';
|
||||
public const MODULE_REGISTERED_FACTORIES = 'registered-factories';
|
||||
public const MODULE_EXTENDED = 'extended';
|
||||
public const MODULE_EXECUTED = 'executed';
|
||||
public const MODULE_EXECUTION_FAILED = 'executed-failed';
|
||||
public const MODULES_ALL = '*';
|
||||
|
||||
/**
|
||||
* Custom states for the class.
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* $package = Package::new();
|
||||
* $package->statusIs(Package::IDLE); // true
|
||||
* $package->boot();
|
||||
* $package->statusIs(Package::BOOTED); // true
|
||||
* </code>
|
||||
*/
|
||||
public const STATUS_IDLE = 2;
|
||||
public const STATUS_INITIALIZED = 4;
|
||||
public const STATUS_MODULES_ADDED = 5;
|
||||
public const STATUS_READY = 7;
|
||||
public const STATUS_BOOTED = 8;
|
||||
public const STATUS_FAILED = -8;
|
||||
|
||||
/**
|
||||
* Current state of the application.
|
||||
*
|
||||
* @see Package::STATUS_*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $status = self::STATUS_IDLE;
|
||||
|
||||
/**
|
||||
* Contains the progress of all modules.
|
||||
*
|
||||
* @see Package::moduleProgress()
|
||||
*
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
private $moduleStatus = [self::MODULES_ALL => []];
|
||||
|
||||
/**
|
||||
* Hashmap of where keys are names of connected packages, and values are boolean, true
|
||||
* if connection was successful.
|
||||
*
|
||||
* @see Package::connect()
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $connectedPackages = [];
|
||||
|
||||
/**
|
||||
* @var list<ExecutableModule>
|
||||
*/
|
||||
private $executables = [];
|
||||
|
||||
/**
|
||||
* @var Properties
|
||||
*/
|
||||
private $properties;
|
||||
|
||||
/**
|
||||
* @var ContainerConfigurator
|
||||
*/
|
||||
private $containerConfigurator;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $built = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $hasContainer = false;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null
|
||||
*/
|
||||
private $lastError = null;
|
||||
|
||||
/**
|
||||
* @param Properties $properties
|
||||
* @param ContainerInterface[] $containers
|
||||
*
|
||||
* @return Package
|
||||
*/
|
||||
public static function new(Properties $properties, ContainerInterface ...$containers): Package
|
||||
{
|
||||
return new self($properties, ...$containers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Properties $properties
|
||||
* @param ContainerInterface[] $containers
|
||||
*/
|
||||
private function __construct(Properties $properties, ContainerInterface ...$containers)
|
||||
{
|
||||
$this->properties = $properties;
|
||||
|
||||
$this->containerConfigurator = new ContainerConfigurator($containers);
|
||||
$this->containerConfigurator->addService(
|
||||
self::PROPERTIES,
|
||||
static function () use ($properties) {
|
||||
return $properties;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Module $module
|
||||
*
|
||||
* @return static
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addModule(Module $module): Package
|
||||
{
|
||||
try {
|
||||
$this->assertStatus(self::STATUS_IDLE, sprintf('add module %s', $module->id()));
|
||||
|
||||
$registeredServices = $this->addModuleServices(
|
||||
$module,
|
||||
self::MODULE_REGISTERED
|
||||
);
|
||||
$registeredFactories = $this->addModuleServices(
|
||||
$module,
|
||||
self::MODULE_REGISTERED_FACTORIES
|
||||
);
|
||||
$extended = $this->addModuleServices(
|
||||
$module,
|
||||
self::MODULE_EXTENDED
|
||||
);
|
||||
$isExecutable = $module instanceof ExecutableModule;
|
||||
|
||||
// ExecutableModules are collected and executed on Package::boot()
|
||||
// when the Container is being compiled.
|
||||
if ($isExecutable) {
|
||||
/** @var ExecutableModule $module */
|
||||
$this->executables[] = $module;
|
||||
}
|
||||
|
||||
$added = $registeredServices || $registeredFactories || $extended || $isExecutable;
|
||||
$status = $added ? self::MODULE_ADDED : self::MODULE_NOT_ADDED;
|
||||
$this->moduleProgress($module->id(), $status);
|
||||
} catch (\Throwable $throwable) {
|
||||
$this->handleFailure($throwable, self::ACTION_FAILED_BUILD);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Package $package
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function connect(Package $package): bool
|
||||
{
|
||||
try {
|
||||
if ($package === $this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$packageName = $package->name();
|
||||
$errorData = ['package' => $packageName, 'status' => $this->status];
|
||||
$errorMessage = "Failed connecting package {$packageName}";
|
||||
|
||||
// Don't connect, if already connected
|
||||
if (array_key_exists($packageName, $this->connectedPackages)) {
|
||||
$error = "{$errorMessage} because it was already connected.";
|
||||
do_action(
|
||||
$this->hookName(self::ACTION_FAILED_CONNECTION),
|
||||
$packageName,
|
||||
new \WP_Error('already_connected', $error, $errorData)
|
||||
);
|
||||
|
||||
throw new \Exception($error, 0, $this->lastError);
|
||||
}
|
||||
|
||||
// Don't connect, if already booted or boot failed
|
||||
$failed = $this->statusIs(self::STATUS_FAILED);
|
||||
if ($failed || $this->statusIs(self::STATUS_BOOTED)) {
|
||||
$status = $failed ? 'errored' : 'booted';
|
||||
$error = "{$errorMessage} to a {$status} package.";
|
||||
do_action(
|
||||
$this->hookName(self::ACTION_FAILED_CONNECTION),
|
||||
$packageName,
|
||||
new \WP_Error("no_connect_on_{$status}", $error, $errorData)
|
||||
);
|
||||
|
||||
throw new \Exception($error, 0, $this->lastError);
|
||||
}
|
||||
|
||||
$this->connectedPackages[$packageName] = true;
|
||||
|
||||
// We put connected package's properties in this package's container, so that in modules
|
||||
// "run" method we can access them if we need to.
|
||||
$this->containerConfigurator->addService(
|
||||
sprintf('%s.%s', $package->name(), self::PROPERTIES),
|
||||
static function () use ($package): Properties {
|
||||
return $package->properties();
|
||||
}
|
||||
);
|
||||
|
||||
// If the other package is booted, we can obtain a container, otherwise
|
||||
// we build a proxy container
|
||||
$container = $package->statusIs(self::STATUS_BOOTED)
|
||||
? $package->container()
|
||||
: new PackageProxyContainer($package);
|
||||
|
||||
$this->containerConfigurator->addContainer($container);
|
||||
|
||||
do_action(
|
||||
$this->hookName(self::ACTION_PACKAGE_CONNECTED),
|
||||
$packageName,
|
||||
$this->status,
|
||||
$container instanceof PackageProxyContainer
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $throwable) {
|
||||
if (isset($packageName)) {
|
||||
$this->connectedPackages[$packageName] = false;
|
||||
}
|
||||
$this->handleFailure($throwable, self::ACTION_FAILED_BUILD);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function build(): Package
|
||||
{
|
||||
try {
|
||||
// Don't allow building the application multiple times.
|
||||
$this->assertStatus(self::STATUS_IDLE, 'build package');
|
||||
|
||||
do_action(
|
||||
$this->hookName(self::ACTION_INIT),
|
||||
$this
|
||||
);
|
||||
// Changing the status here ensures we can not call this method again, and also we can not
|
||||
// add new modules, because both this and `addModule()` methods check for idle status.
|
||||
// For backward compatibility, adding new modules via `boot()` will still be possible, even
|
||||
// if deprecated, at the condition that the container was not yet accessed at that point.
|
||||
$this->progress(self::STATUS_INITIALIZED);
|
||||
} catch (\Throwable $throwable) {
|
||||
$this->handleFailure($throwable, self::ACTION_FAILED_BUILD);
|
||||
} finally {
|
||||
$this->built = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Module ...$defaultModules Deprecated, use `addModule()` to add default modules.
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function boot(Module ...$defaultModules): bool
|
||||
{
|
||||
try {
|
||||
// Call build() if not called yet, and ensure any new module passed here is added
|
||||
// as well, throwing if the container was already built.
|
||||
$this->doBuild(...$defaultModules);
|
||||
|
||||
// Don't allow booting the application multiple times.
|
||||
$this->assertStatus(self::STATUS_MODULES_ADDED, 'boot application', '<');
|
||||
$this->assertStatus(self::STATUS_FAILED, 'boot application', '!=');
|
||||
|
||||
$this->progress(self::STATUS_MODULES_ADDED);
|
||||
|
||||
$this->doExecute();
|
||||
|
||||
$this->progress(self::STATUS_READY);
|
||||
|
||||
do_action(
|
||||
$this->hookName(self::ACTION_READY),
|
||||
$this
|
||||
);
|
||||
} catch (\Throwable $throwable) {
|
||||
$this->handleFailure($throwable, self::ACTION_FAILED_BOOT);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->progress(self::STATUS_BOOTED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Module ...$defaultModules
|
||||
* @return void
|
||||
*/
|
||||
private function doBuild(Module ...$defaultModules): void
|
||||
{
|
||||
if ($defaultModules) {
|
||||
$this->deprecatedArgument(
|
||||
sprintf(
|
||||
'Passing default modules to %1$s::boot() is deprecated since version 1.7.0.'
|
||||
. ' Please add modules via %1$s::addModule().',
|
||||
__CLASS__
|
||||
),
|
||||
__METHOD__,
|
||||
'1.7.0'
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->built) {
|
||||
array_map([$this, 'addModule'], $defaultModules);
|
||||
$this->build();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!$defaultModules
|
||||
|| ($this->status >= self::STATUS_MODULES_ADDED)
|
||||
|| ($this->statusIs(self::STATUS_FAILED))
|
||||
) {
|
||||
// if we don't have default modules, there's nothing to do, and if the status is beyond
|
||||
// "modules added" or is failed, we do nothing as well and let `boot()` throw.
|
||||
return;
|
||||
}
|
||||
|
||||
$backup = $this->status;
|
||||
|
||||
try {
|
||||
// simulate idle status to prevent `addModule()` from throwing
|
||||
// only if we don't have a container yet
|
||||
$this->hasContainer or $this->status = self::STATUS_IDLE;
|
||||
|
||||
foreach ($defaultModules as $defaultModule) {
|
||||
// If a module was added by `build()` or `addModule()` we can skip it, a
|
||||
// deprecation was trigger to make it noticeable without breakage
|
||||
if (!$this->moduleIs($defaultModule->id(), self::MODULE_ADDED)) {
|
||||
$this->addModule($defaultModule);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
$this->status = $backup;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Module $module
|
||||
* @param string $status
|
||||
* @return bool
|
||||
*/
|
||||
private function addModuleServices(Module $module, string $status): bool
|
||||
{
|
||||
$services = null;
|
||||
$addCallback = null;
|
||||
switch ($status) {
|
||||
case self::MODULE_REGISTERED:
|
||||
$services = $module instanceof ServiceModule ? $module->services() : null;
|
||||
$addCallback = [$this->containerConfigurator, 'addService'];
|
||||
break;
|
||||
case self::MODULE_REGISTERED_FACTORIES:
|
||||
$services = $module instanceof FactoryModule ? $module->factories() : null;
|
||||
$addCallback = [$this->containerConfigurator, 'addFactory'];
|
||||
break;
|
||||
case self::MODULE_EXTENDED:
|
||||
$services = $module instanceof ExtendingModule ? $module->extensions() : null;
|
||||
$addCallback = [$this->containerConfigurator, 'addExtension'];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$services) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
array_walk(
|
||||
$services,
|
||||
static function (callable $service, string $id) use ($addCallback, &$ids) {
|
||||
/** @var callable(string, callable) $addCallback */
|
||||
$addCallback($id, $service);
|
||||
/** @var list<string> $ids */
|
||||
$ids[] = $id;
|
||||
}
|
||||
);
|
||||
/** @var list<string> $ids */
|
||||
$this->moduleProgress($module->id(), $status, $ids);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function doExecute(): void
|
||||
{
|
||||
foreach ($this->executables as $executable) {
|
||||
$success = $executable->run($this->container());
|
||||
$this->moduleProgress(
|
||||
$executable->id(),
|
||||
$success
|
||||
? self::MODULE_EXECUTED
|
||||
: self::MODULE_EXECUTION_FAILED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moduleId
|
||||
* @param string $status
|
||||
* @param list<string>|null $serviceIds
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function moduleProgress(string $moduleId, string $status, ?array $serviceIds = null)
|
||||
{
|
||||
isset($this->moduleStatus[$status]) or $this->moduleStatus[$status] = [];
|
||||
$this->moduleStatus[$status][] = $moduleId;
|
||||
|
||||
if (!$serviceIds || !$this->properties->isDebug()) {
|
||||
$this->moduleStatus[self::MODULES_ALL][] = "{$moduleId} {$status}";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$description = sprintf('%s %s (%s)', $moduleId, $status, implode(', ', $serviceIds));
|
||||
$this->moduleStatus[self::MODULES_ALL][] = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function modulesStatus(): array
|
||||
{
|
||||
return $this->moduleStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, bool>
|
||||
*/
|
||||
public function connectedPackages(): array
|
||||
{
|
||||
return $this->connectedPackages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return bool
|
||||
*/
|
||||
public function isPackageConnected(string $packageName): bool
|
||||
{
|
||||
return $this->connectedPackages[$packageName] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moduleId
|
||||
* @param string $status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function moduleIs(string $moduleId, string $status): bool
|
||||
{
|
||||
return in_array($moduleId, $this->moduleStatus[$status] ?? [], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filter name to be used to extend modules of the plugin.
|
||||
*
|
||||
* If the plugin is single file `my-plugin.php` in plugins folder the filter name will be:
|
||||
* `inpsyde.modularity.my-plugin`.
|
||||
*
|
||||
* If the plugin is in a sub-folder e.g. `my-plugin/index.php` the filter name will be:
|
||||
* `inpsyde.modularity.my-plugin` anyway, so the file name is not relevant.
|
||||
*
|
||||
* @param string $suffix
|
||||
*
|
||||
* @return string
|
||||
* @see Package::name()
|
||||
*
|
||||
*/
|
||||
public function hookName(string $suffix = ''): string
|
||||
{
|
||||
$filter = self::HOOK_PREFIX . $this->properties->baseName();
|
||||
|
||||
if ($suffix) {
|
||||
$filter .= '.' . $suffix;
|
||||
}
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Properties
|
||||
*/
|
||||
public function properties(): Properties
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ContainerInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function container(): ContainerInterface
|
||||
{
|
||||
$this->assertStatus(self::STATUS_INITIALIZED, 'obtain the container instance', '>=');
|
||||
$this->hasContainer = true;
|
||||
|
||||
return $this->containerConfigurator->createReadOnlyContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
return $this->properties->baseName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*/
|
||||
private function progress(int $status): void
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function statusIs(int $status): bool
|
||||
{
|
||||
return $this->status === $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $throwable
|
||||
* @param Package::ACTION_FAILED_* $action
|
||||
* @return void
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function handleFailure(\Throwable $throwable, string $action): void
|
||||
{
|
||||
$this->progress(self::STATUS_FAILED);
|
||||
$hook = $this->hookName($action);
|
||||
did_action($hook) or do_action($hook, $throwable);
|
||||
|
||||
if ($this->properties->isDebug()) {
|
||||
throw $throwable;
|
||||
}
|
||||
|
||||
$this->lastError = $throwable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
* @param string $action
|
||||
* @param string $operator
|
||||
*
|
||||
* @throws \Exception
|
||||
* @psalm-suppress ArgumentTypeCoercion
|
||||
*/
|
||||
private function assertStatus(int $status, string $action, string $operator = '=='): void
|
||||
{
|
||||
if (!version_compare((string) $this->status, (string) $status, $operator)) {
|
||||
throw new \Exception(
|
||||
sprintf("Can't %s at this point of application.", $action),
|
||||
0,
|
||||
$this->lastError
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to WP's `_deprecated_argument()`, but executes regardless of WP_DEBUG and without
|
||||
* translated message (so without attempting loading translation files).
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $function
|
||||
* @param string $version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function deprecatedArgument(string $message, string $function, string $version): void
|
||||
{
|
||||
do_action('deprecated_argument_run', $function, $message, $version);
|
||||
|
||||
if (apply_filters('deprecated_argument_trigger_error', true)) {
|
||||
trigger_error($message, \E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties;
|
||||
|
||||
class BaseProperties implements Properties
|
||||
{
|
||||
/**
|
||||
* @var null|bool
|
||||
*/
|
||||
protected $isDebug = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $baseName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $basePath;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $baseUrl;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* @param string $baseName
|
||||
* @param string $basePath
|
||||
* @param string|null $baseUrl
|
||||
* @param array $properties
|
||||
*/
|
||||
protected function __construct(
|
||||
string $baseName,
|
||||
string $basePath,
|
||||
string $baseUrl = null,
|
||||
array $properties = []
|
||||
) {
|
||||
$baseName = $this->sanitizeBaseName($baseName);
|
||||
$basePath = (string) trailingslashit($basePath);
|
||||
if ($baseUrl) {
|
||||
$baseUrl = (string) trailingslashit($baseUrl);
|
||||
}
|
||||
|
||||
$this->baseName = $baseName;
|
||||
$this->basePath = $basePath;
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->properties = array_replace(Properties::DEFAULT_PROPERTIES, $properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function sanitizeBaseName(string $name): string
|
||||
{
|
||||
substr_count($name, '/') and $name = dirname($name);
|
||||
|
||||
return strtolower(pathinfo($name, PATHINFO_FILENAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function baseName(): string
|
||||
{
|
||||
return $this->baseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function basePath(): string
|
||||
{
|
||||
return $this->basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function baseUrl(): ?string
|
||||
{
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function author(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_AUTHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function authorUri(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_AUTHOR_URI);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function description(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_DESCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function textDomain(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_TEXTDOMAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function domainPath(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_DOMAIN_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function uri(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_URI);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function version(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function requiresWp(): ?string
|
||||
{
|
||||
$value = $this->get(self::PROP_REQUIRES_WP);
|
||||
|
||||
return $value && is_string($value) ? $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function requiresPhp(): ?string
|
||||
{
|
||||
$value = $this->get(self::PROP_REQUIRES_PHP);
|
||||
|
||||
return $value && is_string($value) ? $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function tags(): array
|
||||
{
|
||||
return (array) $this->get(self::PROP_TAGS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param null $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key, $default = null)
|
||||
{
|
||||
return $this->properties[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $key): bool
|
||||
{
|
||||
return isset($this->properties[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @see Properties::isDebug()
|
||||
*/
|
||||
public function isDebug(): bool
|
||||
{
|
||||
if ($this->isDebug === null) {
|
||||
$this->isDebug = defined('WP_DEBUG') && WP_DEBUG;
|
||||
}
|
||||
|
||||
return $this->isDebug;
|
||||
}
|
||||
}
|
|
@ -1,209 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties;
|
||||
|
||||
/**
|
||||
* Class LibraryProperties
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties
|
||||
*/
|
||||
class LibraryProperties extends BaseProperties
|
||||
{
|
||||
/**
|
||||
* Allowed configuration in composer.json "extra.modularity".
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public const EXTRA_KEYS = [
|
||||
self::PROP_DOMAIN_PATH,
|
||||
self::PROP_NAME,
|
||||
self::PROP_TEXTDOMAIN,
|
||||
self::PROP_URI,
|
||||
self::PROP_VERSION,
|
||||
self::PROP_REQUIRES_WP,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $composerJsonFile
|
||||
* @param string|null $baseUrl
|
||||
*
|
||||
* @return LibraryProperties
|
||||
*
|
||||
* @throws \Exception
|
||||
* @psalm-suppress MixedArrayAccess
|
||||
*/
|
||||
public static function new(string $composerJsonFile, ?string $baseUrl = null): LibraryProperties
|
||||
{
|
||||
if (!\is_file($composerJsonFile) || !\is_readable($composerJsonFile)) {
|
||||
throw new \Exception("File {$composerJsonFile} does not exist or is not readable.");
|
||||
}
|
||||
|
||||
$content = (string) file_get_contents($composerJsonFile);
|
||||
/** @var array $composerJsonData */
|
||||
$composerJsonData = json_decode($content, true);
|
||||
|
||||
$properties = Properties::DEFAULT_PROPERTIES;
|
||||
$properties[self::PROP_DESCRIPTION] = $composerJsonData['description'] ?? '';
|
||||
$properties[self::PROP_TAGS] = $composerJsonData['keywords'] ?? [];
|
||||
|
||||
$authors = $composerJsonData['authors'] ?? [];
|
||||
$names = [];
|
||||
foreach ((array) $authors as $author) {
|
||||
$name = $author['name'] ?? null;
|
||||
if ($name && is_string($name)) {
|
||||
$names[] = $name;
|
||||
}
|
||||
$url = $author['homepage'] ?? null;
|
||||
if ($url && !$properties['authorUri'] && is_string($url)) {
|
||||
$properties[self::PROP_AUTHOR_URI] = $url;
|
||||
}
|
||||
}
|
||||
if (count($names) > 0) {
|
||||
$properties[self::PROP_AUTHOR] = implode(', ', $names);
|
||||
}
|
||||
|
||||
// Custom settings which can be stored in composer.json "extra.modularity"
|
||||
$extra = $composerJsonData['extra']['modularity'] ?? [];
|
||||
foreach (self::EXTRA_KEYS as $key) {
|
||||
$properties[$key] = $extra[$key] ?? '';
|
||||
}
|
||||
|
||||
// PHP requirement in composer.json "require" or "require-dev"
|
||||
$properties[self::PROP_REQUIRES_PHP] = self::extractPhpVersion($composerJsonData);
|
||||
|
||||
// composer.json might have "version" in root
|
||||
$version = $composerJsonData['version'] ?? null;
|
||||
if ($version && is_string($version)) {
|
||||
$properties[self::PROP_VERSION] = $version;
|
||||
}
|
||||
|
||||
[$baseName, $name] = static::buildNames($composerJsonData);
|
||||
$basePath = dirname($composerJsonFile);
|
||||
if (empty($properties[self::PROP_NAME])) {
|
||||
$properties[self::PROP_NAME] = $name;
|
||||
}
|
||||
|
||||
return new self(
|
||||
$baseName,
|
||||
$basePath,
|
||||
$baseUrl,
|
||||
$properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $composerJsonData
|
||||
*
|
||||
* @return array{string, string}
|
||||
*/
|
||||
private static function buildNames(array $composerJsonData): array
|
||||
{
|
||||
$composerName = (string) ($composerJsonData['name'] ?? '');
|
||||
$packageNamePieces = explode('/', $composerName, 2);
|
||||
$basename = implode('-', $packageNamePieces);
|
||||
// "inpsyde/foo-bar-baz" => "Inpsyde Foo Bar Baz"
|
||||
$name = mb_convert_case(
|
||||
str_replace(['-', '_', '.'], ' ', implode(' ', $packageNamePieces)),
|
||||
MB_CASE_TITLE
|
||||
);
|
||||
|
||||
return [$basename, $name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check PHP version in require, require-dev.
|
||||
*
|
||||
* Attempt to parse requirements to find the _minimum_ accepted version (consistent with WP).
|
||||
* Composer requirements are parsed in a way that, for example:
|
||||
* `>=7.2` returns `7.2`
|
||||
* `^7.3` returns `7.3`
|
||||
* `5.6 || >= 7.1` returns `5.6`
|
||||
* `>= 7.1 < 8` returns `7.1`
|
||||
*
|
||||
* @param array $composerData
|
||||
* @param string $key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private static function extractPhpVersion(array $composerData, string $key = 'require'): ?string
|
||||
{
|
||||
$nextKey = ($key === 'require')
|
||||
? 'require-dev'
|
||||
: null;
|
||||
$base = (array) ($composerData[$key] ?? []);
|
||||
$requirement = $base['php'] ?? null;
|
||||
$version = ($requirement && is_string($requirement))
|
||||
? trim($requirement)
|
||||
: null;
|
||||
if (!$version) {
|
||||
return $nextKey
|
||||
? static::extractPhpVersion($composerData, $nextKey)
|
||||
: null;
|
||||
}
|
||||
|
||||
static $matcher;
|
||||
$matcher or $matcher = static function (string $version): ?string {
|
||||
$version = trim($version);
|
||||
if (!$version) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// versions range like `>= 7.2.4 < 8`
|
||||
if (preg_match('{>=?([\s0-9\.]+)<}', $version, $matches)) {
|
||||
return trim($matches[1], " \t\n\r\0\x0B.");
|
||||
}
|
||||
|
||||
// aliases like `dev-src#abcde as 7.4`
|
||||
if (preg_match('{as\s*([\s0-9\.]+)}', $version, $matches)) {
|
||||
return trim($matches[1], " \t\n\r\0\x0B.");
|
||||
}
|
||||
|
||||
// Basic requirements like 7.2, >=7.2, ^7.2, ~7.2
|
||||
if (preg_match('{^(?:[>=\s~\^]+)?([0-9\.]+)}', $version, $matches)) {
|
||||
return trim($matches[1], " \t\n\r\0\x0B.");
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
// support for simpler requirements like `7.3`, `>=7.4` or alternative like `5.6 || >=7`
|
||||
|
||||
$alternatives = explode('||', $version);
|
||||
$found = null;
|
||||
foreach ($alternatives as $alternative) {
|
||||
/** @var callable(string):?string $matcher */
|
||||
$itemFound = $matcher($alternative);
|
||||
if ($itemFound && (!$found || version_compare($itemFound, $found, '<'))) {
|
||||
$found = $itemFound;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
return $found;
|
||||
}
|
||||
|
||||
return $nextKey
|
||||
? static::extractPhpVersion($composerData, $nextKey)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return static
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function withBaseUrl(string $url): LibraryProperties
|
||||
{
|
||||
if ($this->baseUrl !== null) {
|
||||
throw new \Exception(sprintf('%s::$baseUrl property is not overridable.', __CLASS__));
|
||||
}
|
||||
|
||||
$this->baseUrl = trailingslashit($url);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties;
|
||||
|
||||
/**
|
||||
* Class PluginProperties
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties
|
||||
*
|
||||
* @psalm-suppress PossiblyFalseArgument, InvalidArgument
|
||||
*/
|
||||
class PluginProperties extends BaseProperties
|
||||
{
|
||||
/**
|
||||
* Custom properties for Plugins.
|
||||
*/
|
||||
public const PROP_NETWORK = 'network';
|
||||
/**
|
||||
* Available methods of Properties::__call()
|
||||
* from plugin headers.
|
||||
*
|
||||
* @link https://developer.wordpress.org/reference/functions/get_plugin_data/
|
||||
*/
|
||||
protected const HEADERS = [
|
||||
self::PROP_AUTHOR => 'Author',
|
||||
self::PROP_AUTHOR_URI => 'AuthorURI',
|
||||
self::PROP_DESCRIPTION => 'Description',
|
||||
self::PROP_DOMAIN_PATH => 'DomainPath',
|
||||
self::PROP_NAME => 'Name',
|
||||
self::PROP_TEXTDOMAIN => 'TextDomain',
|
||||
self::PROP_URI => 'PluginURI',
|
||||
self::PROP_VERSION => 'Version',
|
||||
self::PROP_REQUIRES_WP => 'RequiresWP',
|
||||
self::PROP_REQUIRES_PHP => 'RequiresPHP',
|
||||
|
||||
// additional headers
|
||||
self::PROP_NETWORK => 'Network',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pluginMainFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pluginBaseName;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $isMu;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $isActive;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $isNetworkActive;
|
||||
|
||||
/**
|
||||
* @param string $pluginMainFile
|
||||
*
|
||||
* @return PluginProperties
|
||||
*/
|
||||
public static function new(string $pluginMainFile): PluginProperties
|
||||
{
|
||||
return new self($pluginMainFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* PluginProperties constructor.
|
||||
*
|
||||
* @param string $pluginMainFile
|
||||
*/
|
||||
protected function __construct(string $pluginMainFile)
|
||||
{
|
||||
if (!function_exists('get_plugin_data')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
$pluginData = get_plugin_data($pluginMainFile);
|
||||
$properties = Properties::DEFAULT_PROPERTIES;
|
||||
|
||||
// Map pluginData to internal structure.
|
||||
foreach (self::HEADERS as $key => $pluginDataKey) {
|
||||
$properties[$key] = $pluginData[$pluginDataKey] ?? '';
|
||||
unset($pluginData[$pluginDataKey]);
|
||||
}
|
||||
$properties = array_merge($properties, $pluginData);
|
||||
|
||||
$this->pluginMainFile = wp_normalize_path($pluginMainFile);
|
||||
|
||||
$this->pluginBaseName = plugin_basename($pluginMainFile);
|
||||
$basePath = plugin_dir_path($pluginMainFile);
|
||||
$baseUrl = plugins_url('/', $pluginMainFile);
|
||||
|
||||
parent::__construct(
|
||||
$this->pluginBaseName,
|
||||
$basePath,
|
||||
$baseUrl,
|
||||
$properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function pluginMainFile(): string
|
||||
{
|
||||
return $this->pluginMainFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @psalm-suppress PossiblyFalseArgument
|
||||
*/
|
||||
public function network(): bool
|
||||
{
|
||||
return (bool) $this->get(self::PROP_NETWORK, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
if ($this->isActive === null) {
|
||||
if (!function_exists('is_plugin_active')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
$this->isActive = is_plugin_active($this->pluginBaseName);
|
||||
}
|
||||
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isNetworkActive(): bool
|
||||
{
|
||||
if ($this->isNetworkActive === null) {
|
||||
if (!function_exists('is_plugin_active_for_network')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
$this->isNetworkActive = is_plugin_active_for_network($this->pluginBaseName);
|
||||
}
|
||||
|
||||
return $this->isNetworkActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isMuPlugin(): bool
|
||||
{
|
||||
if ($this->isMu === null) {
|
||||
/**
|
||||
* @psalm-suppress UndefinedConstant
|
||||
* @psalm-suppress MixedArgument
|
||||
*/
|
||||
$muPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
|
||||
$this->isMu = strpos($this->pluginMainFile, $muPluginDir) === 0;
|
||||
}
|
||||
|
||||
return $this->isMu;
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties;
|
||||
|
||||
interface Properties
|
||||
{
|
||||
public const PROP_AUTHOR = 'author';
|
||||
public const PROP_AUTHOR_URI = 'authorUri';
|
||||
public const PROP_DESCRIPTION = 'description';
|
||||
public const PROP_DOMAIN_PATH = 'domainPath';
|
||||
public const PROP_NAME = 'name';
|
||||
public const PROP_TEXTDOMAIN = 'textDomain';
|
||||
public const PROP_URI = 'uri';
|
||||
public const PROP_VERSION = 'version';
|
||||
public const PROP_REQUIRES_WP = 'requiresWp';
|
||||
public const PROP_REQUIRES_PHP = 'requiresPhp';
|
||||
public const PROP_TAGS = 'tags';
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public const DEFAULT_PROPERTIES = [
|
||||
self::PROP_AUTHOR => '',
|
||||
self::PROP_AUTHOR_URI => '',
|
||||
self::PROP_DESCRIPTION => '',
|
||||
self::PROP_DOMAIN_PATH => '',
|
||||
self::PROP_NAME => '',
|
||||
self::PROP_TEXTDOMAIN => '',
|
||||
self::PROP_URI => '',
|
||||
self::PROP_VERSION => '',
|
||||
self::PROP_REQUIRES_WP => null,
|
||||
self::PROP_REQUIRES_PHP => null,
|
||||
self::PROP_TAGS => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param null $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key, $default = null);
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $key): bool;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDebug(): bool;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function baseName(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function basePath(): string;
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function baseUrl(): ?string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function author(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function authorUri(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function description(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function textDomain(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function domainPath(): string;
|
||||
|
||||
/**
|
||||
* The name of the plugin, theme or library.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name(): string;
|
||||
|
||||
/**
|
||||
* The home page of the plugin, theme or library.
|
||||
* @return string
|
||||
*/
|
||||
public function uri(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function version(): string;
|
||||
|
||||
/**
|
||||
* Optional. Specify the minimum required WordPress version.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function requiresWp(): ?string;
|
||||
|
||||
/**
|
||||
* Optional. Specify the minimum required PHP version.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function requiresPhp(): ?string;
|
||||
|
||||
/**
|
||||
* Optional. Currently, only available for Theme and Library.
|
||||
* Plugins do not have support for "tags"/"keywords" in header.
|
||||
*
|
||||
* @link https://developer.wordpress.org/reference/classes/wp_theme/#properties
|
||||
* @link https://getcomposer.org/doc/04-schema.md#keywords
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tags(): array;
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties;
|
||||
|
||||
/**
|
||||
* Class ThemeProperties
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Properties
|
||||
*
|
||||
* @psalm-suppress PossiblyFalseArgument, InvalidArgument
|
||||
*/
|
||||
class ThemeProperties extends BaseProperties
|
||||
{
|
||||
/**
|
||||
* Additional properties specific for themes.
|
||||
*/
|
||||
public const PROP_STATUS = 'status';
|
||||
public const PROP_TEMPLATE = 'template';
|
||||
/**
|
||||
* Available methods of Properties::__call()
|
||||
* from theme headers.
|
||||
*
|
||||
* @link https://developer.wordpress.org/reference/classes/wp_theme/
|
||||
*/
|
||||
protected const HEADERS = [
|
||||
self::PROP_AUTHOR => 'Author',
|
||||
self::PROP_AUTHOR_URI => 'AuthorURI',
|
||||
self::PROP_DESCRIPTION => 'Description',
|
||||
self::PROP_DOMAIN_PATH => 'DomainPath',
|
||||
self::PROP_NAME => 'Name',
|
||||
self::PROP_TEXTDOMAIN => 'TextDomain',
|
||||
self::PROP_URI => 'ThemeURI',
|
||||
self::PROP_VERSION => 'Version',
|
||||
self::PROP_REQUIRES_WP => 'RequiresWP',
|
||||
self::PROP_REQUIRES_PHP => 'RequiresPHP',
|
||||
|
||||
// additional headers
|
||||
self::PROP_STATUS => 'Status',
|
||||
self::PROP_TAGS => 'Tags',
|
||||
self::PROP_TEMPLATE => 'Template',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $themeDirectory
|
||||
*
|
||||
* @return ThemeProperties
|
||||
*/
|
||||
public static function new(string $themeDirectory): ThemeProperties
|
||||
{
|
||||
return new self($themeDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* ThemeProperties constructor.
|
||||
*
|
||||
* @param string $themeDirectory
|
||||
*/
|
||||
protected function __construct(string $themeDirectory)
|
||||
{
|
||||
if (!function_exists('wp_get_theme')) {
|
||||
require_once ABSPATH . 'wp-includes/theme.php';
|
||||
}
|
||||
|
||||
$theme = wp_get_theme($themeDirectory);
|
||||
$properties = Properties::DEFAULT_PROPERTIES;
|
||||
|
||||
foreach (self::HEADERS as $key => $themeKey) {
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
$properties[$key] = $theme->get($themeKey) ?? '';
|
||||
}
|
||||
|
||||
$baseName = $theme->get_stylesheet();
|
||||
$basePath = $theme->get_stylesheet_directory();
|
||||
$baseUrl = (string) trailingslashit($theme->get_stylesheet_directory_uri());
|
||||
|
||||
parent::__construct(
|
||||
$baseName,
|
||||
$basePath,
|
||||
$baseUrl,
|
||||
$properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the theme is published.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function status(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_STATUS);
|
||||
}
|
||||
|
||||
public function template(): string
|
||||
{
|
||||
return (string) $this->get(self::PROP_TEMPLATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isChildTheme(): bool
|
||||
{
|
||||
return (bool) $this->template();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCurrentTheme(): bool
|
||||
{
|
||||
return get_stylesheet() === $this->baseName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ThemeProperties|null
|
||||
*/
|
||||
public function parentThemeProperties(): ?ThemeProperties
|
||||
{
|
||||
$template = $this->template();
|
||||
if (!$template) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parent = wp_get_theme($template, get_theme_root($template));
|
||||
|
||||
return static::new($parent->get_template_directory());
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Interop\Container;
|
||||
|
||||
/**
|
||||
* A service provider provides entries to a container.
|
||||
*/
|
||||
interface ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Returns a list of all container entries registered by this service provider.
|
||||
*
|
||||
* - the key is the entry name
|
||||
* - the value is a callable that will return the entry, aka the **factory**
|
||||
*
|
||||
* Factories have the following signature:
|
||||
* function(\WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container)
|
||||
*
|
||||
* @return callable[]
|
||||
*/
|
||||
public function getFactories();
|
||||
|
||||
/**
|
||||
* Returns a list of all container entries extended by this service provider.
|
||||
*
|
||||
* - the key is the entry name
|
||||
* - the value is a callable that will return the modified entry
|
||||
*
|
||||
* Callables have the following signature:
|
||||
* function(WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container, $previous)
|
||||
* or function(WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface $container, $previous = null)
|
||||
*
|
||||
* About factories parameters:
|
||||
*
|
||||
* - the container (instance of `WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface`)
|
||||
* - the entry to be extended. If the entry to be extended does not exist and the parameter is nullable, `null` will be passed.
|
||||
*
|
||||
* @return callable[]
|
||||
*/
|
||||
public function getExtensions();
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Psr\Container;
|
||||
|
||||
/**
|
||||
* Base interface representing a generic exception in a container.
|
||||
*/
|
||||
interface ContainerExceptionInterface
|
||||
{
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Psr\Container;
|
||||
|
||||
/**
|
||||
* Describes the interface of a container that exposes methods to read its entries.
|
||||
*/
|
||||
interface ContainerInterface
|
||||
{
|
||||
/**
|
||||
* Finds an entry of the container by its identifier and returns it.
|
||||
*
|
||||
* @param string $id Identifier of the entry to look for.
|
||||
*
|
||||
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
|
||||
* @throws ContainerExceptionInterface Error while retrieving the entry.
|
||||
*
|
||||
* @return mixed Entry.
|
||||
*/
|
||||
public function get(string $id);
|
||||
|
||||
/**
|
||||
* Returns true if the container can return an entry for the given identifier.
|
||||
* Returns false otherwise.
|
||||
*
|
||||
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
|
||||
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
|
||||
*
|
||||
* @param string $id Identifier of the entry to look for.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $id);
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Vendor\Psr\Container;
|
||||
|
||||
/**
|
||||
* No entry was found in the container.
|
||||
*/
|
||||
interface NotFoundExceptionInterface extends ContainerExceptionInterface
|
||||
{
|
||||
}
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\AdminNotices;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Renderer\Renderer;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Renderer\RendererInterface;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
||||
|
|
|
@ -9,11 +9,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\AdminNotices;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class AdminNotices
|
||||
|
|
|
@ -28,7 +28,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\RefundPayerFactory;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerPayableBreakdownFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingOptionFactory;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
|
||||
|
|
|
@ -12,11 +12,11 @@ namespace WooCommerce\PayPalCommerce\ApiClient;
|
|||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderTransient;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Exception;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class ApplicationContextRepository
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace WooCommerce\PayPalCommerce\Applepay;
|
|||
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use WooCommerce\PayPalCommerce\Applepay\Helper\ApmApplies;
|
|||
use WooCommerce\PayPalCommerce\Applepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'applepay.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
|
|
|
@ -17,11 +17,11 @@ use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
|||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Blocks;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'wcgateway.button.locations' => function ( array $locations, ContainerInterface $container ): array {
|
||||
|
|
|
@ -10,7 +10,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Blocks;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'blocks.url' => static function ( ContainerInterface $container ): string {
|
||||
|
|
|
@ -12,11 +12,11 @@ namespace WooCommerce\PayPalCommerce\Blocks;
|
|||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class BlocksModule
|
||||
|
|
|
@ -19,7 +19,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
|||
use WooCommerce\PayPalCommerce\Button\Validation\CheckoutFormValidator;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\DisabledSmartButton;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||
|
|
|
@ -21,11 +21,11 @@ use WooCommerce\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
|
|||
use WooCommerce\PayPalCommerce\Button\Endpoint\DataClientIdEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\StartPayPalVaultingEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class ButtonModule
|
||||
|
|
|
@ -10,7 +10,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||
|
||||
use WooCommerce\PayPalCommerce\CardFields\Helper\CardFieldsApplies;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'card-fields.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
|
|
|
@ -9,11 +9,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Compat;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Compat\Assets\CompatAssets;
|
||||
|
||||
return array(
|
||||
|
|
|
@ -9,11 +9,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Compat;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\Compat\Assets\CompatAssets;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace WooCommerce\PayPalCommerce\Googlepay;
|
|||
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\PropertiesDictionary;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
|||
use WooCommerce\PayPalCommerce\Googlepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
|||
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Onboarding;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Onboarding;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class Environment
|
||||
|
|
|
@ -13,11 +13,11 @@ use WooCommerce\PayPalCommerce\Onboarding\Endpoint\UpdateSignupLinksEndpoint;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class OnboardingModule
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Onboarding;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Onboarding;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class State
|
||||
|
|
|
@ -16,7 +16,7 @@ use WooCommerce\PayPalCommerce\OrderTracking\Integration\WcShippingTaxIntegratio
|
|||
use WooCommerce\PayPalCommerce\OrderTracking\Integration\YithShipmentIntegration;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactory;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Assets\OrderEditPageAssets;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\OrderTracking;
|
||||
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Assets\OrderEditPageAssets;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
||||
|
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\PayPalSubscriptions;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'paypal-subscriptions.deactivate-plan-endpoint' => static function ( ContainerInterface $container ): DeactivatePlanEndpoint {
|
||||
|
|
|
@ -22,11 +22,11 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingSubscriptions;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
|
|
|
@ -13,7 +13,7 @@ use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CaptureCardPayment;
|
|||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentToken;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreateSetupToken;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Helper\SavePaymentMethodsApplies;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'save-payment-methods.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
|
|
|
@ -22,11 +22,11 @@ use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
|||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CaptureCardPayment;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentToken;
|
||||
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreateSetupToken;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use Inpsyde\Modularity\Module\ServiceModule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue