nvg-cockpit:dxo-base-model
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| nvg-cockpit:dxo-base-model [2025/11/11 17:07] – [Quick facts] admin | nvg-cockpit:dxo-base-model [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== _DXOBaseModel (PHP) ====== | ||
| - | Generic Base Model providing shared ORM-like functionality. | ||
| - | |||
| - | * **Author:** dynaxio AG | ||
| - | * **Created: | ||
| - | * **Updated: | ||
| - | * **Version: | ||
| - | * **License: | ||
| - | |||
| - | Provides dynamic getters/ | ||
| - | Edges and policies may use '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | ===== Quick facts ===== | ||
| - | |||
| - | * **Constructor: | ||
| - | * | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Example: minimal child model ===== | ||
| - | <code php> | ||
| - | namespace Lib\Model; | ||
| - | |||
| - | use Lib\_DXOBaseModel; | ||
| - | |||
| - | class Partner extends _DXOBaseModel | ||
| - | { | ||
| - | protected ?string $table = null; | ||
| - | |||
| - | // Outbound relations from Partner rows | ||
| - | protected array $edgesMap = [ | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ], | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ], | ||
| - | ]; | ||
| - | |||
| - | public function __construct(int $id = 0, array $initial = []) | ||
| - | { | ||
| - | $this-> | ||
| - | parent:: | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Properties ===== | ||
| - | ^ Property ^ Type ^ Purpose ^ | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | | '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Construction lifecycle ===== | ||
| - | <code php> | ||
| - | public function __construct(int $id = 0, array $initial = []) | ||
| - | </ | ||
| - | * If '' | ||
| - | * If '' | ||
| - | * Populates '' | ||
| - | |||
| - | '' | ||
| - | |||
| - | <code php> | ||
| - | INSERT INTO `< | ||
| - | </ | ||
| - | |||
| - | On success, the new '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Magic accessors ===== | ||
| - | Use dynamic getters/ | ||
| - | |||
| - | <code php> | ||
| - | $partner = new Partner(123); | ||
| - | $name = $partner-> | ||
| - | $ok = $partner-> | ||
| - | </ | ||
| - | |||
| - | Guards: | ||
| - | * '' | ||
| - | * Per-field validators can be added via '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Persistence ===== | ||
| - | ==== Save ==== | ||
| - | <code php> | ||
| - | protected function _save(): false|int | ||
| - | </ | ||
| - | * If the row exists → '' | ||
| - | * If not → '' | ||
| - | * On success: | ||
| - | * invalidates the cache, | ||
| - | * **registers outbound edges**, | ||
| - | * returns '' | ||
| - | |||
| - | ==== Load (with cache) ==== | ||
| - | <code php> | ||
| - | protected function _load(): false|array | ||
| - | </ | ||
| - | * Per-class, per-id cache with TTL ('' | ||
| - | * Falls back to DB if expired/ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Table name resolution ===== | ||
| - | <code php> | ||
| - | protected function fetchTableName(): | ||
| - | protected function resolveTableName(string $maybe): string | ||
| - | </ | ||
| - | |||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Consistency edges ===== | ||
| - | Outbound edges are derived from '' | ||
| - | |||
| - | ==== edgesFromSelf() ==== | ||
| - | <code php> | ||
| - | public function edgesFromSelf(): | ||
| - | </ | ||
| - | |||
| - | Returns an array of edges: | ||
| - | |||
| - | < | ||
| - | [ | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ] | ||
| - | </ | ||
| - | |||
| - | Notes: | ||
| - | * '' | ||
| - | * If '' | ||
| - | |||
| - | ==== registerConsistencyEdges() ==== | ||
| - | <code php> | ||
| - | protected function registerConsistencyEdges(): | ||
| - | </ | ||
| - | * Skips if '' | ||
| - | * Determines '' | ||
| - | * Removes all existing outbound edges for '' | ||
| - | * Recreates edges via '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Policy-aware deletion ===== | ||
| - | <code php> | ||
| - | public function _destroyMySelf(): | ||
| - | </ | ||
| - | * Validates '' | ||
| - | * If '' | ||
| - | <code php> | ||
| - | $mgr-> | ||
| - | </ | ||
| - | * The manager reads '' | ||
| - | * Fallback: hard delete (not recommended). | ||
| - | |||
| - | **Always delete via** '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Utilities ===== | ||
| - | <code php> | ||
| - | public function getId(): int | ||
| - | public function invalidateRecordCache(): | ||
| - | protected function toSnakeCase(string $name): string | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Logging & error handling ===== | ||
| - | * No exceptions are thrown to the caller in normal flow; failures are logged via '' | ||
| - | * Methods return '' | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Worked snippets ===== | ||
| - | **Create, set, save** | ||
| - | <code php> | ||
| - | $p = new Partner(0, [' | ||
| - | $p-> | ||
| - | $id = $p-> | ||
| - | </ | ||
| - | |||
| - | **Policy-aware delete** | ||
| - | <code php> | ||
| - | $p = new Partner(123); | ||
| - | if (!$p-> | ||
| - | // Deletion was restricted by policy (see logs) | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | **Custom validator** | ||
| - | <code php> | ||
| - | $this-> | ||
| - | return filter_var($val, | ||
| - | }; | ||
| - | </ | ||
| - | |||
| - | **Restrict writable fields** | ||
| - | <code php> | ||
| - | protected ?array $allowedFields = [' | ||
| - | protected array $readOnlyFields = [' | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Interop with Consistency Manager ===== | ||
| - | * '' | ||
| - | * '' | ||
| - | * Resolves '' | ||
| - | * Optionally resolves destination by '' | ||
| - | * Stores edges with '' | ||
| - | |||
| - | See the **Consistency Manager** page for schema, policies, and the reindex CLI. | ||
| - | |||
| - | ---- | ||
| - | |||
| - | ===== Changelog ===== | ||
| - | * **1.4.1 (2025-11-11): | ||
| - | * **1.4.0 (2025-11-11): | ||
| - | * **1.3.0 (2025-11-11): | ||
| - | * **1.2.0 (2025-11-11): | ||
| - | * **1.1.0 (2025-11-06): | ||
| - | * **1.0.0 (2025-11-06): | ||
| - | |||
nvg-cockpit/dxo-base-model.1762880841.txt.gz · Last modified: by admin
