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 | protected function getCacheItem($key, $item, $defaultKey, $defaultItem = null) |
||
84 | |||
85 | /** |
||
86 | * Sets a specific cache item, for when a cacheable value was a by-product. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * @param mixed $value |
||
90 | */ |
||
91 | protected function setCache($key, $value) |
||
95 | |||
96 | /** |
||
97 | * @return UserContext |
||
98 | */ |
||
99 | public function getContext() |
||
103 | |||
104 | /** |
||
105 | * Protected as a derived class may want to offer the name under a different name. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function getName() |
||
113 | |||
114 | /** |
||
115 | * Converts an array of string items to an associative array of objects of the specified type. |
||
116 | * |
||
117 | * @param array $items |
||
118 | * @param string $class |
||
119 | * @param UserContext $context |
||
120 | * @return array |
||
121 | */ |
||
122 | public static function toObjectArray(array $items, $class, UserContext $context) |
||
128 | |||
129 | /** |
||
130 | * Converts an associative array of descriptors to objects of the specified type. |
||
131 | * |
||
132 | * @param array $items |
||
133 | * @param string $class |
||
134 | * @param UserContext $context |
||
135 | * @return array |
||
136 | */ |
||
137 | public static function toRichObjectArray(array $items, $class, UserContext $context) |
||
144 | } |
||
145 |