PHP Класс Gc\Core\Object

Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$data array Object attributes
$origData array Original data
$underscoreCache array Setter/Getter underscore transformation cache

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

Метод Описание
__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.

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

Метод Описание
__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

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

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

Set/Get attribute wrapper
public __call ( string $method, array $args ) : mixed | Object
$method string Method
$args array Arguments
Результат mixed | Object

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

Initialize constructor
public __construct ( )

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

Convert object attributes to array
public __toArray ( array $array = [] ) : array
$array array array of required attributes
Результат array

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

Convert object attributes to JSON
protected __toJson ( array $array = [] ) : string
$array array array of required attributes
Результат string

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

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[]
Результат string

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

Retains previous data in the object.
public addData ( array $array ) : Object
$array array Data
Результат Object

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

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
Результат mixed

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

Get Original data
public getOrigData ( string $key = null ) : mixed
$key string Key
Результат mixed

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

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
Результат boolean

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

Check if data has changed
public hasDataChangedFor ( string $field ) : boolean
$field string Field
Результат boolean

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

Initialize data
public init ( ) : void
Результат void

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

Implementation of ArrayAccess::offsetExists()
public offsetExists ( string $offset ) : boolean
$offset string Offset
Результат boolean

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

Implementation of ArrayAccess::offsetGet()
public offsetGet ( string $offset ) : mixed
$offset string Offset
Результат mixed

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

Implementation of ArrayAccess::offsetSet()
public offsetSet ( string $offset, mixed $value ) : void
$offset string Offset
$value mixed Value
Результат void

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

Implementation of ArrayAccess::offsetUnset()
public offsetUnset ( string $offset ) : void
$offset string Offset
Результат void

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

$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
Результат Object

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

Set Id
protected setId ( integer $id = null ) : Object
$id integer Id
Результат Object

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

Set Original data
public setOrigData ( string $key = null, mixed $data = null ) : Object
$key string Key
$data mixed Data
Результат Object

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

Public wrapper for __toArray
public toArray ( array $array = [] ) : array
$array array Data
Результат array

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

Public wrapper for __toJson
public toJson ( array $array = [] ) : string
$array array Data
Результат string

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

Will use $format as an template and substitute {{key}} for attributes
public toString ( string $format = '' ) : string
$format string Format
Результат string

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

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[]
Результат string

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

$this->setMyField($value) === $this->setData('my_field', $value) Uses cache to eliminate unneccessary preg_replace
protected underscore ( string $name ) : string
$name string Name
Результат string

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

$key can be a string only. Array will be ignored.
public unsetData ( string $key = null ) : Object
$key string Key
Результат Object

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

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

Object attributes
protected array $data
Результат array

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

Original data
protected array $origData
Результат array

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

Setter/Getter underscore transformation cache
protected static array $underscoreCache
Результат array