Refactor app container to modularity.

This commit is contained in:
Pedro Silva 2023-11-23 17:43:56 +00:00
parent 42f995222d
commit 3be8563870
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
22 changed files with 2367 additions and 45 deletions

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View file

@ -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__;
}
}

View 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;
}