Properties

$datamap

$datamap : 

Maps names used in sets and gets against unique names within the class, allowing independence from database column names.

Example: $datamap = [ 'db_name' => 'class_name' ];

Type

$dates

$dates : 

Type

$casts

$casts : 

Array of field names and the type of value to cast them as when they are accessed.

Type

$attributes

$attributes : array

Holds the current values of all class vars.

Type

array

$original

$original : array

Holds original copies of all class vars so we can determine what's actually been changed and not accidentally write nulls where we shouldn't.

Type

array

$_cast

$_cast : boolean

Holds info whenever properties have to be casted

Type

boolean

Methods

__construct()

__construct(array|null  $data = null) 

Allows filling in Entity parameters during construction.

Parameters

array|null $data

fill()

fill(array  $data = null) : \CodeIgniter\Entity

Takes an array of key/value pairs and sets them as class properties, using any `setCamelCasedProperty()` methods that may or may not exist.

Parameters

array $data

Returns

\CodeIgniter\Entity

toArray()

toArray(boolean  $onlyChanged = false, boolean  $cast = true) : array

General method that will return all public and protected values of this entity as an array. All values are accessed through the __get() magic method so will have any casts, etc applied to them.

Parameters

boolean $onlyChanged

If true, only return values that have changed since object creation

boolean $cast

If true, properties will be casted.

Throws

\Exception

Returns

array

toRawArray()

toRawArray(boolean  $onlyChanged = false) : array

Returns the raw values of the current attributes.

Parameters

boolean $onlyChanged

Returns

array

syncOriginal()

syncOriginal() : $this

Ensures our "original" values match the current values.

Returns

$this

hasChanged()

hasChanged(string  $key = null) : boolean

Checks a property to see if it has changed since the entity was created.

Or, without a parameter, checks if any properties have changed.

Parameters

string $key

Returns

boolean

__get()

__get(string  $key) : mixed

Magic method to allow retrieval of protected and private class properties either by their name, or through a `getCamelCasedProperty()` method.

Examples:

 $p = $this->my_property
 $p = $this->getMyProperty()

Parameters

string $key

Throws

\Exception

Returns

mixed

__set()

__set(string  $key, null  $value = null) : $this

Magic method to all protected/private class properties to be easily set, either through a direct access or a `setCamelCasedProperty()` method.

Examples:

 $this->my_property = $p;
 $this->setMyProperty() = $p;

Parameters

string $key
null $value

Throws

\Exception

Returns

$this

__unset()

__unset(string  $key) 

Unsets an attribute property.

Parameters

string $key

Throws

\ReflectionException

__isset()

__isset(string  $key) : boolean

Returns true if a property exists names $key, or a getter method exists named like for __get().

Parameters

string $key

Returns

boolean

setAttributes()

setAttributes(array  $data) : $this

Set raw data array without any mutations

Parameters

array $data

Returns

$this

mapProperty()

mapProperty(string  $key) : mixed|string

Checks the datamap to see if this column name is being mapped, and returns the mapped name, if any, or the original name.

Parameters

string $key

Returns

mixed|string

mutateDate()

mutateDate(  $value) : \CodeIgniter\I18n\Time

Converts the given string|timestamp|DateTime|Time instance into a \CodeIgniter\I18n\Time object.

Parameters

$value

Throws

\Exception

Returns

\CodeIgniter\I18n\Time

castAs()

castAs(  $value, string  $type) : mixed

Provides the ability to cast an item as a specific data type.

Add ? at the beginning of $type (i.e. ?string) to get NULL instead of casting $value if $value === null

Parameters

$value
string $type

Throws

\Exception

Returns

mixed

castAsJson()

castAsJson(mixed  $value, boolean  $asArray = false) : mixed

Cast as JSON

Parameters

mixed $value
boolean $asArray

Throws

\CodeIgniter\Exceptions\CastException

Returns

mixed