mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor app container to modularity.
This commit is contained in:
parent
42f995222d
commit
3be8563870
22 changed files with 2367 additions and 45 deletions
21
lib/packages/Inpsyde/Modularity/Module/ExecutableModule.php
Normal file
21
lib/packages/Inpsyde/Modularity/Module/ExecutableModule.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?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;
|
||||
}
|
24
lib/packages/Inpsyde/Modularity/Module/ExtendingModule.php
Normal file
24
lib/packages/Inpsyde/Modularity/Module/ExtendingModule.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?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;
|
||||
}
|
18
lib/packages/Inpsyde/Modularity/Module/FactoryModule.php
Normal file
18
lib/packages/Inpsyde/Modularity/Module/FactoryModule.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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;
|
||||
}
|
20
lib/packages/Inpsyde/Modularity/Module/Module.php
Normal file
20
lib/packages/Inpsyde/Modularity/Module/Module.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?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;
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?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__;
|
||||
}
|
||||
}
|
21
lib/packages/Inpsyde/Modularity/Module/ServiceModule.php
Normal file
21
lib/packages/Inpsyde/Modularity/Module/ServiceModule.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue