Callback
extends EntityBase
in package
This class represents a callback function.
This class supports three different kinds of callbacks: INLINE: An inline function. Note that these cannot be persisted!
$callback = new \Cx\Core_Modules\Access\Model\Entity\Callback( function($a) { return 2 * $a; } ); $callback(2);
REFERENCE: A PHP-style function or method reference.
$callback = new \Cx\Core_Modules\Access\Model\Entity\Callback( array('Cx\Core\Html\Controller\ViewGenerator', 'getVgSearchUrl') ); $callback(0, 'foo');
JSON: A JsonAdapter method. Params can be extended (but not overwritten) on invoke.
$callback = \Cx\Core_Modules\Access\Model\Entity\Callback::fromJsonAdapter( 'page', 'get', array('page'=>1) ); return $callback(array('lang' => 'en'));
Tags
Table of Contents
Constants
- TYPE_INLINE = 1
- TYPE_JSON = 3
- TYPE_REFERENCE = 2
Properties
- $callbackInfo : array<string|int, mixed>|callable
- $localeCodes : array<string|int, mixed>
- List of locale codes ordered by translation fallback order per Cx instance
- $nestingCount : int
- Counts the nesting level of __call()
- $stringRepresentationBlank : bool
- Whether blank string representations are valid
- $stringRepresentationFields : array<string|int, mixed>
- List of fields that should be available in the string representation
- $stringRepresentationFormat : string
- Sprintf format for the string representation
- $type : int
- $validators : array<string|int, mixed>
- Initialize this array as follows: array( 'columName' => Zend_Validate )
- $virtual : bool
- Defines if an entity is virtual and therefore not persistable.
Methods
- __call() : mixed
- Route methods like getName(), getType(), getDirectory(), etc.
- __construct() : mixed
- Creates a new callback from callback function info
- __get() : mixed
- This is an ugly solution to allow $this->cx to be available in all entity classes Since the entity's constructor is not called when an entity is loaded from DB this cannot be assigned there.
- __invoke() : mixed
- Calls the method or function specified by this Callback
- __sleep() : array<string|int, mixed>
- Advises PHP to only serialize $this->callbackInfo.
- __toString() : string
- Returns this entity's identifying value
- __wakeup() : void
- Recreates $this->type on wakeup
- fromJsonAdapter() : self
- Creates a callback for a JsonAdapter
- getCallbackInfo() : array<string|int, mixed>
- Returns the information about a callback
- getComponentController() : SystemComponent
- Returns the component controller for this component
- getKeyAsString() : string
- Returns this entity's key
- getTranslatedFieldValue() : mixed
- Returns the value of a translatable field using fallback mechanisms
- getType() : int
- Returns the type detected by analyzing $callbackInfo
- initializeValidators() : mixed
- Set $this->validators
- isSerializable() : bool
- Tells whether this callback can be serialized
- isVirtual() : bool
- Returns the virtuality of the entity
- setVirtual() : mixed
- Set the virtuality of the entity
- validate() : mixed
- findType() : mixed
- Sets $this->type by analyzing $this->callbackInfo
- getFallbackLocaleCodes() : array<string|int, mixed>
- Returns a list of all locale codes ordered by fallback order
- getStringRepresentationBlank() : bool
- Whether blank string representations are valid
- getStringRepresentationFields() : array<string|int, mixed>
- Returns a list of fields available in the string representation
- getStringRepresentationFormat() : string
- Returns the sprintf() format for the string representation
Constants
TYPE_INLINE
public
int
TYPE_INLINE
= 1
Inline function
TYPE_JSON
public
int
TYPE_JSON
= 3
JsonAdapter method
TYPE_REFERENCE
public
int
TYPE_REFERENCE
= 2
PHP-style referenced function
Properties
$callbackInfo
protected
array<string|int, mixed>|callable
$callbackInfo
Info about the callback function
$localeCodes
List of locale codes ordered by translation fallback order per Cx instance
protected
static array<string|int, mixed>
$localeCodes
= array()
Array in the form: array(<instanceId> => array(<localeCode>, ...))
Tags
$nestingCount
Counts the nesting level of __call()
protected
static int
$nestingCount
= 0
$stringRepresentationBlank
Whether blank string representations are valid
protected
bool
$stringRepresentationBlank
= false
Whether blank string representations are valid
Tags
$stringRepresentationFields
List of fields that should be available in the string representation
protected
array<string|int, mixed>
$stringRepresentationFields
= array()
List of field names
Tags
$stringRepresentationFormat
Sprintf format for the string representation
protected
string
$stringRepresentationFormat
= ''
Sprintf format string
Tags
$type
protected
int
$type
= 0
Type of this callback (see constants)
$validators
Initialize this array as follows: array( 'columName' => Zend_Validate )
protected
array<string|int, mixed>
$validators
= array()
$virtual
Defines if an entity is virtual and therefore not persistable.
protected
bool
$virtual
= false
Defaults to FALSE - not virtual.
Methods
__call()
Route methods like getName(), getType(), getDirectory(), etc.
public
__call(string $methodName, array<string|int, mixed> $arguments) : mixed
Parameters
- $methodName : string
-
Name of method to call
- $arguments : array<string|int, mixed>
-
List of arguments for the method to call
Tags
Attributes
- #[ReturnTypeWillChange]
Return values
mixed —Return value of the method to call
__construct()
Creates a new callback from callback function info
public
__construct(array<string|int, mixed>|callable $callbackInfo) : mixed
$callbackInfo can be an inline function, a PHP-style reference to a function or method or a reference to a JsonAdapter. References to JsonAdapters have the following format: array( <adapterName>, <methodName>, [<getParamsAsArray], [<postParamsAsArray] )
Parameters
- $callbackInfo : array<string|int, mixed>|callable
__get()
This is an ugly solution to allow $this->cx to be available in all entity classes Since the entity's constructor is not called when an entity is loaded from DB this cannot be assigned there.
public
__get(mixed $name) : mixed
Parameters
- $name : mixed
Attributes
- #[ReturnTypeWillChange]
__invoke()
Calls the method or function specified by this Callback
public
__invoke(mixed ...$args) : mixed
Parameters
- $args : mixed
-
,... Arguments as defined by the specified callback method or function. JsonAdapter methods accept zero, one or two arguments. Both arguments (if specified) need to be arrays. The first is used as GET, the second as POST params. Params specified in the Callback's definition cannot be overwritten this way.
Tags
Attributes
- #[ReturnTypeWillChange]
Return values
mixed —Return value of the callback method or function
__sleep()
Advises PHP to only serialize $this->callbackInfo.
public
__sleep() : array<string|int, mixed>
Does nothing if this Callback is not serializable (see isSerializable())
Return values
array<string|int, mixed> —List of properties to serialize
__toString()
Returns this entity's identifying value
public
__toString() : string
By default this returns the same as getKeyAsString(), but this method might get overridden by subclasses.
Return values
string —Identifying value for this entity
__wakeup()
Recreates $this->type on wakeup
public
__wakeup() : void
fromJsonAdapter()
Creates a callback for a JsonAdapter
public
static fromJsonAdapter(string $adapterName, string $adapterMethod[, array<string|int, mixed> $arguments = array() ][, array<string|int, mixed> $dataArguments = array() ]) : self
Parameters
- $adapterName : string
-
Name of the JsonAdapter
- $adapterMethod : string
-
Name of the adapter's method
- $arguments : array<string|int, mixed> = array()
-
(optional) "GET" arguments to pass
- $dataArguments : array<string|int, mixed> = array()
-
(optional) "POST" arguments to pass
Tags
Return values
self —Callback instance for the given JsonAdapter method
getCallbackInfo()
Returns the information about a callback
public
getCallbackInfo() : array<string|int, mixed>
See class and constructor DocBlock for more info
Return values
array<string|int, mixed> —Callback info
getComponentController()
Returns the component controller for this component
public
getComponentController() : SystemComponent
Return values
SystemComponentgetKeyAsString()
Returns this entity's key
public
final getKeyAsString([string $separator = '/' ]) : string
If this entity has a composite key, the fields are separated by $separator.
Parameters
- $separator : string = '/'
-
(optional) Separator for composite key fields, default "/"
Return values
string —Entity key as string
getTranslatedFieldValue()
Returns the value of a translatable field using fallback mechanisms
public
getTranslatedFieldValue(string $fieldName) : mixed
If the field is not translatable its value is returned anyway. Tries to return the value in the following locales (if non-empty):
- Current locale
- Default locale
- All other locales
Parameters
- $fieldName : string
-
Name of a translatable field
getType()
Returns the type detected by analyzing $callbackInfo
public
getType() : int
Return values
int —Type (see constants)
initializeValidators()
Set $this->validators
public
initializeValidators() : mixed
Validators can be found in lib/FRAMEWORK/Validator.class.php These will be executed if validate() is called
isSerializable()
Tells whether this callback can be serialized
public
isSerializable() : bool
Return values
bool —True for all types except "inline"
isVirtual()
Returns the virtuality of the entity
public
isVirtual() : bool
Return values
bool —TRUE if the entity is virtual, otherwise FALSE
setVirtual()
Set the virtuality of the entity
public
setVirtual(bool $virtual) : mixed
Parameters
- $virtual : bool
-
TRUE to set the entity as virtual or otherwise to FALSE
validate()
public
validate() : mixed
Tags
findType()
Sets $this->type by analyzing $this->callbackInfo
protected
findType() : mixed
getFallbackLocaleCodes()
Returns a list of all locale codes ordered by fallback order
protected
getFallbackLocaleCodes() : array<string|int, mixed>
- First entry is the current locale
- Second entry is the default locale (if different from current, it's omitted otherwise)
- Then all other locales follow (in no particular order)
Tags
Return values
array<string|int, mixed> —List of locale codes
getStringRepresentationBlank()
Whether blank string representations are valid
protected
getStringRepresentationBlank() : bool
Return values
bool —Whether blank string representations are valid
getStringRepresentationFields()
Returns a list of fields available in the string representation
protected
getStringRepresentationFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of field names
getStringRepresentationFormat()
Returns the sprintf() format for the string representation
protected
getStringRepresentationFormat() : string
Return values
string —sprintf() format string