CategoryRepository
extends ApiRepository
in package
uses
TreeTrait
Admin repository that reads through the Api bridge and bypasses the query cache by default.
find(), findBy() and findAll() send ApiBridge::PARAM_USE_CACHE = false.
$useCache is ?bool: null leaves the decision to this layer (false); an explicit
true (->useCache(true) on the query) is respected and is the only way to request the cache.
IMPORTANT: an admin form is a read followed by a write, so a stale cached value would be
written back to the DB (silent data regression). Invalidation cannot cover it: the view
counters (views, viewsList, viewsDetail) are deliberately excluded from it
(SaveTrait::$nonInvalidatingColumns), because
bumping on every detail view would drop the cache of all lists.
NOTE: this default is not the only safeguard. The main switch is
QueryCacheContext, turned off for the whole request by
BasePresenter::startup(), because an admin request also runs
front managers (AssetManager, ThemeManager, UserManager) through the front repository.
This default covers admin reads outside an admin request (CLI harness, admin cron).
Table of Contents
Properties
- $apiEndpoint : string
- Api presenter path (e.g. `api/system/page`); set by each concrete repository.
- $bridge : ApiBridge
Methods
- __construct() : mixed
- delete() : Result
- deleteAll() : Result
- deleteTreeNode() : Result
- find() : array<string|int, mixed>
- findAll() : array<string|int, mixed>
- findBy() : array<string|int, mixed>
- insertTreeNode() : Result
- moveSubtree() : Result
- moveSubtreeTo() : Result
- moveTreeNode() : Result
- reorderChildren() : Result
- Propagates `data.changed` from the Api (number of children that changed place) into the result.
- save() : Result
- updateColumns() : Result
- failSoftRead() : array<string|int, mixed>
- Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
- getApiCallSource() : string
- Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.
- callTreeEndpoint() : Result
Properties
$apiEndpoint
Api presenter path (e.g. `api/system/page`); set by each concrete repository.
protected
string
$apiEndpoint
= 'api/comcat/category'
$bridge read-only
protected
ApiBridge
$bridge
Methods
__construct()
public
__construct(ApiBridge $bridge) : mixed
Parameters
- $bridge : ApiBridge
delete()
public
delete(int|array<string|int, mixed> $id) : Result
Parameters
- $id : int|array<string|int, mixed>
Return values
ResultdeleteAll()
public
deleteAll([array<string|int, mixed> $filters = [] ]) : Result
Parameters
- $filters : array<string|int, mixed> = []
Return values
ResultdeleteTreeNode()
public
deleteTreeNode(int $id, TreeConfig $config) : Result
Parameters
- $id : int
- $config : TreeConfig
Return values
Resultfind()
public
find(int $id[, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>findAll()
public
findAll([array<string|int, mixed>|null $filters = [] ][, array<string|int, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<string|int, mixed>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $filters : array<string|int, mixed>|null = []
- $orderBys : array<string|int, mixed>|null = null
- $offset : int|null = null
- $limit : int|null = null
- $columns : array<string|int, mixed>|null = null
- $computeTotalCount : bool = false
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>findBy()
public
findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $filters : array<string|int, mixed>|null = []
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>insertTreeNode()
public
insertTreeNode(int $id, TreeConfig $config) : Result
Parameters
- $id : int
- $config : TreeConfig
Return values
ResultmoveSubtree()
public
moveSubtree(int $id, int|null $newParentId, TreeConfig $config) : Result
Parameters
- $id : int
- $newParentId : int|null
-
null moves to the root level
- $config : TreeConfig
Return values
ResultmoveSubtreeTo()
public
moveSubtreeTo(int $id, int|null $newParentId, int $afterId, TreeConfig $config[, TreeMoveExpectation|null $expectation = null ]) : Result
Parameters
- $id : int
- $newParentId : int|null
-
null is the root level
- $afterId : int
-
-1 first child, 0 last child, >0 after that sibling
- $config : TreeConfig
- $expectation : TreeMoveExpectation|null = null
-
always sent, even when null; the internal bridge calls
internalActionMoveSubtreeTo(...$params)with named arguments
Return values
ResultmoveTreeNode()
public
moveTreeNode(int $id, int $direction, TreeConfig $config) : Result
Parameters
- $id : int
- $direction : int
- $config : TreeConfig
Return values
ResultreorderChildren()
Propagates `data.changed` from the Api (number of children that changed place) into the result.
public
reorderChildren(int|null $parentId, array<int, int> $orderedIds, TreeConfig $config) : Result
Parameters
- $parentId : int|null
-
null is the root level
- $orderedIds : array<int, int>
-
child ids in the new order
- $config : TreeConfig
Return values
Resultsave()
public
save(array<string, mixed> $data[, array<string, mixed> $meta = [] ][, array<int, string> $skipFields = [] ]) : Result
Parameters
- $data : array<string, mixed>
-
extracted entity payload
- $meta : array<string, mixed> = []
- $skipFields : array<int, string> = []
Return values
ResultupdateColumns()
public
updateColumns(array<string|int, mixed> $ids, array<string, mixed> $values) : Result
Parameters
- $ids : array<string|int, mixed>
-
ids or composite-id arrays
- $values : array<string, mixed>
-
property name => new value
Return values
ResultfailSoftRead()
Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
protected
failSoftRead(mixed $response, string $endpoint) : array<string|int, mixed>
NOTE: it does not log on purpose. ApiBridge::call(), which sees both the
endpoint and the caller, has already written the API_FAILSOFT source=bridge line; a second
copy would turn one failure into three lines in auth.log.
Parameters
- $response : mixed
- $endpoint : string
-
only for call readability; the log takes the endpoint from the bridge
Return values
array<string|int, mixed>getApiCallSource()
Branch marker for writes ({@see ApiBridge::PARAM_SOURCE}), read by the shared repository `SaveTrait`.
protected
getApiCallSource() : string
Return values
stringcallTreeEndpoint()
private
callTreeEndpoint(string $action, int $id, TreeConfig $config, string $failureMessage) : Result
Parameters
- $action : string
- $id : int
- $config : TreeConfig
- $failureMessage : string