PHP Class Sokil\Mongo\Structure

Inheritance: implements Sokil\Mongo\ArrayableInterface, implements JsonSerializable
Afficher le fichier Open project: sokil/php-mongo Class Usage Examples

Protected Properties

Свойство Type Description
$_data array
$schema array Initial document's data

Méthodes publiques

Méthode Description
__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 )

Méthodes protégées

Méthode Description
setDataReference ( array &$data ) : Structure IMPORTANT! Do not use this method

Private Methods

Méthode Description
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()

Method Details

__clone() final public méthode

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 méthode

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 méthode

public __get ( $name )

__isset() public méthode

public __isset ( $name )

__set() public méthode

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

addError() public méthode

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
Résultat Document

addErrors() public méthode

Add errors
public addErrors ( array $errors ) : Document
$errors array
Résultat Document

addValidatorNamespace() public méthode

Add own namespace of validators
public addValidatorNamespace ( type $namespace ) : Document
$namespace type
Résultat Document

append() public méthode

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
Résultat Structure

apply() public méthode

Apply modified document fields as original
public apply ( )

clearErrors() public méthode

Clear triggered and validation errors
public clearErrors ( )

clearTriggeredErrors() public méthode

Remove custom errors
public clearTriggeredErrors ( ) : Document
Résultat Document

get() public méthode

public get ( $selector )

getErrors() public méthode

Format: $errors['fieldName']['rule'] = 'message';
public getErrors ( ) : array
Résultat array list of validation errors

getModifiedFields() public méthode

public getModifiedFields ( )

getObject() public méthode

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
Résultat object representation of document with class, passed as argument

getObjectList() public méthode

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
Résultat object representation of document with class, passed as argument

getOriginalData() public méthode

public getOriginalData ( )

getScenario() public méthode

public getScenario ( )

has() public méthode

public has ( $selector )

hasErrors() public méthode

public hasErrors ( )

isModified() public méthode

public isModified ( $selector = null )

isScenario() public méthode

public isScenario ( $scenario )

isValid() public méthode

check if filled model params is valid
public isValid ( ) : boolean
Résultat boolean

jsonSerialize() public méthode

public jsonSerialize ( )

merge() public méthode

Merge array to current structure with setting modification mark
public merge ( array $data ) : Structure
$data array
Résultat Structure

mergeUnmodified() public méthode

Merge array to current structure without setting modification mark
public mergeUnmodified ( array $data ) : Structure
$data array
Résultat Structure

prepareToStore() public static méthode

public static prepareToStore ( $value )

replace() public méthode

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

reset() public méthode

Replace modified fields with original
public reset ( )

rules() public méthode

Validation rules
public rules ( ) : array
Résultat array

set() public méthode

Store value to specified selector in local cache
public set ( string $selector, mixed $value ) : Document
$selector string point-delimited field selector
$value mixed value
Résultat Document

setDataReference() protected méthode

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
Résultat Structure

setNoScenario() public méthode

public setNoScenario ( )

setScenario() public méthode

public setScenario ( $scenario )

toArray() public méthode

public toArray ( )

triggerError() public méthode

Add custom error which not reset after validation
public triggerError ( type $fieldName, type $ruleName, type $message ) : Document
$fieldName type
$ruleName type
$message type
Résultat Document

triggerErrors() public méthode

Add custom errors
public triggerErrors ( array $errors ) : Document
$errors array
Résultat Document

unsetField() public méthode

public unsetField ( $selector )

Property Details

$_data protected_oe property

Deprecation: use self::$schema to define initial data and getters or setters to get or set field's values.
protected array $_data
Résultat array

$schema protected_oe property

Initial document's data
protected array $schema
Résultat array