PHP Класс AuditableBehavior

Store info about user which created entry, and user which modified an entry at the proper table. Also use a table called 'logs' (or other configurated for that) to save created/edited action for continuous changes history. Code comments in brazilian portuguese. ----- Behavior que permite log automágico de ações executadas em uma aplicação com usuários autenticados. Armazena informações do usuário que criou um registro, e do usuário que alterou o registro no próprio registro. Ainda utiliza um modelo auxiliar Logger (ou outro configurado para isso) para registrar ações de inserção/edição e manter um histórico contínuo de alterações. PHP version > 5.3.1 Licensed under The MIT License Redistributions of files must retain the above copyright notice.
Наследование: extends ModelBehavior
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$_modelOrder A copy of the model order to restore from
$_modelVirtualFields A copy of the model virtual fields to restore from
$_original array A copy of the object as it existed prior to the save. We're going to store this off, so we can calculate the deltas after save.
$_requestId string The requestId is a unique ID generated once per request to allow multiple record changes to be grouped by request

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

Метод Описание
afterDelete ( Model $Model ) : void Executed after a model is deleted.
afterSave ( Model $Model, boolean $created, array $options = [] ) : true Executed after a save operation completes.
beforeDelete ( Model $Model, boolean $cascade = true ) : true Executed before a delete operation.
beforeSave ( Model $Model, array $options = [] ) : true Executed before a save operation.
setup ( Model $Model, array $settings = [] ) : void Initiate behavior for the model using specified settings.

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

Метод Описание
_getModelData ( Model $Model ) : array | false Get model data
_isAuditLogModel ( Model $Model ) : boolean Check if the given model is one of AuditLog ones
_requestId ( ) : null | string Get request ID
_restoreVirtualFields ( Model $Model ) : void Restore the virtual fields & order
_unsetVirtualFieldsTemporarily ( Model $Model ) : void Preserve and unset virtual fields and order as we don't need them and since they can cause SQL errors

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

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

Retrieves the entire set model data contained to the primary object and any/all HABTM associated data that has been configured with the behavior. Additionally, for the HABTM data, all we care about is the IDs, so the data will be reduced to an indexed array of those IDs.
protected _getModelData ( Model $Model ) : array | false
$Model Model The model that uses the behavior.
Результат array | false The model data or false.

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

Check if the given model is one of AuditLog ones
protected _isAuditLogModel ( Model $Model ) : boolean
$Model Model The model to check
Результат boolean True if yes, else false.

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

Get request ID
protected _requestId ( ) : null | string
Результат null | string The request ID.

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

Restore the virtual fields & order
protected _restoreVirtualFields ( Model $Model ) : void
$Model Model The model to restore the virtual fields for.
Результат void

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

Preserve and unset virtual fields and order as we don't need them and since they can cause SQL errors
protected _unsetVirtualFieldsTemporarily ( Model $Model ) : void
$Model Model The model to unset the virtual fields from.
Результат void

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

Executed after a model is deleted.
public afterDelete ( Model $Model ) : void
$Model Model The model that is used for the delete operation.
Результат void

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

Executed after a save operation completes.
public afterSave ( Model $Model, boolean $created, array $options = [] ) : true
$Model Model The model that is used for the save operation.
$created boolean True, if the save operation was an insertion, false otherwise.
$options array The options data (unused).
Результат true Always true.

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

Executed before a delete operation.
public beforeDelete ( Model $Model, boolean $cascade = true ) : true
$Model Model The model using the behavior.
$cascade boolean Whether to cascade (unused).
Результат true Always true.

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

Executed before a save operation.
public beforeSave ( Model $Model, array $options = [] ) : true
$Model Model The model using the behavior.
$options array The options data (unused).
Результат true Always true.

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

Available settings: - ignore array, optional An array of property names to be ignored when records are created in the deltas table. - habtm array, optional An array of models that have a HABTM relationship with the acting model and whose changes should be monitored with the model.
public setup ( Model $Model, array $settings = [] ) : void
$Model Model The model using the behavior.
$settings array The settings overrides.
Результат void

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

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

A copy of the model order to restore from
protected $_modelOrder

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

A copy of the model virtual fields to restore from
protected $_modelVirtualFields

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

A copy of the object as it existed prior to the save. We're going to store this off, so we can calculate the deltas after save.
protected array $_original
Результат array

$_requestId защищенное статическое свойство

The requestId is a unique ID generated once per request to allow multiple record changes to be grouped by request
protected static string $_requestId
Результат string