PHP Class Sokil\Mongo\Structure

Inheritance: implements Sokil\Mongo\ArrayableInterface, implements JsonSerializable
Datei anzeigen Open project: sokil/php-mongo Class Usage Examples

Protected Properties

Property Type Description
$_data array
$schema array Initial document's data

Public Methods

Method 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 )

Protected Methods

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

Private Methods

Method 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 method

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 method

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 method

public __get ( $name )

__isset() public method

public __isset ( $name )

__set() public method

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

addError() public method

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
return Document

addErrors() public method

Add errors
public addErrors ( array $errors ) : Document
$errors array
return Document

addValidatorNamespace() public method

Add own namespace of validators
public addValidatorNamespace ( type $namespace ) : Document
$namespace type
return Document

append() public method

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
return Structure

apply() public method

Apply modified document fields as original
public apply ( )

clearErrors() public method

Clear triggered and validation errors
public clearErrors ( )

clearTriggeredErrors() public method

Remove custom errors
public clearTriggeredErrors ( ) : Document
return Document

get() public method

public get ( $selector )

getErrors() public method

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

getModifiedFields() public method

public getModifiedFields ( )

getObject() public method

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

getObjectList() public method

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

getOriginalData() public method

public getOriginalData ( )

getScenario() public method

public getScenario ( )

has() public method

public has ( $selector )

hasErrors() public method

public hasErrors ( )

isModified() public method

public isModified ( $selector = null )

isScenario() public method

public isScenario ( $scenario )

isValid() public method

check if filled model params is valid
public isValid ( ) : boolean
return boolean

jsonSerialize() public method

public jsonSerialize ( )

merge() public method

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

mergeUnmodified() public method

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

prepareToStore() public static method

public static prepareToStore ( $value )

replace() public method

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

reset() public method

Replace modified fields with original
public reset ( )

rules() public method

Validation rules
public rules ( ) : array
return array

set() public method

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

setDataReference() protected method

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
return Structure

setNoScenario() public method

public setNoScenario ( )

setScenario() public method

public setScenario ( $scenario )

toArray() public method

public toArray ( )

triggerError() public method

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

triggerErrors() public method

Add custom errors
public triggerErrors ( array $errors ) : Document
$errors array
return Document

unsetField() public method

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
return array

$schema protected_oe property

Initial document's data
protected array $schema
return array