<TEntity is SyncEntityInterface>
final | |
---|---|
implements |
SyncSerializeRulesInterface<TEntity>, Buildable<SyncSerializeRulesBuilder<TEntity>> |
uses |
HasBuilder, HasMutator |
Rules applied when serializing a sync entity
Rules can be applied to any combination of paths and class properties
reachable from the entity, e.g. for a User
entity that normalises property
names:
<?php
[
// Applied to '.Manager.OrgUnit'
'.manager.org_unit',
User::class => [
// Ignored for '.Manager.OrgUnit' because a path-based rule applies,
// but applied to '.OrgUnit', '.Staff[].OrgUnit', ...
'org_unit',
],
];
Path-based rules apply to specific nodes in the object graph below the entity
(only the OrgUnit
of the user's manager in the example above), whereas
class-based rules apply to every appearance of a class in the entity's object
graph (the OrgUnit
of every User
object, including the one being
serialized, in this example).
Each rule must be either a string
containing the path or key to act upon,
or an array
with up to 3 values:
string
; required; must be the first value)string
; optional)Closure($value, $store, $rules): mixed
; optional)Optional values may be omitted.
If multiple rules apply to the same key, path-based rules take precedence over class-based ones, then later rules take precedence over earlier ones:
<?php
[
// Ignored because it applies to the same path as the next rule
'.manager.org_unit',
// Applied to '.Manager.OrgUnit'
[
'.manager.org_unit',
'org_unit_id',
fn($ou) => $ou->Id,
],
User::class => [
// Ignored because it applies to the same property as the next rule
'org_unit',
// Ignored for '.Manager.OrgUnit' because a path-based rule applies,
// but applied to '.OrgUnit', '.Staff[].OrgUnit', ...
['org_unit', 'org_unit_id'],
],
];
Methods | ||
---|---|---|
public
|
merge(SerializeRulesInterface $rules): SerializeRulesInterface
|
# |
public
|
getRemovableKeys(?string $class, ?string $baseClass, array $path): array
|
# |
public
|
getReplaceableKeys(?string $class, ?string $baseClass, array $path): array
|
# |
public
|
getEntity(): string
|
# |
public
|
getDateFormatter(): ?DateFormatterInterface
|
# |
public
|
getIncludeMeta(): bool
|
# |
public
|
getSortByKey(): bool
|
# |
public
|
getMaxDepth(): int
|
# |
public
|
getDetectRecursion(): bool
|
# |
public
|
getRecurseRules(): bool
|
# |
public
|
getForSyncStore(): bool
|
# |
public
|
getIncludeCanonicalId(): bool
|
# |
public
|
withDateFormatter(?DateFormatterInterface $formatter)
|
# |
public
|
withIncludeMeta(?bool $include = true)
|
# |
public
|
withSortByKey(?bool $sort = true)
|
# |
public
|
withMaxDepth(?int $depth)
|
# |
public
|
withDetectRecursion(?bool $detect = true)
|
# |
public
|
withRecurseRules(?bool $recurse = true)
|
# |
public
|
withForSyncStore(?bool $forSyncStore = true)
|
# |
public
|
withIncludeCanonicalId(?bool $include = true)
|
# |
Methods used from Salient\Core\Concern\HasBuilder |
---|
getBuilder(), build(), resolve() |