1 | <?php |
||
12 | class AttributeLoader { |
||
13 | |||
14 | /** |
||
15 | * @var array names of attributes in all entities |
||
16 | * |
||
17 | * @todo require this to be injected and get it from \ElggEntity |
||
18 | */ |
||
19 | protected static $primary_attr_names = array( |
||
20 | 'guid', |
||
21 | 'type', |
||
22 | 'subtype', |
||
23 | 'owner_guid', |
||
24 | 'container_guid', |
||
25 | 'site_guid', |
||
26 | 'access_id', |
||
27 | 'time_created', |
||
28 | 'time_updated', |
||
29 | 'last_action', |
||
30 | 'enabled', |
||
31 | ); |
||
32 | |||
33 | /** |
||
34 | * @var array names of attributes in all entities that should be stored as integer values |
||
35 | */ |
||
36 | protected static $integer_attr_names = array( |
||
37 | 'guid', |
||
38 | 'owner_guid', |
||
39 | 'container_guid', |
||
40 | 'site_guid', |
||
41 | 'access_id', |
||
42 | 'time_created', |
||
43 | 'time_updated', |
||
44 | 'last_action', |
||
45 | // \ElggUser |
||
46 | 'prev_last_action', |
||
47 | 'last_login', |
||
48 | 'prev_last_login' |
||
49 | ); |
||
50 | |||
51 | /** |
||
52 | * @var array names of attributes in all entities that should be stored as null if empty |
||
53 | */ |
||
54 | protected static $null_attr_names = array( |
||
55 | 'name', |
||
56 | 'title', |
||
57 | 'description', |
||
58 | 'url', |
||
59 | ); |
||
60 | |||
61 | /** |
||
62 | * @var array names of secondary attributes required for the entity |
||
63 | */ |
||
64 | protected $secondary_attr_names = array(); |
||
65 | |||
66 | /** |
||
67 | * @var string entity type (not class) required for fetched primaries |
||
68 | */ |
||
69 | protected $required_type; |
||
70 | |||
71 | /** |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $initialized_attributes; |
||
75 | |||
76 | /** |
||
77 | * @var string class of object being loaded |
||
78 | */ |
||
79 | protected $class; |
||
80 | |||
81 | /** |
||
82 | * @var bool should access control be considered when fetching entity? |
||
83 | */ |
||
84 | public $requires_access_control = true; |
||
85 | |||
86 | /** |
||
87 | * @var callable function used to load attributes from {prefix}entities table |
||
88 | */ |
||
89 | public $primary_loader = 'get_entity_as_row'; |
||
90 | |||
91 | /** |
||
92 | * @var callable function used to load attributes from secondary table |
||
93 | */ |
||
94 | public $secondary_loader = ''; |
||
95 | |||
96 | /** |
||
97 | * @var callable function used to load all necessary attributes |
||
98 | */ |
||
99 | public $full_loader = ''; |
||
100 | |||
101 | /** |
||
102 | * @var array retrieved values that are not attributes |
||
103 | */ |
||
104 | protected $additional_select_values = array(); |
||
105 | |||
106 | /** |
||
107 | * Constructor |
||
108 | * |
||
109 | * @param string $class class of object being loaded |
||
110 | * @param string $required_type entity type this is being used to populate |
||
111 | * @param array $initialized_attrs attributes after initializeAttributes() has been run |
||
112 | * @throws \InvalidArgumentException |
||
113 | */ |
||
114 | public function __construct($class, $required_type, array $initialized_attrs) { |
||
129 | |||
130 | /** |
||
131 | * Get primary attributes missing that are missing |
||
132 | * |
||
133 | * @param \stdClass $row Database row |
||
134 | * @return array |
||
135 | */ |
||
136 | protected function isMissingPrimaries($row) { |
||
139 | |||
140 | /** |
||
141 | * Get secondary attributes that are missing |
||
142 | * |
||
143 | * @param \stdClass $row Database row |
||
144 | * @return array |
||
145 | */ |
||
146 | protected function isMissingSecondaries($row) { |
||
149 | |||
150 | /** |
||
151 | * Check that the type is correct |
||
152 | * |
||
153 | * @param \stdClass $row Database row |
||
154 | * @return void |
||
155 | * @throws \InvalidClassException |
||
156 | */ |
||
157 | protected function checkType($row) { |
||
163 | |||
164 | /** |
||
165 | * Get values selected from the database that are not attributes |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | public function getAdditionalSelectValues() { |
||
172 | |||
173 | /** |
||
174 | * Get all required attributes for the entity, validating any that are passed in. Returns empty array |
||
175 | * if can't be loaded (Check $failure_reason). |
||
176 | * |
||
177 | * This function splits loading between "primary" attributes (those in {prefix}entities table) and |
||
178 | * "secondary" attributes (e.g. those in {prefix}objects_entity), but can load all at once if a |
||
179 | * combined loader is available. |
||
180 | * |
||
181 | * @param mixed $row a row loaded from DB (array or \stdClass) or a GUID |
||
182 | * @return array will be empty if failed to load all attributes (access control or entity doesn't exist) |
||
183 | * |
||
184 | * @throws \InvalidArgumentException|\LogicException|\IncompleteEntityException |
||
185 | */ |
||
186 | public function getRequiredAttributes($row) { |
||
263 | |||
264 | /** |
||
265 | * Filter non-attribute keys into $this->additional_select_values |
||
266 | * |
||
267 | * @param array $row All columns from the query |
||
268 | * @return array Columns acceptable for the entity's attributes |
||
269 | */ |
||
270 | protected function filterAddedColumns($row) { |
||
284 | } |
||
285 | |||
286 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: