API.php
27 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\API; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\DI\ContainerWrapper; |
| 9 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
| 10 | |
| 11 | class API { |
| 12 | /** |
| 13 | * @param string $version |
| 14 | * @return \MailPoet\API\MP\v1\API |
| 15 | * @throws \Exception |
| 16 | */ |
| 17 | public static function MP($version) { |
| 18 | /** @var class-string<\MailPoet\API\MP\v1\API> $apiClass */ |
| 19 | $apiClass = sprintf('%s\MP\%s\API', __NAMESPACE__, $version); |
| 20 | try { |
| 21 | return ContainerWrapper::getInstance()->get($apiClass); |
| 22 | } catch (ServiceNotFoundException $e) { |
| 23 | throw new \Exception(__('Invalid API version.', 'mailpoet')); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 |