1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ServiceContainer.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\v2\IoC;
4
5use Bitrix\Catalog\v2\Facade\Repository;
6use Bitrix\Catalog\v2\Iblock\IblockInfo;
7use Bitrix\Catalog\v2\Product\ProductFactory;
8use Bitrix\Catalog\v2\Product\ProductRepositoryContract;
9use Bitrix\Catalog\v2\Sku\SkuFactory;
10use Bitrix\Catalog\v2\Sku\SkuRepositoryContract;
11use Bitrix\Main\ObjectNotFoundException;
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
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
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)
Определения ContainerBuilder.php:100
const PRODUCT_FACTORY
Определения Dependency.php:46
const REPOSITORY_FACADE
Определения Dependency.php:44
const PRODUCT_REPOSITORY
Определения Dependency.php:47
const SKU_REPOSITORY
Определения Dependency.php:53
static getProductFactory(int $iblockId)
Определения ServiceContainer.php:79
static make($id, array $args=[])
Определения ServiceContainer.php:52
static getSkuFactory(int $iblockId)
Определения ServiceContainer.php:144
static getSkuRepository(int $iblockId)
Определения ServiceContainer.php:123
static getIblockInfo(int $iblockId)
Определения ServiceContainer.php:61
static getProductRepository(int $iblockId)
Определения ServiceContainer.php:105
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$iblockId
Определения iblock_catalog_edit.php:30