Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entityfabric.php
1<?php
3use \Bitrix\Main;
5{
6 protected static $repo = [];
7
12 public static function getById($id)
13 {
14 if (!array_key_exists(__CLASS__, self::$repo))
15 {
16 self::$repo[__CLASS__] = [];
17 }
18 $id = intval($id);
19 if (!array_key_exists($id, self::$repo[__CLASS__]))
20 {
21 try
22 {
23 self::$repo[__CLASS__][$id] = new static($id);
24 }
25 catch (Main\ObjectNotFoundException $exception)
26 {
27 return null;
28 }
29 }
30 return self::$repo[__CLASS__][$id];
31 }
32
33 public function destroy()
34 {
35 if (array_key_exists(__CLASS__, self::$repo))
36 {
37 foreach (self::$repo[__CLASS__] as $key => $object)
38 {
39 if ($object === $this)
40 {
41 unset(self::$repo[__CLASS__][$key]);
42// AddMessage2Log("Object: ".__CLASS__." $key were destroyed.");
43 return;
44 }
45 }
46 }
47 }
52 public static function getInstance($object)
53 {
54 if ($object instanceof static)
55 {
56 return $object;
57 }
58 return static::getById($object);
59 }
60}