PHP Trait Esensi\Model\Traits\JugglingModelTrait

See also: Esensi\Model\Contracts\JugglingModelInterface
Author: Diego Caprioli ([email protected])
Author: Daniel LaBarge ([email protected])
显示文件 Open project: esensi/model

Protected Properties

Property Type Description
$juggling boolean Whether the model is type juggling attributes or not.

Public Methods

Method Description
__get ( string $key ) : mixed Dynamically retrieve attributes on the model.
__set ( string $key, mixed $value ) Dynamically set attributes on the model.
addJugglable ( string $attribute, string $type ) Add an attribute to the jugglable array.
attributesToArray ( ) : array Override attributesToArray() Eloquent Model method, to type juggle first, and then call the parent method.
buildJuggleMethod ( string $type ) : string Build the method name that the type normalizes to.
checkJuggleType ( string $type ) : boolean Checks whether the type is a type that can be juggled to.
getJugglable ( ) : array Get the juggable attributes.
getJuggleType ( string $attribute ) : string Gets the type that the attribute will be casted to.
getJuggling ( ) : boolean Returns whether or not the model will juggle attributes.
isJugglable ( string $attribute ) : boolean Returns whether the attribute is type jugglable.
isJuggleType ( string $type ) : boolean Returns whether the type is a type that can be juggled to.
juggle ( mixed $value, string $type ) : mixed Cast the value to the attribute's type as specified in the juggable array.
juggleArray ( mixed $value ) : array Returns the value as an array.
juggleAttribute ( string $attribute, string $value ) Casts a value to the coresponding attribute type and sets it on the attributes array of this model.
juggleAttributes ( ) Juggles all attributes that are configured to be juggled.
juggleBoolean ( mixed $value ) : boolean Returns the value as a boolean.
juggleDate ( mixed $value ) : Carbon\Carbon\Carbon Returns the value as a Carbon instance.
juggleDateTime ( mixed $value ) : string Returns a string formated as ISO standard of 0000-00-00 00:00:00.
juggleFloat ( mixed $value ) : float Returns the value as a float.
juggleInteger ( mixed $value ) : integer Returns the value as an integer.
juggleNull ( mixed $value ) : mixed | null Casts to null on empty.
juggleString ( mixed $value ) : string Returns the value as a string.
juggleTimestamp ( mixed $value ) : integer Returns the date as a Unix timestamp.
mergeJugglable ( array $attributes ) Merge an array of attributes with the jugglable array.
removeJugglable ( mixed $attributes ) Remove an attribute or several attributes from the jugglable array.
setJugglable ( array $attributes ) Set the jugglable attributes.
setJuggling ( $value ) Set whether or not the model will juggle attributes.

Protected Methods

Method Description
getDynamicJuggle ( string $key, mixed $value ) : mixed If juggling is active, it returns the juggleAttribute.
juggleType ( mixed $value, string $type ) : mixed Casts the value to the type. Possibles types are: boolean, integer, float, string, array, object, null.
setDynamicJuggle ( string $key, mixed $value ) If juggling is active, it sets the attribute in the model by type juggling the value first.

Method Details

__get() public method

Dynamically retrieve attributes on the model.
public __get ( string $key ) : mixed
$key string
return mixed

__set() public method

Dynamically set attributes on the model.
public __set ( string $key, mixed $value )
$key string
$value mixed

addJugglable() public method

Add an attribute to the jugglable array.
public addJugglable ( string $attribute, string $type )
$attribute string
$type string

attributesToArray() public method

Override attributesToArray() Eloquent Model method, to type juggle first, and then call the parent method.
See also: Illuminate\Database\Eloquent\Model::attributestoArray()
public attributesToArray ( ) : array
return array

buildJuggleMethod() public method

Build the method name that the type normalizes to.
public buildJuggleMethod ( string $type ) : string
$type string to cast
return string

checkJuggleType() public method

Checks whether the type is a type that can be juggled to.
public checkJuggleType ( string $type ) : boolean
$type string to cast
return boolean

getDynamicJuggle() protected method

If not it just returns the value as it was passed.
protected getDynamicJuggle ( string $key, mixed $value ) : mixed
$key string
$value mixed
return mixed

getJugglable() public method

Get the juggable attributes.
public getJugglable ( ) : array
return array

getJuggleType() public method

Gets the type that the attribute will be casted to.
public getJuggleType ( string $attribute ) : string
$attribute string
return string

getJuggling() public method

Returns whether or not the model will juggle attributes.
public getJuggling ( ) : boolean
return boolean

isJugglable() public method

Returns whether the attribute is type jugglable.
public isJugglable ( string $attribute ) : boolean
$attribute string name
return boolean

isJuggleType() public method

Returns whether the type is a type that can be juggled to.
public isJuggleType ( string $type ) : boolean
$type string to cast
return boolean

juggle() public method

Cast the value to the attribute's type as specified in the juggable array.
public juggle ( mixed $value, string $type ) : mixed
$value mixed
$type string
return mixed

juggleArray() public method

Returns the value as an array.
public juggleArray ( mixed $value ) : array
$value mixed
return array

juggleAttribute() public method

Casts a value to the coresponding attribute type and sets it on the attributes array of this model.
public juggleAttribute ( string $attribute, string $value )
$attribute string
$value string

juggleAttributes() public method

Juggles all attributes that are configured to be juggled.
public juggleAttributes ( )

juggleBoolean() public method

Returns the value as a boolean.
public juggleBoolean ( mixed $value ) : boolean
$value mixed
return boolean

juggleDate() public method

Returns the value as a Carbon instance.
See also: Illuminate\Database\Eloquent\Model::asDateTime()
public juggleDate ( mixed $value ) : Carbon\Carbon\Carbon
$value mixed
return Carbon\Carbon\Carbon

juggleDateTime() public method

Returns a string formated as ISO standard of 0000-00-00 00:00:00.
public juggleDateTime ( mixed $value ) : string
$value mixed
return string

juggleFloat() public method

Returns the value as a float.
public juggleFloat ( mixed $value ) : float
$value mixed
return float

juggleInteger() public method

Returns the value as an integer.
public juggleInteger ( mixed $value ) : integer
$value mixed
return integer

juggleNull() public method

Casts to null on empty.
public juggleNull ( mixed $value ) : mixed | null
$value mixed
return mixed | null

juggleString() public method

Returns the value as a string.
public juggleString ( mixed $value ) : string
$value mixed
return string

juggleTimestamp() public method

Returns the date as a Unix timestamp.
public juggleTimestamp ( mixed $value ) : integer
$value mixed
return integer

juggleType() protected method

Casts the value to the type. Possibles types are: boolean, integer, float, string, array, object, null.
protected juggleType ( mixed $value, string $type ) : mixed
$value mixed
$type string
return mixed

mergeJugglable() public method

Merge an array of attributes with the jugglable array.
public mergeJugglable ( array $attributes )
$attributes array to juggle

removeJugglable() public method

Remove an attribute or several attributes from the jugglable array.
public removeJugglable ( mixed $attributes )
$attributes mixed

setDynamicJuggle() protected method

If juggling is active, it sets the attribute in the model by type juggling the value first.
protected setDynamicJuggle ( string $key, mixed $value )
$key string
$value mixed

setJugglable() public method

Set the jugglable attributes.
public setJugglable ( array $attributes )
$attributes array to juggle

setJuggling() public method

Set whether or not the model will juggle attributes.
public setJuggling ( $value )

Property Details

$juggling protected_oe property

Whether the model is type juggling attributes or not.
protected bool $juggling
return boolean