Class \Prado\Util\TBehavior
TBehavior is one of two types of behaviors in PRADO. The other type is the TClassBehavior where each instance can have multiple owners and is is designed to not retain per object information (acting stateless).
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.
TComponent clones instanced IBehavior when applied to whole classes.
TBehavior is a subclass of TBaseBehavior that implements the core behavior functionality. See IBehavior for implementation details.
Class hierarchy
- \Prado\Util\TBehavior implements IBehavior
- \Prado\Util\TBaseBehavior implements IBaseBehavior uses TPriorityPropertyTrait
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.2.3
public
|
|
public
|
attach(TComponent $owner) : mixed
Attaches the behavior object to the 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 set the \Prado\Util\getOwner property and synchronized the behavior event handlers (cached in eventsLog) with the owner. Make sure you call the parent implementation if you override this method. |
public
|
detach(TComponent $owner) : mixed
Detaches the behavior object from the 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 detaches the behavior event handlers (cached in eventsLog) and resets the owner. Make sure you call this parent implementation if you override this method. |
public
|
dyDisableBehaviors([TCallChain|null $chain = null ]) : mixed
This dynamic event method tracks the "behaviors disabled" status of an owner. Subclasses
can call this parent method (as "parent::dyDisableBehaviors()") without the $chain
and it will delegate the $chain continuation to the subclass implementation.
|
public
|
dyEnableBehaviors([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
|
getOwner() : object|null
This class stores the owner as a WeakReference. This method retrieves and re-references
the owner.
|
public
|
getOwners() : array<string|int, mixed>
This returns an array of the one owner that the TBehavior is attached to.
TClassBehavior could return multiple owners, but this type of behavior only has one. |
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 event handlers on the owner
component.
|
protected
|
setHandlersStatus(TComponent $component, bool $attach) : bool
This sets the attachment status of the behavior handlers on the owner. It only
returns true when there is a change in status.
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |