Documentation

YamlRepository
in package
implements Countable

YAML Repository

Do not use anymore or at least not until the storage format has been changed (see @todo).

A entity repository with its storage being in a YAML-file.

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Thomas Däppen thomas.daeppen@comvation.com

subpackage

core_model

todo

Make thread safe. The current implementation of YamlRepository does not take the case into account if the repository gets modified by a parallel operation. Changes made by a parallel operation will be discarded,merged or overwritten. The behavior is unknown!

todo

Either drop this class or convert its storage format from plain PHP objects to normalized data. See CLX-3825

Table of Contents

Interfaces

Countable

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
$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
Initialize a YAML-Repository.
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.
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

$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()

$updatedEntities

All entities currently modified in the repository

protected array<string|int, mixed> $updatedEntities = array()

Methods

__construct()

Initialize a YAML-Repository.

public __construct(string $repositoryPath) : mixed

Load the entities stored in the file specified by $repositoryPath.

Parameters
$repositoryPath : string

Absolute path in the file system to the YAML-repository

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

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

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

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
bool

getIdentifierOfEntity()

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

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
throws
YamlRepositoryException

validate()

Validate the entity to comply with any unique-key constraints

protected validate(mixed $entity) : mixed
Parameters
$entity : mixed

        
On this page

Search results