Rename endpoint "factory" to a more exact "container"
[MAILPOET-4207]
This commit is contained in:
@ -13,17 +13,17 @@ class API {
|
||||
private const PREFIX = 'mailpoet/v1/automation';
|
||||
private const WP_REST_API_INIT_ACTION = 'rest_api_init';
|
||||
|
||||
/** @var EndpointFactory */
|
||||
private $endpointFactory;
|
||||
/** @var EndpointContainer */
|
||||
private $endpointContainer;
|
||||
|
||||
/** @var WordPress */
|
||||
private $wordPress;
|
||||
|
||||
public function __construct(
|
||||
EndpointFactory $endpointFactory,
|
||||
EndpointContainer $endpointContainer,
|
||||
WordPress $wordPress
|
||||
) {
|
||||
$this->endpointFactory = $endpointFactory;
|
||||
$this->endpointContainer = $endpointContainer;
|
||||
$this->wordPress = $wordPress;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ class API {
|
||||
'methods' => $method,
|
||||
'callback' => function (WP_REST_Request $wpRequest) use ($endpointClass) {
|
||||
try {
|
||||
$endpoint = $this->endpointFactory->createEndpoint($endpointClass);
|
||||
$endpoint = $this->endpointContainer->get($endpointClass);
|
||||
$request = new Request($wpRequest);
|
||||
return $endpoint->handle($request);
|
||||
} catch (Throwable $e) {
|
||||
@ -70,7 +70,7 @@ class API {
|
||||
}
|
||||
},
|
||||
'permission_callback' => function () use ($endpointClass) {
|
||||
$endpoint = $this->endpointFactory->createEndpoint($endpointClass);
|
||||
$endpoint = $this->endpointContainer->get($endpointClass);
|
||||
return $endpoint->checkPermissions();
|
||||
},
|
||||
'args' => $schema,
|
||||
|
@ -5,7 +5,7 @@ namespace MailPoet\Automation\Engine\API;
|
||||
use MailPoet\InvalidStateException;
|
||||
use MailPoetVendor\Psr\Container\ContainerInterface;
|
||||
|
||||
class EndpointFactory {
|
||||
class EndpointContainer {
|
||||
/** @var ContainerInterface */
|
||||
private $container;
|
||||
|
||||
@ -15,7 +15,7 @@ class EndpointFactory {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function createEndpoint(string $class): Endpoint {
|
||||
public function get(string $class): Endpoint {
|
||||
$endpoint = $this->container->get($class);
|
||||
if (!$endpoint instanceof Endpoint) {
|
||||
throw new InvalidStateException(sprintf("Class '%s' doesn't implement '%s'", $class, Endpoint::class));
|
@ -105,7 +105,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\AutomaticEmails\WooCommerce\Events\PurchasedProduct::class)->setPublic(true);
|
||||
// Automation
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\API::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\EndpointFactory::class)
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\EndpointContainer::class)
|
||||
->setPublic(true)
|
||||
->setArgument('$container', new Reference(ContainerWrapper::class));
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\CreateWorkflowController::class)->setPublic(true);
|
||||
|
@ -6,7 +6,7 @@ require_once __DIR__ . '/../../Test.php';
|
||||
require_once __DIR__ . '/Endpoint.php';
|
||||
|
||||
use MailPoet\Automation\Engine\API\API;
|
||||
use MailPoet\Automation\Engine\API\EndpointFactory;
|
||||
use MailPoet\Automation\Engine\API\EndpointContainer;
|
||||
use MailPoet\Automation\Engine\API\Request;
|
||||
use MailPoet\Automation\Engine\WordPress;
|
||||
use MailPoet\REST\Automation\API\Endpoints\Endpoint;
|
||||
@ -114,8 +114,8 @@ class EndpointTest extends Test {
|
||||
rest_get_server();
|
||||
|
||||
return new API(
|
||||
$this->make(EndpointFactory::class, [
|
||||
'createEndpoint' => function () use ($requestCallback) {
|
||||
$this->make(EndpointContainer::class, [
|
||||
'get' => function () use ($requestCallback) {
|
||||
return new Endpoint($requestCallback);
|
||||
}
|
||||
]),
|
||||
|
Reference in New Issue
Block a user