You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, our code have lots of repeated logic, long functions with too many parameters and no structure when it comes to defining indices. If we introduce an ORM-like architecture, we would solve the majority of these issues. A base Index (equivalent to Model in traditional ORMs) would handle defining the data mappings (columns), querying the index and creating new records. It would also provide a way to sanitize and protect against malicious code.
Example Index class:
namespaceES\Indices;
class Entity extends Index {
protected$fields = [
'content',
'entity_id'
'bundle_label'
];
/** * Get the related entity * * @return object */publicfunctionentity($fields = []) {
returntripal_load_entity('TripalEntity', $this->entity_id, false, $fields);
}
}
The text was updated successfully, but these errors were encountered:
Index class: Handles index definition and data manipulation. Depends on Query\Builder.
Register an SPL loader
Since we will have classes that depend on each other, it is likely that we'll need to load the classes in a certain order, which can cause fatal errors if the order is wrong. PHP provides a solution for this, SPL loaders. The loaders trigger a function when a class has been called but was not found. The function can handle the loading of the class as needed. This requires that we define all our classes within a namespace as such: ES\Common, ES\Jobs, etc. Then, when a class that belongs to the ES namespace is encountered, we will attempt to check if the file exists and load it. If it does not exist, let php handle the rest (throw an error or find another SPL loader).
Currently, our code have lots of repeated logic, long functions with too many parameters and no structure when it comes to defining indices. If we introduce an ORM-like architecture, we would solve the majority of these issues. A base
Index
(equivalent toModel
in traditional ORMs) would handle defining the data mappings (columns), querying the index and creating new records. It would also provide a way to sanitize and protect against malicious code.Example
Index
class:The text was updated successfully, but these errors were encountered: