PHP Class yii\base\Component

Inheritance: extends Object
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Méthode Description
__call ( string $name, array $params ) : mixed Calls the named method which is not a class method.
__clone ( ) This method is called after the object is created by cloning an existing one.
__get ( string $name ) : mixed Returns the value of a component property.
__isset ( string $name ) : boolean Checks if a property is set, i.e. defined and not null.
__set ( string $name, mixed $value ) Sets the value of a component property.
__unset ( string $name ) Sets a component property to be null.
attachBehavior ( string $name, string | array | Behavior $behavior ) : Behavior Attaches a behavior to this component.
attachBehaviors ( array $behaviors ) Attaches a list of behaviors to the component.
behaviors ( ) : array Returns a list of behaviors that this component should behave as.
canGetProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean Returns a value indicating whether a property can be read.
canSetProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean Returns a value indicating whether a property can be set.
detachBehavior ( string $name ) : null | Behavior Detaches a behavior from the component.
detachBehaviors ( ) Detaches all behaviors from the component.
ensureBehaviors ( ) Makes sure that the behaviors declared in Component::behaviors are attached to this component.
getBehavior ( string $name ) : null | Behavior Returns the named behavior object.
getBehaviors ( ) : Behavior[] Returns all behaviors attached to this component.
hasEventHandlers ( string $name ) : boolean Returns a value indicating whether there is any handler attached to the named event.
hasMethod ( string $name, boolean $checkBehaviors = true ) : boolean Returns a value indicating whether a method is defined.
hasProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean Returns a value indicating whether a property is defined for this component.
off ( string $name, callable $handler = null ) : boolean Detaches an existing event handler from this component.
on ( string $name, callable $handler, mixed $data = null, boolean $append = true ) Attaches an event handler to an event.
trigger ( string $name, Event $event = null ) Triggers an event.

Private Methods

Méthode Description
attachBehaviorInternal ( string | integer $name, string | array | Behavior $behavior ) : Behavior Attaches a behavior to this component.

Method Details

__call() public méthode

This method will check if any attached behavior has the named method and will execute it if available. Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.
public __call ( string $name, array $params ) : mixed
$name string the method name
$params array method parameters
Résultat mixed the method return value

__clone() public méthode

It removes all behaviors because they are attached to the old object.
public __clone ( )

__get() public méthode

This method will check in the following order and act accordingly: - a property defined by a getter: return the getter result - a property of a behavior: return the behavior property value Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $component->property;.
See also: __set()
public __get ( string $name ) : mixed
$name string the property name
Résultat mixed the property value or the value of a behavior's property

__isset() public méthode

This method will check in the following order and act accordingly: - a property defined by a setter: return whether the property is set - a property of a behavior: return whether the property is set - return false for non existing properties Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($component->property).
See also: http://php.net/manual/en/function.isset.php
public __isset ( string $name ) : boolean
$name string the property name or the event name
Résultat boolean whether the named property is set

__set() public méthode

This method will check in the following order and act accordingly: - a property defined by a setter: set the property value - an event in the format of "on xyz": attach the handler to the event "xyz" - a behavior in the format of "as xyz": attach the behavior named as "xyz" - a property of a behavior: set the behavior property value Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.
See also: __get()
public __set ( string $name, mixed $value )
$name string the property name or the event name
$value mixed the property value

__unset() public méthode

This method will check in the following order and act accordingly: - a property defined by a setter: set the property value to be null - a property of a behavior: set the property value to be null Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($component->property).
See also: http://php.net/manual/en/function.unset.php
public __unset ( string $name )
$name string the property name

attachBehavior() public méthode

This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the [[Behavior::attach()]] method.
See also: detachBehavior()
public attachBehavior ( string $name, string | array | Behavior $behavior ) : Behavior
$name string the name of the behavior.
$behavior string | array | Behavior the behavior configuration. This can be one of the following: - a [[Behavior]] object - a string specifying the behavior class - an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object.
Résultat Behavior the behavior object

attachBehaviors() public méthode

Each behavior is indexed by its name and should be a Behavior object, a string specifying the behavior class, or an configuration array for creating the behavior.
See also: attachBehavior()
public attachBehaviors ( array $behaviors )
$behaviors array list of behaviors to be attached to the component

behaviors() public méthode

Child classes may override this method to specify the behaviors they want to behave as. The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure: php 'behaviorName' => [ 'class' => 'BehaviorClass', 'property1' => 'value1', 'property2' => 'value2', ] Note that a behavior class must extend from Behavior. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using Component::getBehavior or be detached using Component::detachBehavior. Anonymous behaviors can not be retrieved or detached. Behaviors declared in this method will be attached to the component automatically (on demand).
public behaviors ( ) : array
Résultat array the behavior configurations.

canGetProperty() public méthode

A property can be read if: - the class has a getter method associated with the specified name (in this case, property name is case-insensitive); - the class has a member variable with the specified name (when $checkVars is true); - an attached behavior has a readable property of the given name (when $checkBehaviors is true).
See also: canSetProperty()
public canGetProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean
$name string the property name
$checkVars boolean whether to treat member variables as properties
$checkBehaviors boolean whether to treat behaviors' properties as properties of this component
Résultat boolean whether the property can be read

canSetProperty() public méthode

A property can be written if: - the class has a setter method associated with the specified name (in this case, property name is case-insensitive); - the class has a member variable with the specified name (when $checkVars is true); - an attached behavior has a writable property of the given name (when $checkBehaviors is true).
See also: canGetProperty()
public canSetProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean
$name string the property name
$checkVars boolean whether to treat member variables as properties
$checkBehaviors boolean whether to treat behaviors' properties as properties of this component
Résultat boolean whether the property can be written

detachBehavior() public méthode

The behavior's [[Behavior::detach()]] method will be invoked.
public detachBehavior ( string $name ) : null | Behavior
$name string the behavior's name.
Résultat null | Behavior the detached behavior. Null if the behavior does not exist.

detachBehaviors() public méthode

Detaches all behaviors from the component.
public detachBehaviors ( )

ensureBehaviors() public méthode

Makes sure that the behaviors declared in Component::behaviors are attached to this component.
public ensureBehaviors ( )

getBehavior() public méthode

Returns the named behavior object.
public getBehavior ( string $name ) : null | Behavior
$name string the behavior name
Résultat null | Behavior the behavior object, or null if the behavior does not exist

getBehaviors() public méthode

Returns all behaviors attached to this component.
public getBehaviors ( ) : Behavior[]
Résultat Behavior[] list of behaviors attached to this component

hasEventHandlers() public méthode

Returns a value indicating whether there is any handler attached to the named event.
public hasEventHandlers ( string $name ) : boolean
$name string the event name
Résultat boolean whether there is any handler attached to the event.

hasMethod() public méthode

A method is defined if: - the class has a method with the specified name - an attached behavior has a method with the given name (when $checkBehaviors is true).
public hasMethod ( string $name, boolean $checkBehaviors = true ) : boolean
$name string the property name
$checkBehaviors boolean whether to treat behaviors' methods as methods of this component
Résultat boolean whether the property is defined

hasProperty() public méthode

A property is defined if: - the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive); - the class has a member variable with the specified name (when $checkVars is true); - an attached behavior has a property of the given name (when $checkBehaviors is true).
See also: canGetProperty()
See also: canSetProperty()
public hasProperty ( string $name, boolean $checkVars = true, boolean $checkBehaviors = true ) : boolean
$name string the property name
$checkVars boolean whether to treat member variables as properties
$checkBehaviors boolean whether to treat behaviors' properties as properties of this component
Résultat boolean whether the property is defined

off() public méthode

This method is the opposite of Component::on.
See also: on()
public off ( string $name, callable $handler = null ) : boolean
$name string event name
$handler callable the event handler to be removed. If it is null, all handlers attached to the named event will be removed.
Résultat boolean if a handler is found and detached

on() public méthode

The event handler must be a valid PHP callback. The following are some examples: function ($event) { ... } // anonymous function [$object, 'handleClick'] // $object->handleClick() ['Page', 'handleClick'] // Page::handleClick() 'handleClick' // global function handleClick() The event handler must be defined with the following signature, function ($event) where $event is an Event object which includes parameters associated with the event.
See also: off()
public on ( string $name, callable $handler, mixed $data = null, boolean $append = true )
$name string the event name
$handler callable the event handler
$data mixed the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]].
$append boolean whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.

trigger() public méthode

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.
public trigger ( string $name, Event $event = null )
$name string the event name
$event Event the event parameter. If not set, a default [[Event]] object will be created.