DomainRepository
extends YamlRepository
in package
Domain Repository
Repository to manage the domain entities.
Tags
Table of Contents
Properties
- $addedEntities : array<string|int, mixed>
- All entities currently added to the repository
- $entities : array<string|int, mixed>
- All entities currently loaded/attached to the repository
- $entityAutoIncrement : int
- Auto-increment value used for the primary identifier when adding a new entity to the repository
- $entityIdentifier : string
- Primary identifier attribute of the entity model
- $entityUniqueKeys : array<string|int, mixed>
- Definition of the unique key attributes of the entity model
- $hostnameDomain : Domain
- The domain (in the repository) that represents the server's hostname
- $originalEntitiesFromRepository : array<string|int, mixed>
- The original set of entities in the repository
- $removedEntities : array<string|int, mixed>
- All entities currently removed from the repository
- $repositoryPath : string
- Absolute path to the YAML-repository
- $updatedEntities : array<string|int, mixed>
- All entities currently modified in the repository
Methods
- __construct() : mixed
- Constructor to initialize the YamlRepository with source file config/DomainRepository.yml.
- add() : mixed
- Add new entity to the repository Method {@see flush()} must triggered to persist the entity in the repository.
- count() : int
- Returns the total count of entities
- find() : YamlEntity
- Return single entity specified by primary identifier $id
- findAll() : mixed
- Return all entities from repository
- findBy() : array<string|int, mixed>
- Return an array of entities matching the criterias specified by $criteria.
- findOneBy() : mixed
- flush() : mixed
- Flush the current state of the repository into the file system.
- getHostDomain() : Domain
- Get the server's hostname domain
- getMainDomain() : mixed
- isManaged() : bool
- Tells wheter an entity is managed by this repo or not
- remove() : mixed
- Remove entity from repository.
- fileExistsAndNotEmpty() : bool
- Checks if file exists and is not empty
- getIdentifierOfEntity() : int
- Get the primary identifier of an entity
- getMetaDefinition() : array<string|int, mixed>
- Generate meta definition to be stored in the repository
- getNewEntityIdentifier() : int
- Generate and get a new primary identifier
- load() : mixed
- Load repository from file system specified by $this->repositoryPath
- loadData() : mixed
- prepareFile() : void
- Create a file with metadata, if necessary
- reset() : mixed
- Reset the repository. Unload all data.
- validate() : mixed
- Validate the entity to comply with any unique-key constraints
Properties
$addedEntities
All entities currently added to the repository
protected
array<string|int, mixed>
$addedEntities
= array()
$entities
All entities currently loaded/attached to the repository
protected
array<string|int, mixed>
$entities
$entityAutoIncrement
Auto-increment value used for the primary identifier when adding a new entity to the repository
protected
int
$entityAutoIncrement
$entityIdentifier
Primary identifier attribute of the entity model
protected
string
$entityIdentifier
$entityUniqueKeys
Definition of the unique key attributes of the entity model
protected
array<string|int, mixed>
$entityUniqueKeys
$hostnameDomain
The domain (in the repository) that represents the server's hostname
protected
Domain
$hostnameDomain
= null
Server's hostname domain
$originalEntitiesFromRepository
The original set of entities in the repository
protected
array<string|int, mixed>
$originalEntitiesFromRepository
$removedEntities
All entities currently removed from the repository
protected
array<string|int, mixed>
$removedEntities
= array()
$repositoryPath
Absolute path to the YAML-repository
protected
string
$repositoryPath
$updatedEntities
All entities currently modified in the repository
protected
array<string|int, mixed>
$updatedEntities
= array()
Methods
__construct()
Constructor to initialize the YamlRepository with source file config/DomainRepository.yml.
public
__construct() : mixed
add()
Add new entity to the repository Method {@see flush()} must triggered to persist the entity in the repository.
public
add(mixed $entity) : mixed
Parameters
- $entity : mixed
count()
Returns the total count of entities
public
count() : int
Tags
Return values
int —Total count of entities
find()
Return single entity specified by primary identifier $id
public
find(mixed $id) : YamlEntity
Parameters
- $id : mixed
Return values
YamlEntity —Object from repository identified by primary identifier $id
findAll()
Return all entities from repository
public
findAll() : mixed
findBy()
Return an array of entities matching the criterias specified by $criteria.
public
findBy([array<string|int, mixed> $criteria = array() ]) : array<string|int, mixed>
Parameters
- $criteria : array<string|int, mixed> = array()
-
Arguments to filter the returned entities by
Return values
array<string|int, mixed> —Array containing the objects from the repository matching the filter criterias
findOneBy()
public
findOneBy([array<string|int, mixed> $criteria = array() ]) : mixed
Parameters
- $criteria : array<string|int, mixed> = array()
flush()
Flush the current state of the repository into the file system.
public
flush() : mixed
getHostDomain()
Get the server's hostname domain
public
getHostDomain() : Domain
Return values
Domain —The server's hostname domain
getMainDomain()
public
getMainDomain() : mixed
isManaged()
Tells wheter an entity is managed by this repo or not
public
isManaged(EntityBase $entity) : bool
Parameters
- $entity : EntityBase
-
Entity to test
Return values
bool —True if given entity is managed by this repo, false otherwise
remove()
Remove entity from repository.
public
remove(YamlEntity $entity) : mixed
Entity will not be removed until the method flush() has been triggered.
Parameters
- $entity : YamlEntity
-
The entity to remove from the repository.
fileExistsAndNotEmpty()
Checks if file exists and is not empty
protected
fileExistsAndNotEmpty(string $filename) : bool
Parameters
- $filename : string
Return values
boolgetIdentifierOfEntity()
Get the primary identifier of an entity
protected
getIdentifierOfEntity(YamlEntity $entity[, mixed $identifierKey = null ]) : int
Parameters
- $entity : YamlEntity
-
The entity of which to get the primary identifier from
- $identifierKey : mixed = null
Return values
int —The primary identifier of the supplied entity
getMetaDefinition()
Generate meta definition to be stored in the repository
protected
getMetaDefinition() : array<string|int, mixed>
Return values
array<string|int, mixed> —Meta definition
getNewEntityIdentifier()
Generate and get a new primary identifier
protected
getNewEntityIdentifier() : int
Return values
int —New primary identifier
load()
Load repository from file system specified by $this->repositoryPath
protected
load() : mixed
loadData()
protected
loadData() : mixed
prepareFile()
Create a file with metadata, if necessary
protected
prepareFile(string $filename, string $identifier[, array<string|int, mixed> $unique_keys = array() ]) : void
Does nothing if the file already exists, and is not empty.
Parameters
- $filename : string
- $identifier : string
- $unique_keys : array<string|int, mixed> = array()
Tags
reset()
Reset the repository. Unload all data.
protected
reset() : mixed
validate()
Validate the entity to comply with any unique-key constraints
protected
validate(mixed $entity) : mixed
Parameters
- $entity : mixed