Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ServiceContainer.php
1<?php
2
4
12
22{
24 private static $container;
25
26 private function __construct()
27 {
28 }
29
30 public static function getContainer(): ContainerContract
31 {
32 if (static::$container === null)
33 {
34 // ToDo make events for customization
35 static::$container = ContainerBuilder::buildFromConfig();
36 }
37
38 return static::$container;
39 }
40
44 public static function get($id, array $args = [])
45 {
46 return static::getContainer()->get($id, $args);
47 }
48
52 public static function make($id, array $args = [])
53 {
54 return static::getContainer()->make($id, $args);
55 }
56
61 public static function getIblockInfo(int $iblockId): ?IblockInfo
62 {
63 try
64 {
65 $iblockInfo = static::get(Dependency::IBLOCK_INFO, compact('iblockId'));
66 }
67 catch (ObjectNotFoundException $exception)
68 {
69 $iblockInfo = null;
70 }
71
72 return $iblockInfo;
73 }
74
79 public static function getProductFactory(int $iblockId): ?ProductFactory
80 {
81 $iblockInfo = static::getIblockInfo($iblockId);
82
83 if ($iblockInfo)
84 {
85 $iblockId = $iblockInfo->getProductIblockId();
86
87 return static::get(Dependency::PRODUCT_FACTORY, compact('iblockId'));
88 }
89
90 return null;
91 }
92
96 public static function getRepositoryFacade(): Repository
97 {
98 return static::make(Dependency::REPOSITORY_FACADE);
99 }
100
105 public static function getProductRepository(int $iblockId): ?ProductRepositoryContract
106 {
107 $iblockInfo = static::getIblockInfo($iblockId);
108
109 if ($iblockInfo)
110 {
111 $iblockId = $iblockInfo->getProductIblockId();
112
113 return static::make(Dependency::PRODUCT_REPOSITORY, compact('iblockId'));
114 }
115
116 return null;
117 }
118
123 public static function getSkuRepository(int $iblockId): ?SkuRepositoryContract
124 {
125 $iblockInfo = static::getIblockInfo($iblockId);
126
127 if ($iblockInfo && $iblockInfo->canHaveSku())
128 {
129 $iblockId = $iblockInfo->getProductIblockId();
130
131 return static::make(Dependency::SKU_REPOSITORY, compact('iblockId'));
132 }
133
134 return null;
135 }
136
144 public static function getSkuFactory(int $iblockId): ?SkuFactory
145 {
146 $iblockInfo = static::getIblockInfo($iblockId);
147
148 if ($iblockInfo)
149 {
150 $iblockId = $iblockInfo->getSkuIblockId();
151 if ($iblockId)
152 {
153 return static::get(Dependency::SKU_FACTORY, compact('iblockId'));
154 }
155 }
156
157 return null;
158 }
159}
static buildFromConfig(string $customPath=null)