Base class for entities serviced by sync providers
{@see AbstractSyncEntity} implements {@see Readable} and {@see Writable}, but
protected
properties are not accessible by default. Override
{@see AbstractSyncEntity::getReadableProperties()} and/or
{@see AbstractSyncEntity::getWritableProperties()} to change this.
The following "magic" property methods are discovered automatically and don't
need to be returned by {@see AbstractSyncEntity::getReadableProperties()} or
{@see AbstractSyncEntity::getWritableProperties()}:
-
protected function _get<PropertyName>()
-
protected function _isset<PropertyName>()
(optional; falls back to
_get<PropertyName>()
if not declared)
-
protected function _set<PropertyName>($value)
-
protected function _unset<PropertyName>()
(optional; falls back to
_set<PropertyName>(null)
if not declared)
Accessible properties are mapped to associative arrays with snake_case keys
when {@see AbstractSyncEntity} objects are serialized. Override
{@see AbstractSyncEntity::buildSerializeRules()} to provide serialization
rules for nested entities.
Methods |
public
static
|
getPlural(): ?string
Get the plural form of the entity's short name
Get the plural form of the entity's short name
If this method returns a value other than null or the unqualified name
of the entity, it may be used to identify provider methods that implement
sync operations on the entity.
For example, if Faculty::getPlural() returns null , a provider may
implement Faculty sync operations via one or more of the following:
-
create_faculty()
-
get_faculty()
-
update_faculty()
-
delete_faculty()
-
createList_faculty()
-
getList_faculty()
-
updateList_faculty()
-
deleteList_faculty()
If the same method returns "Faculties" , these are also recognised as
Faculty sync implementations:
-
createFaculty()
-
getFaculty()
-
updateFaculty()
-
deleteFaculty()
-
createFaculties()
-
getFaculties()
-
updateFaculties()
-
deleteFaculties()
Implements
|
#
|
public
static
|
getRelationships(): array
Get an array that maps properties to relationships
Get an array that maps properties to relationships
Implements
|
#
|
public
static
|
getDateProperties(): array
Get properties that accept date and time values
Get properties that accept date and time values
If ["*"] is returned, a {@see DateTimeInterface} instance may be
applied to any accessible property.
Implements
|
#
|
public
static
|
flushStatic(): void
Reset static properties
|
#
|
public
|
getName(): string
Get the name of the object
Get the name of the object
Implements
|
#
|
protected
static
|
buildSerializeRules(SyncSerializeRulesBuilder<static> $rulesB): SyncSerializeRulesBuilder<static>
Override to specify how object graphs below entities of this type should
be serialized
Override to specify how object graphs below entities of this type should
be serialized
To prevent infinite recursion when entities of this type are serialized,
return a {@see SyncSerializeRulesBuilder} object configured to remove or
replace circular references.
|
#
|
protected
static
|
getRemovablePrefixes(): string[]|null
Override to specify prefixes to remove when normalising property names
Override to specify prefixes to remove when normalising property names
Entity names are removed by default, e.g. for an
{@see AbstractSyncEntity} subclass called User , "User" is removed to
ensure fields like "USER_ID" and "USER_NAME" match properties like "Id"
and "Name". For a subclass of User called AdminUser , both "User" and
"AdminUser" are removed.
Return null to suppress prefix removal, otherwise use
{@see AbstractSyncEntity::normalisePrefixes()} or
{@see AbstractSyncEntity::expandPrefixes()} to normalise the return
value.
|
#
|
final
public
|
getId()
Get the object's unique identifier
Get the object's unique identifier
Implements
|
#
|
final
public
|
getCanonicalId()
Get the unique identifier assigned to the entity by its canonical backend
Get the unique identifier assigned to the entity by its canonical backend
If a provider is bound to the service container as the default
implementation of the entity's underlying provider interface, it is
regarded as its canonical backend.
To improve the accuracy and performance of sync operations, providers
should propagate this value to and from backends capable of storing it.
Implements
|
#
|
final
public
static
|
getDefaultProvider(ContainerInterface $container): SyncProviderInterface
Get the entity's default provider
Get the entity's default provider
Implements
|
#
|
final
public
static
|
withDefaultProvider(ContainerInterface $container, ?SyncContextInterface $context = null): SyncEntityProviderInterface
Perform sync operations on the entity using its default provider
Perform sync operations on the entity using its default provider
Implements
|
#
|
final
public
static
|
getSerializeRules(): SyncSerializeRulesInterface
Get the entity's serialization rules
Get the entity's serialization rules
Implements
|
#
|
final
protected
static
|
getParentSerializeRules(): SyncSerializeRules<static>|null
Get the serialization rules of the entity's parent class
Get the serialization rules of the entity's parent class
|
#
|
final
public
static
|
normaliseProperty(string $name, bool $greedy = true, string ...$hints): string
Normalise a property name
Normalise a property name
-
$name is converted to snake_case
- If the result is one of the given
$hints , it is returned
- If
$greedy is true , prefixes returned by
{@see AbstractSyncEntity::getRemovablePrefixes()} are removed
Implements
|
#
|
final
public
|
toArray(?SyncStoreInterface $store = null): array
Serialize the entity and any nested entities
Serialize the entity and any nested entities
Rules returned by {@see SyncEntityInterface::getSerializeRules()} are
used.
Implements
|
#
|
final
public
|
toArrayWith(SyncSerializeRulesInterface $rules, ?SyncStoreInterface $store = null): array
Use the given serialization rules to serialize the entity and any nested
entities
Use the given serialization rules to serialize the entity and any nested
entities
Implements
|
#
|
final
public
|
toLink(?SyncStoreInterface $store = null, int $type = LinkType::DEFAULT, bool $compact = true): array
Get the entity's canonical location in the form of an array
Get the entity's canonical location in the form of an array
Inspired by JSON-LD.
Implements
|
#
|
final
public
|
getUri(?SyncStoreInterface $store = null, bool $compact = true): string
Get the entity's canonical location in the form of a URI
Get the entity's canonical location in the form of a URI
Inspired by OData.
Implements
|
#
|
final
public
|
state(): int-mask-of<EntityState::*>
Get the current state of the entity
Get the current state of the entity
|
#
|
final
protected
static
|
normalisePrefixes(string[] $prefixes): string[]
Convert prefixes to snake_case for removal from property names
Convert prefixes to snake_case for removal from property names
e.g. ['AdminUserGroup'] becomes ['admin_user_group'] .
|
#
|
final
protected
static
|
expandPrefixes(string[] $prefixes): string[]
Convert prefixes to snake_case and expand them for removal from property
names
Convert prefixes to snake_case and expand them for removal from property
names
e.g. ['AdminUserGroup'] becomes ['admin_user_group', 'user_group', 'group'] .
|
#
|
final
public
static
|
provide(array $data, SyncProviderInterface $provider, SyncContextInterface|null $context = null)
Create an instance of the class from an array on behalf of a provider
Create an instance of the class from an array on behalf of a provider
Implements
|
#
|
final
public
static
|
provideMultiple(
iterable $list,
SyncProviderInterface $provider,
int $conformity = ListConformity::NONE,
SyncContextInterface|null $context = null,
): FluentIteratorInterface
Create instances of the class from arrays on behalf of a provider
Create instances of the class from arrays on behalf of a provider
Implements
|
#
|
final
public
static
|
idFromNameOrId(
$nameOrId,
$providerOrContext,
?float $uncertaintyThreshold = null,
?string $nameProperty = null,
?float &$uncertainty = null,
)
Resolve a name or entity ID to the entity ID of one matching entity
Resolve a name or entity ID to the entity ID of one matching entity
Returns:
-
null if $nameOrId is null
-
$nameOrId if it is a valid identifier for the entity in the given
provider (see {@see SyncProviderInterface::isValidIdentifier()}), or
- the entity ID of the entity to which
$nameOrId resolves
A {@see SyncEntityNotFoundExceptionInterface} is thrown if:
- there are no matching entities, or
- there are multiple matching entities
Implements
|
#
|
public
|
postLoad(): void
Called after data from the provider has been applied to the object
Called after data from the provider has been applied to the object
Implements
|
#
|
public
|
__serialize(): array<string, mixed>
|
#
|
public
|
__unserialize(array<string, mixed> $data): void
|
#
|