mini\Database\ModelScopedTable class

Documentation

MutableTableInterface decorator that enforces Model authorization on writes

Wraps the inner table registered in VirtualDatabase. By the time rows reach this decorator, VDB has already applied the scope WHERE at the SQL level (Layer 1). This decorator adds per-entity can() checks (Layer 2).

Write operations use a snapshot-then-pin pattern (in-memory equivalent of SELECT FOR UPDATE): rows are materialized once, authorization is checked on the snapshot, and the actual operation is pinned to exactly those row IDs. This eliminates the TOCTOU gap between checking and operating.

  • insert(): gates on can(Create, $modelClass)
  • update(): snapshots rows, checks can(Update, $entity) per row, pins by PK
  • delete(): snapshots rows, checks can(Delete, $entity) per row, pins by PK
  • reads: pass through (VDB applied readable scope at SQL level)

Inheritance

Extends: mini\Table\Wrappers\AbstractTableWrapper

Implements: mini\Table\Contracts\SetInterface IteratorAggregate Countable Traversable mini\Table\Contracts\TableInterface mini\Table\Contracts\MutableTableInterface

Properties (7)

private string $primaryKey
protected mini\Table\AbstractTable $source
protected ?Closure $compareFn
protected ?int $limit
protected int $offset

Methods (40)

Documentation missing

Get the model configuration for this table

Documentation missing

Documentation missing

Documentation missing

Get the source table this wrapper delegates to

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Hook for subclasses to customize clone behavior

Get column name(s) that the row key represents

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Get the current table alias (null if not set)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Check if value(s) exist in the table's projected columns

Get the primary key column definition (cached)

Iterate over rows with visible columns only

Return table with property set

Source

src/Database/ModelScopedTable.php:33-122