PHP Класс Sokil\Mongo\Structure

Наследование: implements Sokil\Mongo\ArrayableInterface, implements JsonSerializable
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$_data array
$schema array Initial document's data

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

Метод Описание
__clone ( ) Cloning not allowed because cloning of object not clone related aggregates of this object, so cloned object has links to original aggregates. This is difficult to handle.
__construct ( array $data = null, boolean | true $notModified = true )
__get ( $name )
__isset ( $name )
__set ( string $name, mixed $value ) Handle setting params through public property
addError ( string $fieldName, string $ruleName, string $message ) : Document Add validator error from validator classes and methods. This error reset on every re-validation
addErrors ( array $errors ) : Document Add errors
addValidatorNamespace ( type $namespace ) : Document Add own namespace of validators
append ( type $selector, type $value ) : Structure If field not exist - set value.
apply ( ) Apply modified document fields as original
clearErrors ( ) Clear triggered and validation errors
clearTriggeredErrors ( ) : Document Remove custom errors
get ( $selector )
getErrors ( ) : array get list of validation errors
getModifiedFields ( )
getObject ( string $selector, string | callable $className = '\Sokil\Mongo\Structure' ) : object Get structure object from a document's value
getObjectList ( string $selector, string | callable $className = '\Sokil\Mongo\Structure' ) : object Get list of structure objects from list of values in mongo document
getOriginalData ( )
getScenario ( )
has ( $selector )
hasErrors ( )
isModified ( $selector = null )
isScenario ( $scenario )
isValid ( ) : boolean check if filled model params is valid
jsonSerialize ( )
merge ( array $data ) : Structure Merge array to current structure with setting modification mark
mergeUnmodified ( array $data ) : Structure Merge array to current structure without setting modification mark
prepareToStore ( $value )
replace ( array $data ) Replace data of document with passed.
reset ( ) Replace modified fields with original
rules ( ) : array Validation rules
set ( string $selector, mixed $value ) : Document Store value to specified selector in local cache
setNoScenario ( )
setScenario ( $scenario )
toArray ( )
triggerError ( type $fieldName, type $ruleName, type $message ) : Document Add custom error which not reset after validation
triggerErrors ( array $errors ) : Document Add custom errors
unsetField ( $selector )

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

Метод Описание
setDataReference ( array &$data ) : Structure IMPORTANT! Do not use this method

Приватные методы

Метод Описание
getValidatorClassNameByRuleName ( $ruleName )
isEmbeddedDocument ( array $array ) Check if array is sequential list
mergePartial ( array &$document, array $updatedDocument, string $prefix = null ) Recursive function to merge data for Structure::merge()
mergeUnmodifiedPartial ( array &$target, array $source ) Recursive function to merge data for Structure::mergeUnmodified()

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

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

Cloning not allowed because cloning of object not clone related aggregates of this object, so cloned object has links to original aggregates. This is difficult to handle.
final public __clone ( )

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

public __construct ( array $data = null, boolean | true $notModified = true )
$data array data to initialise structure
$notModified boolean | true define if data set as modified or not

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

public __get ( $name )

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

public __isset ( $name )

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

Handle setting params through public property
public __set ( string $name, mixed $value )
$name string
$value mixed

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

Add validator error from validator classes and methods. This error reset on every re-validation
public addError ( string $fieldName, string $ruleName, string $message ) : Document
$fieldName string dot-notated field name
$ruleName string name of validation rule
$message string error message
Результат Document

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

Add errors
public addErrors ( array $errors ) : Document
$errors array
Результат Document

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

Add own namespace of validators
public addValidatorNamespace ( type $namespace ) : Document
$namespace type
Результат Document

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

If field exists and is not array - convert to array and append If field -s array - append
public append ( type $selector, type $value ) : Structure
$selector type
$value type
Результат Structure

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

Apply modified document fields as original
public apply ( )

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

Clear triggered and validation errors
public clearErrors ( )

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

Remove custom errors
public clearTriggeredErrors ( ) : Document
Результат Document

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

public get ( $selector )

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

Format: $errors['fieldName']['rule'] = 'message';
public getErrors ( ) : array
Результат array list of validation errors

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

public getModifiedFields ( )

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

Get structure object from a document's value
public getObject ( string $selector, string | callable $className = '\Sokil\Mongo\Structure' ) : object
$selector string
$className string | callable string class name or closure, which accept data and return string class name
Результат object representation of document with class, passed as argument

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

Get list of structure objects from list of values in mongo document
public getObjectList ( string $selector, string | callable $className = '\Sokil\Mongo\Structure' ) : object
$selector string
$className string | callable Structure class name or closure, which accept data and return string class name of Structure
Результат object representation of document with class, passed as argument

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

public getOriginalData ( )

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

public getScenario ( )

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

public has ( $selector )

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

public hasErrors ( )

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

public isModified ( $selector = null )

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

public isScenario ( $scenario )

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

check if filled model params is valid
public isValid ( ) : boolean
Результат boolean

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

public jsonSerialize ( )

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

Merge array to current structure with setting modification mark
public merge ( array $data ) : Structure
$data array
Результат Structure

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

Merge array to current structure without setting modification mark
public mergeUnmodified ( array $data ) : Structure
$data array
Результат Structure

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

public static prepareToStore ( $value )

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

Document became unmodified
public replace ( array $data )
$data array new document data

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

Replace modified fields with original
public reset ( )

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

Validation rules
public rules ( ) : array
Результат array

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

Store value to specified selector in local cache
public set ( string $selector, mixed $value ) : Document
$selector string point-delimited field selector
$value mixed value
Результат Document

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

This method allow set data of document in external code. e.g. link data of document to GridFS file matadata. Modification of document's data will modify external data too. Note that also the opposite case also right - modification of external data will modify document's data directly, so document may be in unconsisted state.
protected setDataReference ( array &$data ) : Structure
$data array reference to data in external code
Результат Structure

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

public setNoScenario ( )

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

public setScenario ( $scenario )

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

public toArray ( )

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

Add custom error which not reset after validation
public triggerError ( type $fieldName, type $ruleName, type $message ) : Document
$fieldName type
$ruleName type
$message type
Результат Document

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

Add custom errors
public triggerErrors ( array $errors ) : Document
$errors array
Результат Document

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

public unsetField ( $selector )

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

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

Устаревший: use self::$schema to define initial data and getters or setters to get or set field's values.
protected array $_data
Результат array

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

Initial document's data
protected array $schema
Результат array