PHP Класс CRUDlex\AbstractData

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$definition Holds the {@see EntityDefinition} entity definition.
$events Holds the events.
$fileProcessor Holds the {@see FileProcessorInterface} file processor.

Открытые методы

Метод Описание
countBy ( string $table, array $params, array $paramsOperators, boolean $excludeDeleted ) : integer Retrieves the amount of entities in the datasource fulfilling the given parameters.
create ( Entity $entity ) : boolean Persists the given entity as new entry in the datasource.
createEmpty ( ) : Entity Creates a new, empty entity instance having all fields prefilled with null or the defined value in case of fixed fields.
createFiles ( Request $request, Entity $entity, string $entityName ) : boolean Creates the uploaded files of a newly created entity.
delete ( Entity $entity ) : integer Deletes an entry from the datasource.
deleteFile ( Entity $entity, string $entityName, string $field ) : boolean Deletes a specific file from an existing entity.
deleteFiles ( Entity $entity, string $entityName ) : boolean Deletes all files of an existing entity.
fetchReferences ( array &$entities = null ) : void Adds the id and name of referenced entities to the given entities. Each reference field is before the raw id of the referenced entity and after the fetch, it's an array with the keys id and name.
get ( string $id ) : void Gets the entity with the given id.
getDefinition ( ) : EntityDefinition Gets the {@see EntityDefinition} instance.
getIdToNameMap ( string $entity, string $nameField ) : array Gets ids and names of a table. Used for building up the dropdown box of reference type fields for example.
hasManySet ( string $field, array $thatIds, string | null $excludeId = null ) : boolean Checks whether a given set of ids is assigned to any entity exactly like it is given (no subset, no superset).
listEntries ( array $filter = [], array $filterOperators = [], integer | null $skip = null, integer | null $amount = null, string | null $sortField = null, boolean | null $sortAscending = null ) : Entity[] Gets a list of entities fullfilling the given filter or all if no selection was given.
popEvent ( string $moment, string $action ) : Closure | null Removes and returns the latest event for the given parameters.
pushEvent ( string $moment, string $action, Closure $function ) Adds an event to fire for the given parameters. The event function must have this signature: function (Entity $entity) and has to return true or false.
renderFile ( Entity $entity, string $entityName, string $field ) : Response Renders (outputs) a file of an entity. This includes setting headers like the file size, mimetype and name, too.
update ( Entity $entity ) : void Updates an existing entry in the datasource having the same id.
updateFiles ( Request $request, Entity $entity, string $entityName ) : boolean Updates the uploaded files of an updated entity.

Защищенные методы

Метод Описание
doDelete ( Entity $entity, boolean $deleteCascade ) : integer Performs the actual deletion.
enrichEntityWithMetaData ( mixed $id, Entity $entity ) Enriches an entity with metadata: id, version, created_at, updated_at
hydrate ( array $row ) : Entity Creates an {@see Entity} from the raw data array with the field name as keys and field values as values.
performOnFiles ( Entity $entity, string $entityName, Closure $function ) Executes a function for each file field of this entity.
shouldExecuteEvents ( Entity $entity, string $moment, string $action ) : boolean Executes the event chain of an entity.

Описание методов

countBy() абстрактный публичный Метод

Retrieves the amount of entities in the datasource fulfilling the given parameters.
abstract public countBy ( string $table, array $params, array $paramsOperators, boolean $excludeDeleted ) : integer
$table string the table to count in
$params array an array with the field names as keys and field values as values
$paramsOperators array the operators of the parameters like "=" defining the full condition of the field
$excludeDeleted boolean false, if soft deleted entries in the datasource should be counted, too
Результат integer the count fulfilling the given parameters

create() абстрактный публичный Метод

Persists the given entity as new entry in the datasource.
abstract public create ( Entity $entity ) : boolean
$entity Entity the entity to persist
Результат boolean true on successful creation

createEmpty() публичный Метод

Creates a new, empty entity instance having all fields prefilled with null or the defined value in case of fixed fields.
public createEmpty ( ) : Entity
Результат Entity the newly created entity

createFiles() публичный Метод

Creates the uploaded files of a newly created entity.
public createFiles ( Request $request, Entity $entity, string $entityName ) : boolean
$request Symfony\Component\HttpFoundation\Request the HTTP request containing the file data
$entity Entity the just created entity
$entityName string the name of the entity as this class here is not aware of it
Результат boolean true if all before events passed

delete() публичный Метод

Deletes an entry from the datasource.
public delete ( Entity $entity ) : integer
$entity Entity the entity to delete
Результат integer returns one of: - AbstractData::DELETION_SUCCESS -> successful deletion - AbstractData::DELETION_FAILED_STILL_REFERENCED -> failed deletion due to existing references - AbstractData::DELETION_FAILED_EVENT -> failed deletion due to a failed before delete event

deleteFile() публичный Метод

Deletes a specific file from an existing entity.
public deleteFile ( Entity $entity, string $entityName, string $field ) : boolean
$entity Entity the entity to delete the file from
$entityName string the name of the entity as this class here is not aware of it
$field string the field of the entity containing the file to be deleted
Результат boolean true on successful deletion

deleteFiles() публичный Метод

Deletes all files of an existing entity.
public deleteFiles ( Entity $entity, string $entityName ) : boolean
$entity Entity the entity to delete the files from
$entityName string the name of the entity as this class here is not aware of it
Результат boolean true on successful deletion

doDelete() абстрактный защищенный Метод

