Class \Prado\Util\TClassBehavior
Each instance of the TClassBehavior can have multiple owners. TClassBehavior tracks all its owners. It manages the attachment status of the behavior event handlers on each owner.
TClassBehavior is one of two types of behaviors in PRADO. The other type is the TBehavior where each instance can have only one owner and has per object state.
TClassBehavior must attach to owner components with the same behavior name.
Behaviors can be attached to instanced objects, with TComponent::attachbehavior, or to each class, the parent classes, interfaces, and first level traits used by the class(es) with TComponent::attachClassBehavior. Class-wide behaviors cannot be attached to the root class TComponent but can attach to any subclass. All new components with an attached class behavior will receive the behavior on instancing. Instances of a class will receive the class behavior if they are TComponent::listening.
TClassBehavior is a subclass of TBaseBehavior that implements the core behavior functionality. See IClassBehavior for implementation details.
The interface IClassBehavior is used by TComponent to inject the owner as the first method parameter, when the behavior method is called on the owner, so the behavior knows which owner is calling it.
Class hierarchy
- \Prado\Util\TClassBehavior implements IClassBehavior
- \Prado\Util\TBaseBehavior implements IBaseBehavior uses TPriorityPropertyTrait
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.2.3
public
|
|
public
|
attach(TComponent $component) : mixed
Attaches the behavior object to a new owner component. This is normally called
by the new owner when attaching a behavior, by {@see \Prado\TComponent::attachBehavior},
and not directly called.
The default implementation will add the new owner to the getOwners and synchronize the behavior event handlers (cached in eventsLog) with the new owner. Make sure you call this parent implementation if you override this method. |
public
|
detach(TComponent $component) : mixed
Detaches the behavior object from an owner component. This is normally called
by the owner when detaching a behavior, by {@see \Prado\TComponent::detachBehavior},
and not directly called.
The default implementation will remove the behavior event handlers (cached in eventsLog) from the owner and remove the owner from the getOwners. Make sure you call this parent implementation if you override this method. |
public
|
dyDisableBehaviors(TComponent $owner[, TCallChain|null $chain = null ]) : mixed
This dynamic event method tracks the "behaviors disabled" status of an owner. Subclasses
can call this method (as "parent::dyDisableBehaviors()") without the $chain and
it will delegate the $chain continuation to the subclass implementation.
|
public
|
dyEnableBehaviors(TComponent $owner[, TCallChain|null $chain = null ]) : mixed
This dynamic event method tracks the behaviors enabled status of an owner. Subclasses
can call this method (as "parent::dyEnableBehaviors()") without the $chain and it
will delegate the $chain continuation to the subclass implementation. At this point,
the behaviors are already enabled in the owner.
|
public
|
|
public
|
|
public
|
|
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
|
getHandlersStatus([TComponent|null $component = null ]) : bool
This gets the attachment status of the behavior handlers on the given component.
|
protected
|
initMap() : mixed
Initializes the WeakMap to manager the attachment status of owners.
Prior to PHP 8, this will use an array rather than a WeakMap. |
protected
|
setHandlersStatus(TComponent $component, bool $attach) : bool
This sets the attachment status of the behavior handlers on the given owner
component. It only returns true when there is a change in status.
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |