objects

Collection

Every item of one collection field - data with no URL of its own, like comments, likes or tags - in a SQLite database at data/collections/{field}.db.

A collection is never part of history, and an item has no files of its own: a file field on one points at a page's file. An item's page is its parent (the page's uuid, always set), and the item is open to a visitor exactly when that page is. The query DSL is the registry's, over the same field columns, field_items and search_index tables.

$collection Phlat\Data\Collection 15 methods
Properties (2)
$collection->path string readonly The folder of every collection's database.
$collection->field string readonly
Show
  • atomic Runs $fn as one transaction on this collection: every write in it lands together or none does, and pays for the disk once - the way for a script to write many items.
  • count How many items $query matches, ignoring limit and offset.
  • create Adds an item to the page $parent, whose uuid is required: an item is always added from a page.
  • database The database file.
  • delete Removes the item.
  • deleteParent Removes every item of the page $parent, locked or not - the page is going.
  • deleteParents deleteParent() for many pages in one transaction.
  • find The items $query matches (the registry's query DSL), as Items.
  • get The item with this uuid, if the visitor may open its page.
  • parents How many items each page has, as [page uuid => count] - including pages that no longer exist.
  • reindex Rebuilds the field columns, field_items and search_index from the stored items, for when a field's search or fields options changed, first dropping the columns of fields it no longer declares. $onProgress, when given, is called with how many items are done after each chunk.
  • reparent Moves items to other pages after those pages' uuids changed: [old page uuid => new page uuid].
  • save Merges $data into the item; a locked item accepts nothing but a change to `locked` itself.
  • sum The sum of a number field over the items $query matches.
  • unscoped The same collection without the visitor scope - for a collection field with `scoped: false`.

Methods

$collection->atomic(callable $fn): mixed

Runs $fn as one transaction on this collection: every write in it lands together or none does, and pays for the disk once - the way for a script to write many items.

Returns what $fn returns.

Parameters (1)
$fn callable

Returns mixed

phlat/src/Data/Collection.php:183
$collection->count(string $query = ''): int

How many items $query matches, ignoring limit and offset.

Parameters (1)
$query string = ''

Returns int

phlat/src/Data/Collection.php:119
$collection->create(string $parent, array $data = [], string $uuid = '', ?int $created = null, ?int $updated = null): Item

Adds an item to the page $parent, whose uuid is required: an item is always added from a page.

A uuid is minted when none is given; one already in use is a ConflictException. $created and $updated keep the stamps of an item brought from elsewhere.

Parameters (5)
$parent string
$data array = []
$uuid string = ''
$created ?int = null
$updated ?int = null

Returns Item

phlat/src/Data/Collection.php:145
$collection->database(): string

The database file.

Returns string

phlat/src/Data/Collection.php:74
$collection->delete(string $uuid): void

Removes the item.

A locked item is refused.

Parameters (1)
$uuid string
phlat/src/Data/Collection.php:223
$collection->deleteParent(string $parent): int

Removes every item of the page $parent, locked or not - the page is going.

Returns how many. Fires no per-item events.

Parameters (1)
$parent string

Returns int

phlat/src/Data/Collection.php:239
$collection->deleteParents(array $parents): int

deleteParent() for many pages in one transaction.

Returns how many items went.

Parameters (1)
$parents array

Returns int

phlat/src/Data/Collection.php:248
$collection->find(string $query = ''): RecordCollection

The items $query matches (the registry's query DSL), as Items.

Pass a limit for a big collection.

Parameters (1)
$query string = ''

Returns RecordCollection

phlat/src/Data/Collection.php:105

get

$collection->get(string $uuid): ?Item

The item with this uuid, if the visitor may open its page.

Parameters (1)
$uuid string

Returns ?Item

phlat/src/Data/Collection.php:89
$collection->parents(): array

How many items each page has, as [page uuid => count] - including pages that no longer exist.

Returns array

phlat/src/Data/Collection.php:265
$collection->reindex(?callable $onProgress = null): int

Rebuilds the field columns, field_items and search_index from the stored items, for when a field's search or fields options changed, first dropping the columns of fields it no longer declares. $onProgress, when given, is called with how many items are done after each chunk.

Returns how many items.

Parameters (1)
$onProgress ?callable = null

Returns int

phlat/src/Data/Collection.php:294
$collection->reparent(array $uuids): int

Moves items to other pages after those pages' uuids changed: [old page uuid => new page uuid].

Returns how many items moved. The items themselves are untouched.

Parameters (1)
$uuids array

Returns int

phlat/src/Data/Collection.php:278
$collection->save(string $uuid, array $data): Item

Merges $data into the item; a locked item accepts nothing but a change to `locked` itself.

Parameters (2)
$uuid string
$data array

Returns Item

phlat/src/Data/Collection.php:191

sum

$collection->sum(string $field, string $query = ''): float

The sum of a number field over the items $query matches.

Parameters (2)
$field string
$query string = ''

Returns float

phlat/src/Data/Collection.php:130
$collection->unscoped(): static

The same collection without the visitor scope - for a collection field with `scoped: false`.

Returns static

phlat/src/Data/Collection.php:80