1 | <?php |
||
21 | abstract class BaseObject |
||
22 | { |
||
23 | /** @var string */ |
||
24 | private $name; |
||
25 | |||
26 | /** @var UserContext */ |
||
27 | private $context; |
||
28 | |||
29 | /** @var array */ |
||
30 | private $cache = []; |
||
31 | |||
32 | /** |
||
33 | * @param string $name Canonical name for the object |
||
34 | * @param UserContext $context Context within which the object is valid |
||
35 | */ |
||
36 | protected function __construct($name, UserContext $context) |
||
41 | |||
42 | /** |
||
43 | * Clear the object's internal cache. |
||
44 | */ |
||
45 | public function clearCache() |
||
49 | |||
50 | /** |
||
51 | * Retrieves an item from the internal cache. |
||
52 | * |
||
53 | * @param string $key Key to retrieve |
||
54 | * @param callable|mixed $default Either a callback or an explicit default value |
||
55 | * @return mixed Cached value |
||
56 | */ |
||
57 | protected function getCache($key, $default) |
||
64 | |||
65 | /** |
||
66 | * Retrieves a keyed item from inside a cache item. |
||
67 | * |
||
68 | * @param string $key |
||
69 | * @param string $item |
||
70 | * @param callable|mixed $defaultKey |
||
71 | * @param mixed|null $defaultItem |
||
72 | * @return mixed Cached value |
||
73 | * |
||
74 | * @codeCoverageIgnore |
||
75 | */ |
||
76 | protected function getCacheItem($key, $item, $defaultKey, $defaultItem = null) |
||
86 | |||
87 | /** |
||
88 | * Sets a specific cache item, for when a cacheable value was a by-product. |
||
89 | * |
||
90 | * @param string $key |
||
91 | * @param mixed $value |
||
92 | */ |
||
93 | protected function setCache($key, $value) |
||
97 | |||
98 | /** |
||
99 | * @return UserContext |
||
100 | */ |
||
101 | public function getContext() |
||
105 | |||
106 | /** |
||
107 | * Protected as a derived class may want to offer the name under a different name. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | protected function getName() |
||
115 | |||
116 | /** |
||
117 | * Converts an array of string items to an associative array of objects of the specified type. |
||
118 | * |
||
119 | * @param array $items |
||
120 | * @param string $class |
||
121 | * @param UserContext $context |
||
122 | * @return array |
||
123 | */ |
||
124 | public static function toObjectArray(array $items, $class, UserContext $context) |
||
130 | |||
131 | /** |
||
132 | * Converts an associative array of descriptors to objects of the specified type. |
||
133 | * |
||
134 | * @param array $items |
||
135 | * @param string $class |
||
136 | * @param UserContext $context |
||
137 | * @return array |
||
138 | */ |
||
139 | public static function toRichObjectArray(array $items, $class, UserContext $context) |
||
146 | } |
||
147 |