Performs the actual deletion.
abstract protected doDelete ( Entity $entity, boolean $deleteCascade ) : integer
$entity Entity the id of the entry to delete
$deleteCascade boolean whether to delete children and subchildren
Результат integer true on successful deletion

enrichEntityWithMetaData() защищенный Метод

Enriches an entity with metadata: id, version, created_at, updated_at
protected enrichEntityWithMetaData ( mixed $id, Entity $entity )
$id mixed the id of the entity to enrich
$entity Entity the entity to enrich

fetchReferences() абстрактный публичный Метод

Adds the id and name of referenced entities to the given entities. Each reference field is before the raw id of the referenced entity and after the fetch, it's an array with the keys id and name.
abstract public fetchReferences ( array &$entities = null ) : void
$entities array
Результат void

get() абстрактный публичный Метод

Gets the entity with the given id.
abstract public get ( string $id ) : void
$id string the id
Результат void the entity belonging to the id or null if not existant

getDefinition() публичный Метод

Gets the {@see EntityDefinition} instance.
public getDefinition ( ) : EntityDefinition
Результат EntityDefinition the definition instance

getIdToNameMap() абстрактный публичный Метод

Gets ids and names of a table. Used for building up the dropdown box of reference type fields for example.
abstract public getIdToNameMap ( string $entity, string $nameField ) : array
$entity string the entity
$nameField string the field defining the name of the rows
Результат array an array with the ids as key and the names as values

hasManySet() абстрактный публичный Метод

Checks whether a given set of ids is assigned to any entity exactly like it is given (no subset, no superset).
abstract public hasManySet ( string $field, array $thatIds, string | null $excludeId = null ) : boolean
$field string the many field
$thatIds array the id set to check
$excludeId string | null one optional own id to exclude from the check
Результат boolean true if the set of ids exists for an entity

hydrate() защищенный Метод

Creates an {@see Entity} from the raw data array with the field name as keys and field values as values.
protected hydrate ( array $row ) : Entity
$row array the array with the raw data
Результат Entity the entity containing the array data then

listEntries() абстрактный публичный Метод

Gets a list of entities fullfilling the given filter or all if no selection was given.
abstract public listEntries ( array $filter = [], array $filterOperators = [], integer | null $skip = null, integer | null $amount = null, string | null $sortField = null, boolean | null $sortAscending = null ) : Entity[]
$filter array the filter all resulting entities must fulfill, the keys as field names
$filterOperators array the operators of the filter like "=" defining the full condition of the field
$skip integer | null if given and not null, it specifies the amount of rows to skip
$amount integer | null if given and not null, it specifies the maximum amount of rows to retrieve
$sortField string | null if given and not null, it specifies the field to sort the entries
$sortAscending boolean | null if given and not null, it specifies that the sort order is ascending, descending else
Результат Entity[] the entities fulfilling the filter or all if no filter was given

performOnFiles() защищенный Метод

Executes a function for each file field of this entity.
protected performOnFiles ( Entity $entity, string $entityName, Closure $function )
$entity Entity the just created entity
$entityName string the name of the entity as this class here is not aware of it
$function Closure the function to perform, takes $entity, $entityName and $field as parameter

popEvent() публичный Метод

Removes and returns the latest event for the given parameters.
public popEvent ( string $moment, string $action ) : Closure | null
$moment string the "moment" of the event, can be either "before" or "after"
$action string the "action" of the event, can be either "create", "update" or "delete"
Результат Closure | null the popped event or null if no event was available.

pushEvent() публичный Метод

The events are executed one after another in the added order as long as they return "true". The first event returning "false" will stop the process.
public pushEvent ( string $moment, string $action, Closure $function )
$moment string the "moment" of the event, can be either "before" or "after"
$action string the "action" of the event, can be either "create", "update" or "delete"
$function Closure the event function to be called if set

renderFile() публичный Метод

Renders (outputs) a file of an entity. This includes setting headers like the file size, mimetype and name, too.
public renderFile ( Entity $entity, string $entityName, string $field ) : Response
$entity Entity the entity to render the file from
$entityName string the name of the entity as this class here is not aware of it
$field string the field of the entity containing the file to be rendered
Результат Symfony\Component\HttpFoundation\Response the HTTP response, likely to be a streamed one

shouldExecuteEvents() защищенный Метод

Executes the event chain of an entity.
protected shouldExecuteEvents ( Entity $entity, string $moment, string $action ) : boolean
$entity Entity the entity having the event chain to execute
$moment string the "moment" of the event, can be either "before" or "after"
$action string the "action" of the event, can be either "create", "update" or "delete"
Результат boolean true on successful execution of the full chain or false if it broke at any point (and stopped the execution)

update() абстрактный публичный Метод

Updates an existing entry in the datasource having the same id.
abstract public update ( Entity $entity ) : void
$entity Entity the entity with the new data
Результат void

updateFiles() публичный Метод

Updates the uploaded files of an updated entity.
public updateFiles ( Request $request, Entity $entity, string $entityName ) : boolean
$request Symfony\Component\HttpFoundation\Request the HTTP request containing the file data
$entity Entity the updated entity
$entityName string the name of the entity as this class here is not aware of it
Результат boolean true on successful update

Описание свойств

$definition защищенное свойство

Holds the {@see EntityDefinition} entity definition.
protected $definition

$events защищенное свойство

Holds the events.
protected $events

$fileProcessor защищенное свойство

Holds the {@see FileProcessorInterface} file processor.
protected $fileProcessor