API.php
6 months ago
AbstractListingEndpoint.php
3 weeks ago
ApiException.php
2 months ago
Endpoint.php
3 months ago
EndpointContainer.php
3 years ago
ErrorResponse.php
3 years ago
Exception.php
3 years ago
ListingRequestValidationTrait.php
1 month ago
Request.php
3 years ago
Response.php
1 year ago
index.php
3 years ago
EndpointContainer.php
29 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\API\REST; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\InvalidStateException; |
| 9 | use MailPoetVendor\Psr\Container\ContainerInterface; |
| 10 | |
| 11 | class EndpointContainer { |
| 12 | /** @var ContainerInterface */ |
| 13 | private $container; |
| 14 | |
| 15 | public function __construct( |
| 16 | ContainerInterface $container |
| 17 | ) { |
| 18 | $this->container = $container; |
| 19 | } |
| 20 | |
| 21 | public function get(string $class): Endpoint { |
| 22 | $endpoint = $this->container->get($class); |
| 23 | if (!$endpoint instanceof Endpoint) { |
| 24 | throw new InvalidStateException(sprintf("Class '%s' doesn't implement '%s'", $class, Endpoint::class)); |
| 25 | } |
| 26 | return $endpoint; |
| 27 | } |
| 28 | } |
| 29 |