PHP Class Gc\Core\Object

Datei anzeigen Open project: gotcms/gotcms Class Usage Examples

Protected Properties

Property Type Description
$data array Object attributes
$origData array Original data
$underscoreCache array Setter/Getter underscore transformation cache

Public Methods

Method Description
__call ( string $method, array $args ) : mixed | Object Set/Get attribute wrapper
__construct ( ) Initialize constructor
__toArray ( array $array = [] ) : array Convert object attributes to array
addData ( array $array ) : Object Add data to the object.
getData ( string $key = '', string | integer $index = null ) : mixed Retrieves data from the object
getOrigData ( string $key = null ) : mixed Get Original data
hasData ( string $key = '' ) : boolean If $key is empty, checks whether there's any data in the object Otherwise checks if the specified attribute is set.
hasDataChangedFor ( string $field ) : boolean Check if data has changed
init ( ) : void Initialize data
offsetExists ( string $offset ) : boolean Implementation of ArrayAccess::offsetExists()
offsetGet ( string $offset ) : mixed Implementation of ArrayAccess::offsetGet()
offsetSet ( string $offset, mixed $value ) : void Implementation of ArrayAccess::offsetSet()
offsetUnset ( string $offset ) : void Implementation of ArrayAccess::offsetUnset()
setData ( string | array $key, mixed $value = null ) : Object Overwrite data in the object.
setOrigData ( string $key = null, mixed $data = null ) : Object Set Original data
toArray ( array $array = [] ) : array Public wrapper for __toArray
toJson ( array $array = [] ) : string Public wrapper for __toJson
toString ( string $format = '' ) : string Public wrapper for __toString
toXml ( array $array = [], string $rootName = 'item', boolean $addOpenTag = false, boolean $addCdata = true ) : string Public wrapper for __toXml
unsetData ( string $key = null ) : Object Unset data from the object.

Protected Methods

Method Description
__toJson ( array $array = [] ) : string Convert object attributes to JSON
__toXml ( array $array = [], string $rootName = 'item', boolean $addOpenTag = false, boolean $addCdata = true ) : string Convert object attributes to XML
setId ( integer $id = null ) : Object Set Id
underscore ( string $name ) : string Converts field names for setters and geters

Method Details

__call() public method

Set/Get attribute wrapper
public __call ( string $method, array $args ) : mixed | Object
$method string Method
$args array Arguments
return mixed | Object

__construct() public method

Initialize constructor
public __construct ( )

__toArray() public method

Convert object attributes to array
public __toArray ( array $array = [] ) : array
$array array array of required attributes
return array

__toJson() protected method

Convert object attributes to JSON
protected __toJson ( array $array = [] ) : string
$array array array of required attributes
return string

__toXml() protected method

Convert object attributes to XML
protected __toXml ( array $array = [], string $rootName = 'item', boolean $addOpenTag = false, boolean $addCdata = true ) : string
$array array Array of required attributes
$rootName string Name of the root element
$addOpenTag boolean Insert
$addCdata boolean Insert CDATA[]
return string

addData() public method

Retains previous data in the object.
public addData ( array $array ) : Object
$array array Data
return Object

getData() public method

If $key is empty will return all the data as an array Otherwise it will return value of the attribute specified by $key If $index is specified it will assume that attribute data is an array and retrieve corresponding member.
public getData ( string $key = '', string | integer $index = null ) : mixed
$key string key
$index string | integer Index
return mixed

getOrigData() public method

Get Original data
public getOrigData ( string $key = null ) : mixed
$key string Key
return mixed

hasData() public method

If $key is empty, checks whether there's any data in the object Otherwise checks if the specified attribute is set.
public hasData ( string $key = '' ) : boolean
$key string Key
return boolean

hasDataChangedFor() public method

Check if data has changed
public hasDataChangedFor ( string $field ) : boolean
$field string Field
return boolean

init() public method

Initialize data
public init ( ) : void
return void

offsetExists() public method

Implementation of ArrayAccess::offsetExists()
public offsetExists ( string $offset ) : boolean
$offset string Offset
return boolean

offsetGet() public method

Implementation of ArrayAccess::offsetGet()
public offsetGet ( string $offset ) : mixed
$offset string Offset
return mixed

offsetSet() public method

Implementation of ArrayAccess::offsetSet()
public offsetSet ( string $offset, mixed $value ) : void
$offset string Offset
$value mixed Value
return void

offsetUnset() public method

Implementation of ArrayAccess::offsetUnset()
public offsetUnset ( string $offset ) : void
$offset string Offset
return void

setData() public method

$key can be string or array. If $key is string, the attribute value will be overwritten by $value If $key is an array, it will overwrite all the data in the object.
public setData ( string | array $key, mixed $value = null ) : Object
$key string | array Key
$value mixed Value
return Object

setId() protected method

Set Id
protected setId ( integer $id = null ) : Object
$id integer Id
return Object

setOrigData() public method

Set Original data
public setOrigData ( string $key = null, mixed $data = null ) : Object
$key string Key
$data mixed Data
return Object

toArray() public method

Public wrapper for __toArray
public toArray ( array $array = [] ) : array
$array array Data
return array

toJson() public method

Public wrapper for __toJson
public toJson ( array $array = [] ) : string
$array array Data
return string

toString() public method

Will use $format as an template and substitute {{key}} for attributes
public toString ( string $format = '' ) : string
$format string Format
return string

toXml() public method

Public wrapper for __toXml
public toXml ( array $array = [], string $rootName = 'item', boolean $addOpenTag = false, boolean $addCdata = true ) : string
$array array Data
$rootName string Root name
$addOpenTag boolean Insert
$addCdata boolean Insert CDATA[]
return string

underscore() protected method

$this->setMyField($value) === $this->setData('my_field', $value) Uses cache to eliminate unneccessary preg_replace
protected underscore ( string $name ) : string
$name string Name
return string

unsetData() public method

$key can be a string only. Array will be ignored.
public unsetData ( string $key = null ) : Object
$key string Key
return Object

Property Details

$data protected_oe property

Object attributes
protected array $data
return array

$origData protected_oe property

Original data
protected array $origData
return array

$underscoreCache protected_oe static_oe property

Setter/Getter underscore transformation cache
protected static array $underscoreCache
return array