PDORepository
MMO\pdo · 1 symbol · generated 27 Oct 2026
PDORepository
PDORepository.php:38A aRepository backed by a SQL database: one Table per collection.
- Namespace
MMO\pdo- Extends
- aRepository
Index
| entities | ||
| handler | ||
| lastIds | ||
| pendingId | A placeholder id, handed to a new entity whose real id the DATABASE will generate. | |
| tables | ||
| addTable($table, $name) | Register a table and the collection that holds its rows. | |
| commitEntity($entity, $commit, $counts) | Persist one entity. Called from inside onCommit's transaction. | |
| createEntity($class, $data, $collection) | ||
| debugName() | ||
| dropCollection($collection) | Drop a collection's table, and forget the collection. | |
| executeQuery($query, $opts) | Run a query against the database. | |
| exportFilterValue($operator, $value, $table, $column) | A condition's value, converted as the column stores it (prepareFilter). | |
| exportRow($table, $values) | ||
| exportValue($table, $column, $value) | Convert one entity value into something a column can hold (PDOExporter), using the column's own type to decide a date's format. | |
| generateId($collection) | An id is not given twice by one repository: what is keyed by an id (a scope edms.files.12, a link, a cache) would apply to the next entity. | |
| getHandler() | ||
| getTable($collection) | ||
| idKeys($class, $table) | ||
| install() | Create any of this repository's tables that the database does not have yet. | |
| IsPendingId($id) static | ||
| loadEntities($collection, $rows, $reload) | Turn rows into entities, reusing the instance a row's id already has in the collection so the same record is never represented twice. | |
| logsQueries() | ||
| nextPendingId() | ||
| onCommit($commit) | Persist every entity of this commit that belongs to one of this repository's collections. | |
| prepareCondition($path, $assert, $table, $collection) | One condition of a filter (prepareFilter). | |
| prepareFilter($filter, $table, $collection) | Rewrite a query's filter into one this table can answer in SQL. | |
| prepareId($operator, $value, $table, $collection) | A condition on id for a table whose primary key has another name, or several columns (prepareCondition). | |
| queryColumns($query, $table) | The columns a query should actually SELECT. | |
| referencedCollection($collection, $property) | ||
| references($collection) | ||
| rowId($class, $row) | ||
| setEntities($entities) | Your own entity class for a table's rows, rather than one generated from its columns. | |
| setHandler($handler) | ||
| setTables($tables) | Declare this repository's tables from configuration, so an application describes its schema in one place instead of building every Table by hand. | |
| uid() | ||
| unregister() | Detach this repository, and its collections, from the global Commit / Fetch events. | |
| __construct($handler, $collections) |
Properties5
entities
- Type
- array
- See
setEntities-- declared here so the configuration keyentitiesreaches it.
handler
- Type
- iHandler
lastIds
- Type
- array
pendingId
A placeholder id, handed to a new entity whose real id the DATABASE will generate.
- Type
- int
tables
- Type
- array
- See
setTables-- declared here so the configuration keytablesreaches it.
Methods32
addTable($table, $name)
PDORepository.php:179Register a table and the collection that holds its rows.
| $table | Table | |
| $name = null | null | string | the collection's name; the table's own name by default |
| returns | iCollection |
commitEntity($entity, $commit, $counts)
PDORepository.php:739Persist one entity. Called from inside onCommit's transaction.
createEntity($class, $data, $collection)
PDORepository.php:244- See
aRepository::createEntity, making sure the new entity has an id of some kind.
| $class | string | |
| $data = [] | array | |
| $collection = null | null | iCollection | |
| returns | iEntity |
debugName()
PDORepository.php:96| returns | string |
dropCollection($collection)
PDORepository.php:200Drop a collection's table, and forget the collection.
| $collection | iCollection | string | |
| returns | bool |
executeQuery($query, $opts)
PDORepository.php:554Run a query against the database.
exportFilterValue($operator, $value, $table, $column)
PDORepository.php:516A condition's value, converted as the column stores it (prepareFilter).
exportRow($table, $values)
PDORepository.php:678exportValue($table, $column, $value)
PDORepository.php:668Convert one entity value into something a column can hold (PDOExporter), using the column's own type to decide a date's format.
generateId($collection)
PDORepository.php:279An id is not given twice by one repository: what is keyed by an id (a scope edms.files.12, a link, a cache) would apply to the next entity.
| $collection | iCollection | |
| returns | int | one more than the highest id in use -- counting both the rows already stored AND the entities already created in this collection, since several can be created before any of them is committed -- and than the ids of the entities removed ($lastIds). |
getHandler()
PDORepository.php:84| returns | iHandler |
getTable($collection)
PDORepository.php:192| $collection | iCollection | string | |
| returns | Table | the table behind a collection |
| throws | if there is none |
idKeys($class, $table)
PDORepository.php:484| $class | string | an entity class |
| $table | Table | its table |
| returns | array | array<string>, 1: non-empty-string} the columns of its id (PDOEntity::ID_PROP), and what joins them |
install()
PDORepository.php:136Create any of this repository's tables that the database does not have yet.
| returns | array | the names of the tables that were created |
IsPendingId($id)
staticPDORepository.php:231loadEntities($collection, $rows, $reload)
PDORepository.php:595Turn rows into entities, reusing the instance a row's id already has in the collection so the same record is never represented twice.
| $collection | iCollection | |
| $rows | iterable | |
| $reload = false | bool | if true, refresh an already-loaded entity from its row |
| returns | array |
logsQueries()
PDORepository.php:64nextPendingId()
PDORepository.php:226| returns | int | the next placeholder id (-1, -2, …). $pendingId |
onCommit($commit)
PDORepository.php:695Persist every entity of this commit that belongs to one of this repository's collections.
prepareCondition($path, $assert, $table, $collection)
PDORepository.php:401One condition of a filter (prepareFilter).
| $path | string | |
| $assert | mixed | the condition: a value, or a FilterValue |
| $table | Table | |
| $collection | iCollection | |
| returns | iFilter | bool | null | the condition for the table, true/false when the row does not decide it, null for a name the table cannot answer |
prepareFilter($filter, $table, $collection)
PDORepository.php:351Rewrite a query's filter into one this table can answer in SQL.
| $filter | iFilter | |
| $table | Table | |
| $collection | iCollection | |
| returns | iFilter | bool | the filter to give the table, or true/false when it matches every row or none |
| throws | on a name that is neither a column nor a property |
prepareId($operator, $value, $table, $collection)
PDORepository.php:457A condition on id for a table whose primary key has another name, or several columns (prepareCondition).
| $operator | FilterOperator | |
| $value | mixed | |
| $table | Table | |
| $collection | iCollection | |
| returns | iFilter | bool | null | |
| throws | on an operator that cannot compare a composite id |
queryColumns($query, $table)
PDORepository.php:311The columns a query should actually SELECT.
referencedCollection($collection, $property)
PDORepository.php:494| $collection | iCollection | |
| $property | string | |
| returns | null | iCollection | the collection of this repository whose entities $property references, if it does |
references($collection)
PDORepository.php:635| $collection | iCollection | |
| returns | array | iCollection> its columns that reference another collection's entities, and that collection |
rowId($class, $row)
PDORepository.php:649| $class | string | the collection's entity class |
| $row | array | |
| returns | string | the row's id in the form PDOEntity::getId produces, or '' if the row does not carry it |
setEntities($entities)
PDORepository.php:160Your own entity class for a table's rows, rather than one generated from its columns. Before or after the table is declared, alike: a collection takes its entity class when its table is added, so a Table's own setEntityClass() called after addTable or setTables changes nothing -- this does.
setHandler($handler)
PDORepository.php:88setTables($tables)
PDORepository.php:115Declare this repository's tables from configuration, so an application describes its schema in one place instead of building every Table by hand.
| $tables | array | name => [column => sql definition, …], or name => Table for one already built |
| returns | void |
uid()
PDORepository.php:92| returns | string |
unregister()
PDORepository.php:78Detach this repository, and its collections, from the global Commit / Fetch events.
| returns | void |
__construct($handler, $collections)
PDORepository.php:54| $handler | iHandler | |
| $collections = [] | array | see aRepository::setCollections -- their tables must already be known to $handler. addTable is usually easier. |
Inherited members (26)
| Properties | Declared by | Description | |
|---|---|---|---|
collections | aRepository |
| Methods | Declared by | Description | |
|---|---|---|---|
addCollection($name, $collection) | aRepository | Add collection | |
createCollection($name, $entityClass, $collectionId) | aRepository | Create and register a plain Collection for entities of $entityClass. | |
createLog($type, $origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Build (but not dispatch) a LogQuery entity describing a data-mutating operation, stored in the repository's LogQuery collection (if one is registered). | |
forceCommit($origin, $entities) | aRepository | ||
getCollection($name) | aRepository | ||
getCollectionByClass($entityClass, $allowChildClass) | aRepository | Find the collection whose entities are (an exact match, or optionally a subclass of) $entityClass. | |
getCollectionName($collection) | aRepository | ||
getCollections() | aRepository | ||
getDistinct($collection, $key) | aRepository | Every value one property takes across a collection, once each, in ascending order. | |
getEntities() | aRepository | ||
getIterator() | aRepository | \IteratorAggregate::getIterator -- iterates name => iCollection | |
hasCollection($collection) | aRepository | ||
hideLogData($collection, $data) | aRepository | What a repository logs is what it wrote (mmo.pdo's row, mmo.mongodb's document or its changes), hidden properties (ArrayProperty::isHidden) included, and a log is exported… | |
logDelete($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch a DELETE operation. | |
logInsert($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch an INSERT operation. | |
logStatus($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch a STATUS-change operation. | |
logUpdate($origin, $collection, $data, $filters, $sorts, $limit, $offset) | aRepository | Log and dispatch an UPDATE operation. | |
offsetExists($key) | aRepository | \ArrayAccess::offsetExists | |
offsetGet($key) | aRepository | \ArrayAccess::offsetGet | |
offsetSet($key, $value) | aRepository | \ArrayAccess::offsetSet -- equivalent to addCollection | |
offsetUnset($key) | aRepository | \ArrayAccess::offsetUnset | |
onFetch($event) | aRepository | Listener for Fetch: resolves a repository-uid/collection-id#id (or repository-uid/collection-id#id/nested/path for an embedded value) URL, what Ent… | |
searchText($query, $text) | aRepository | Full-text search (?search[type]=$text of RepositoryController::routeGet), on top of the query's own filters, its sort and its page. | |
setCollections($cols) | aRepository | Register a batch of collections at once, e.g. | |
__wakeup() | aRepository | Register this repository's onCommit / onFetch as listeners on the global |