Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ServiceContainer.php
1
<?php
2
3
namespace
Bitrix\Catalog\v2\IoC
;
4
5
use
Bitrix\Catalog\v2\Facade\Repository
;
6
use
Bitrix\Catalog\v2\Iblock\IblockInfo
;
7
use
Bitrix\Catalog\v2\Product\ProductFactory
;
8
use
Bitrix\Catalog\v2\Product\ProductRepositoryContract
;
9
use
Bitrix\Catalog\v2\Sku\SkuFactory
;
10
use
Bitrix\Catalog\v2\Sku\SkuRepositoryContract
;
11
use
Bitrix\Main\ObjectNotFoundException
;
12
21
final
class
ServiceContainer
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
}
Bitrix\Catalog\v2\Facade\Repository
Definition
Repository.php:18
Bitrix\Catalog\v2\Iblock\IblockInfo
Definition
IblockInfo.php:17
Bitrix\Catalog\v2\IoC\ContainerBuilder\buildFromConfig
static buildFromConfig(string $customPath=null)
Definition
ContainerBuilder.php:100
Bitrix\Catalog\v2\IoC\Dependency\SKU_FACTORY
const SKU_FACTORY
Definition
Dependency.php:52
Bitrix\Catalog\v2\IoC\Dependency\PRODUCT_FACTORY
const PRODUCT_FACTORY
Definition
Dependency.php:46
Bitrix\Catalog\v2\IoC\Dependency\REPOSITORY_FACADE
const REPOSITORY_FACADE
Definition
Dependency.php:44
Bitrix\Catalog\v2\IoC\Dependency\PRODUCT_REPOSITORY
const PRODUCT_REPOSITORY
Definition
Dependency.php:47
Bitrix\Catalog\v2\IoC\Dependency\SKU_REPOSITORY
const SKU_REPOSITORY
Definition
Dependency.php:53
Bitrix\Catalog\v2\IoC\Dependency\IBLOCK_INFO
const IBLOCK_INFO
Definition
Dependency.php:42
Bitrix\Catalog\v2\IoC\ServiceContainer
Definition
ServiceContainer.php:22
Bitrix\Catalog\v2\IoC\ServiceContainer\getProductFactory
static getProductFactory(int $iblockId)
Definition
ServiceContainer.php:79
Bitrix\Catalog\v2\IoC\ServiceContainer\make
static make($id, array $args=[])
Definition
ServiceContainer.php:52
Bitrix\Catalog\v2\IoC\ServiceContainer\getSkuFactory
static getSkuFactory(int $iblockId)
Definition
ServiceContainer.php:144
Bitrix\Catalog\v2\IoC\ServiceContainer\getSkuRepository
static getSkuRepository(int $iblockId)
Definition
ServiceContainer.php:123
Bitrix\Catalog\v2\IoC\ServiceContainer\getIblockInfo
static getIblockInfo(int $iblockId)
Definition
ServiceContainer.php:61
Bitrix\Catalog\v2\IoC\ServiceContainer\getProductRepository
static getProductRepository(int $iblockId)
Definition
ServiceContainer.php:105
Bitrix\Catalog\v2\IoC\ServiceContainer\getContainer
static getContainer()
Definition
ServiceContainer.php:30
Bitrix\Catalog\v2\IoC\ServiceContainer\getRepositoryFacade
static getRepositoryFacade()
Definition
ServiceContainer.php:96
Bitrix\Catalog\v2\Product\ProductFactory
Definition
ProductFactory.php:18
Bitrix\Catalog\v2\Sku\SkuFactory
Definition
SkuFactory.php:19
Bitrix\Main\ObjectNotFoundException
Definition
exception.php:203
Bitrix\Catalog\v2\IoC\ContainerContract
Definition
ContainerContract.php:15
Bitrix\Catalog\v2\Product\ProductRepositoryContract
Definition
ProductRepositoryContract.php:16
Bitrix\Catalog\v2\Sku\SkuRepositoryContract
Definition
SkuRepositoryContract.php:18
Bitrix\Catalog\v2\IoC
Definition
Container.php:3
modules
catalog
lib
v2
IoC
ServiceContainer.php
Создано системой
1.10.0