Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
typefactory.php
1<?php
2
4
8abstract class TypeFactory
9{
10 protected $itemEntities = [];
11
15 abstract public function getTypeDataClass(): string;
16
20 abstract public function getItemPrototypeDataClass(): string;
21
22 abstract public function getCode(): string;
23
28 public function getItemDataClass($type): string
29 {
30 return $this->getItemEntity($type)->getDataClass();
31 }
32
33 public function getItemEntity($type): \Bitrix\Main\ORM\Entity
34 {
35 $typeData = $this->getTypeDataClass()::resolveType($type);
36 if(!empty($typeData) && isset($this->itemEntities[$typeData['ID']]))
37 {
38 return $this->itemEntities[$typeData['ID']];
39 }
40
41 $entity = $this->getTypeDataClass()::compileEntity($type);
42 $this->itemEntities[$typeData['ID']] = $entity;
43
44 return $entity;
45 }
46
50 public function getItemParentClass(): string
51 {
52 return Item::class;
53 }
54
55 public function getUserFieldEntityPrefix(): string
56 {
57 $code = $this->getCode();
58 return static::getPrefixByCode($code).'_';
59 }
60
61 public function getUserFieldEntityId(int $typeId): string
62 {
63 return $this->getUserFieldEntityPrefix().$typeId;
64 }
65
66 public static function getCodeByPrefix(string $prefix): string
67 {
68 return mb_strtolower($prefix);
69 }
70
71 public static function getPrefixByCode(string $code): string
72 {
73 return mb_strtoupper($code);
74 }
75
76 public function prepareIdentifier($identifier)
77 {
78 return (int)$identifier;
79 }
80}