Class \Prado\Util\TBaseBehavior
This provides an init stub, events for attaching the behaviors' handlers (value) to events (keys), an \Prado\Util\getEnabled flag, the \Prado\Util\getName of the behavior, a \Prado\Util\getRetainDisabledHandlers flag to retain event handlers on the behavior being disabled, and attaching and detaching from an owner. Attaching and detaching call methods syncEventHandlers and detachEventHandlers, respectively, to manage the behaviors' handlers in the owner[s] events.
Behaviors use the TPriorityItemTrait to receive priority information from insertion into the owner's TPriorityMap of behaviors. When attaching events to an owner, the event handlers receive the same priority as the behavior in the owner.
Changing the \Prado\Util\setEnabled flag can automatically attach or detach events from the owner. If the behavior events should be preserved in the owner when disabled, set \Prado\Util\setRetainDisabledHandlers to true. To force detach event handlers, give this property the value null. When false, the default attachment logic applies where the behavior event handlers are attached where the owner has behaviors enabled and the behavior is enabled.
Event Handlers from events are cached and available by the method eventsLog. The eventsLog retains Closures across event handler management and multiple TClassBehavior owners.
Class hierarchy
- \Prado\Util\TBaseBehavior implements IBaseBehavior uses TPriorityPropertyTrait
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 4.3.0
public
|
|
public
|
attach(TComponent $component) : mixed
Attaches the behavior object to a new owner component.
The default implementation will synchronize attachment of event handlers declared in eventsLog. Make sure you call the parent implementation if you override this method. |
public
|
detach(TComponent $component) : mixed
Detaches the behavior object from an owner component.
The default implementation will detach event handlers declared in eventsLog. Make sure you call this parent implementation if you override this method. |
public
|
events() : array<string|int, mixed>
Declares events and the corresponding event handler methods.
The events are defined by the owner component, while the handler methods defined in the behavior class. These events will be attached to the owner depending on the enable status and getRetainDisabledHandlers. The format of events is as follows: e.g. return ["onEvent" => function($sender, $param) {...}, "onInit" => "myInitHandler", 'onAnEvent' => [$this, 'methodHandler'], 'onOtherEvent' => [[$this, 'handlerMethod'], "behaviorMethod", function($sender, $param) {...}]; Subclasses should use mergeHandlers to combine event handlers with the parent's event handlers. For example:
Acceptable array values are string name of behavior method, callable, or an array of string behavior method names or callables. |
public
|
eventsLog() : array<string|int, mixed>
Returns the cached events of the behavior where Closures are retained. TClassBehavior
owners will all have the same Closure instances.
|
public
|
|
public
|
|
public
|
|
public
|
getRetainDisabledHandlers() : null|bool
RetainDisabledHandlers has three states:
1) "true" is to always install the event handlers regardless of behavior enabled
or owner behaviors enabled status.
|
public
|
getStrictEvents() : bool
By default, all events with handlers in {@see eventsLog} are attached or there
will be an error. When this is false, attaching behavior event handlers will
not fail if the owner is missing events and handlers are not attached. Put
another way, when false, behavior event handlers are optional rather than made
mandatory.
|
public
|
init(array<string|int, mixed>|TXmlElement $config) : mixed
This processes behavior configuration elements. This is usually called before
attach. This is only needed for complex behavior configurations.
|
public
static
|
mergeHandlers(array<string|int, mixed> ...$args) : array<string|int, mixed>
Merges the handlers of an event into an array of keys (as event names) and values
as an array of behavior method names (strings) and callable.
|
public
|
setEnabled(bool|string $value) : mixed
This method sets the enabled flag and synchronizes the behavior's handlers with
its owner[s].
|
public
|
|
public
|
setRetainDisabledHandlers(null|bool $value) : mixed
This changes the retaining of disabled behavior handlers and then synchronizes
the behavior's handlers with its owner[s]. There are three acceptable values:
1) "true" is to always install the event handlers regardless of behavior enabled
or owner behaviors enabled status.
|
public
|
syncEventHandlers([object|null $component = null ][, null|bool|int $attachOverride = 0 ]) : mixed
This synchronizes an owner's events of the behavior event handlers by attaching
or detaching where needed. A behaviors handlers are attached depending on whether
{@see getRetainDisabledHandlers} is true (or null) or both the owner and behavior are
[Behavior] enabled. The $attachOverride will set RetainDisabledHandlers when not
its default value 0 and thus can act like {@see setRetainDisabledHandlers}.
|
protected
|
_getZappableSleepProps(array<string|int, mixed> &$exprops) : mixed
Returns an array with the names of all variables of this object that should NOT be serialized
because their value is the default one or useless to be cached for the next page loads.
Reimplement in derived classes to add new variables, but remember to also to call the parent implementation first. |
protected
|
|
protected
|
|
protected
abstract
|
getHandlersStatus([TComponent|null $component = null ]) : bool
This gets the attachment status of the behavior event handlers on the given
component.
|
protected
abstract
|
setHandlersStatus(TComponent $component, bool $attach) : bool
This sets the attachment status of the behavior event handlers on the given
component.
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |