1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ServiceContainer.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Rest\Service;
6
7use Bitrix\Main\DI\ServiceLocator;
8use Bitrix\Main\ObjectNotFoundException;
9use Bitrix\Rest\Repository\AppRepository;
10use Bitrix\Rest\Repository\IntegrationRepository;
11use Psr\Container\ContainerInterface;
12use Psr\Container\NotFoundExceptionInterface;
13use Bitrix\Rest\Contract;
14
15class ServiceContainer implements ContainerInterface
16{
17 private static ServiceContainer $instance;
18 private ServiceLocator $serviceLocator;
19 private string $prefix;
20
21 private function __construct()
22 {
23 $this->serviceLocator = ServiceLocator::getInstance();
24 $this->prefix = 'rest.service.';
25 }
26
27 private function __clone()
28 {}
29
30 public static function getInstance(): self
31 {
32 if (!isset(self::$instance))
33 {
34 self::$instance = new self();
35 }
36
37 return self::$instance;
38 }
39
40 public function has(string $id): bool
41 {
42 return $this->serviceLocator->has($this->prefix . $id);
43 }
44
49 public function get(string $id): mixed
50 {
51 return $this->serviceLocator->get($this->prefix . $id);
52 }
53
54 public function getAPAuthPasswordService(): Contract\Service\APAuth\PasswordService
55 {
56 return $this->get('apauth.password');
57 }
58
60 {
61 return $this->get('app');
62 }
63
65 {
66 return $this->get('integration');
67 }
68
69 public function getAPAuthPermissionService(): Contract\Service\APAuth\PermissionService
70 {
71 return $this->get('apauth.permission');
72 }
73}