Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TComponent


TComponent class

TComponent is the base class for all PRADO components. TComponent implements the protocol of defining, using properties and events.

A property is defined by a getter method, and/or a setter method. Properties can be accessed in the way like accessing normal object members. Reading or writing a property will cause the invocation of the corresponding getter or setter method, e.g.,

  1. $a=$this->Text; // equivalent to $a=$this->getText();
  2. $this->Text='abc'; // equivalent to $this->setText('abc');
The signatures of getter and setter methods are as follows,
  1. // getter, defines a readable property 'Text'
  2. function getText() { ... }
  3. // setter, defines a writable property 'Text', with $value being the value to be set to the property
  4. function setText($value) { ... }
Property names are case-insensitive. It is recommended that they are written in the format of concatenated words, with the first letter of each word capitalized (e.g. DisplayMode, ItemStyle).

An event is defined by the presence of a method whose name starts with 'on'. The event name is the method name and is thus case-insensitive. An event can be attached with one or several methods (called event handlers). An event can be raised by calling raiseEvent method, upon which the attached event handlers will be invoked automatically in the order they are attached to the event. Event handlers must have the following signature,

  1. function eventHandlerFuncName($sender,$param) { ... }
where $sender refers to the object who is responsible for the raising of the event, and $param refers to a structure that may contain event-specific information. To raise an event (assuming named as 'Click') of a component, use
  1. $component->raiseEvent('OnClick');
To attach an event handler to an event, use one of the following ways,
  1. $component->OnClick=$callback; // or $component->OnClick->add($callback);
  2. $$component->attachEventHandler('OnClick',$callback);
The first two ways make use of the fact that $component->OnClick refers to the event handler list TList for the 'OnClick' event. The variable $callback contains the definition of the event handler that can be either a string referring to a global function name, or an array whose first element refers to an object and second element a method name/path that is reachable by the object, e.g.
  • 'buttonClicked' : buttonClicked($sender,$param);
  • array($object,'buttonClicked') : $object->buttonClicked($sender,$param);
  • array($object,'MainContent.SubmitButton.buttonClicked') : $object->MainContent->SubmitButton->buttonClicked($sender,$param);

Since: 3.0
Author: Qiang Xue <qiang.xue@gmail.com>

Method Summary
void
addParsedObject ( string|TComponent $object)
Processes an object that is created during parsing template.
void
attachEventHandler ( string $name, callback $handler)
Attaches an event handler to an event.
boolean
canGetProperty ( string $name)
Determines whether a property can be read.
boolean
canSetProperty ( string $name)
Determines whether a property can be set.
void
This method is invoked after the component is instantiated by a template.
boolean
detachEventHandler ( string $name, callback $handler)
Detaches an existing event handler.
mixed
evaluateExpression ( mixed $expression)
Evaluates a PHP expression in the context of this control.
string
evaluateStatements ( string $statements)
Evaluates a list of PHP statements.
TList
getEventHandlers ( mixed $name)
Returns the list of attached event handlers for an event.
mixed
getSubProperty ( string $path)
Evaluates a property path.
boolean
hasEvent ( string $name)
Determines whether an event is defined.
boolean
hasEventHandler ( mixed $name)
boolean
hasProperty ( string $name)
Determines whether a property is defined.
void
raiseEvent ( string $name, mixed $sender, TEventParameter $param)
Raises an event.
void
setSubProperty ( string $path, mixed $value)
Sets a value to a property path.
mixed
__get ( string $name)
Returns a property value or an event handler list by property or event name.
void
__set ( string $name, mixed $value)
Sets value of a component property.

Method Details

addParsedObject

public void addParsedObject (string|TComponent $object )

Processes an object that is created during parsing template.

The object can be either a component or a static text string. This method can be overridden to customize the handling of newly created objects in template. Only framework developers and control developers should use this method.

Input
string|TComponent$objecttext string or component parsed and instantiated in template
Output
Exception

attachEventHandler

public void attachEventHandler (string $name , callback $handler )

Attaches an event handler to an event.

The handler must be a valid PHP callback, i.e., a string referring to a global function name, or an array containing two elements with the first element being an object and the second element a method name of the object. In Prado, you can also use method path to refer to an event handler. For example, array($object,'Parent.buttonClicked') uses a method path that refers to the method $object->Parent->buttonClicked(...).

The event handler must be of the following signature,

  1. function handlerName($sender,$param) {}
where $sender represents the object that raises the event, and $param is the event parameter.

This is a convenient method to add an event handler. It is equivalent to getEventHandlers($name)->add($handler). For complete management of event handlers, use getEventHandlers to get the event handler list first, and then do various TList operations to append, insert or remove event handlers. You may also do these operations like getting and setting properties, e.g.,

  1. $component->OnClick[]=array($object,'buttonClicked');
  2. $component->OnClick->insertAt(0,array($object,'buttonClicked'));
which are equivalent to the following
  1. $component->getEventHandlers('OnClick')->add(array($object,'buttonClicked'));
  2. $component->getEventHandlers('OnClick')->insertAt(0,array($object,'buttonClicked'));

Input
string$namethe event name
callback$handlerthe event handler
Output
Exception
throwsTInvalidOperationException if the event does not exist

canGetProperty

public boolean canGetProperty (string $name )

Determines whether a property can be read.

A property can be read if the class has a getter method for the property name. Note, property name is case-insensitive.

Input
string$namethe property name
Output
boolean whether the property can be read
Exception

canSetProperty

public boolean canSetProperty (string $name )

Determines whether a property can be set.

A property can be written if the class has a setter method for the property name. Note, property name is case-insensitive.

Input
string$namethe property name
Output
boolean whether the property can be written
Exception

createdOnTemplate

public void createdOnTemplate (TComponent $parent )

This method is invoked after the component is instantiated by a template.

When this method is invoked, the component's properties have been initialized. The default implementation of this method will invoke the potential parent component's addParsedObject. This method can be overridden.

Input
TComponent$parentpotential parent of this control
Output
Exception

detachEventHandler

public boolean detachEventHandler (string $name , callback $handler )

Detaches an existing event handler.

This method is the opposite of attachEventHandler.

Input
string$nameevent name
callback$handlerthe event handler to be removed
Output
boolean if the removal is successful
Exception

evaluateExpression

public mixed evaluateExpression (mixed $expression )

Evaluates a PHP expression in the context of this control.

Input
mixed$expression
Output
mixed the expression result
Exception
throwsTInvalidOperationException if the expression is invalid

evaluateStatements

public string evaluateStatements (string $statements )

Evaluates a list of PHP statements.

Input
string$statementsPHP statements
Output
string content echoed or printed by the PHP statements
Exception
throwsTInvalidOperationException if the statements are invalid

getEventHandlers

public TList getEventHandlers (mixed $name )

Returns the list of attached event handlers for an event.

Input
mixed$name
Output
TList list of attached event handlers for an event
Exception
throwsTInvalidOperationException if the event is not defined

getSubProperty

public mixed getSubProperty (string $path )

Evaluates a property path.

A property path is a sequence of property names concatenated by '.' character. For example, 'Parent.Page' refers to the 'Page' property of the component's 'Parent' property value (which should be a component also).

Input
string$pathproperty path
Output
mixed the property path value
Exception

hasEvent

public boolean hasEvent (string $name )

Determines whether an event is defined.

An event is defined if the class has a method whose name is the event name prefixed with 'on'. Note, event name is case-insensitive.

Input
string$namethe event name
Output
Exception

hasEventHandler

public boolean hasEventHandler (mixed $name )

Input
mixed$name
Output
boolean whether an event has been attached one or several handlers
Exception

hasProperty

public boolean hasProperty (string $name )

Determines whether a property is defined.

A property is defined if there is a getter or setter method defined in the class. Note, property names are case-insensitive.

Input
string$namethe property name
Output
boolean whether the property is defined
Exception

raiseEvent

public void raiseEvent (string $name , mixed $sender , TEventParameter $param )

Raises an event.

This method represents the happening of an event and will invoke all attached event handlers for the event.

Input
string$namethe event name
mixed$senderthe event sender object
TEventParameter$paramthe event parameter
Output
Exception
throwsTInvalidOperationException if the event is undefined
throwsTInvalidDataValueException If an event handler is invalid

setSubProperty

public void setSubProperty (string $path , mixed $value )

Sets a value to a property path.

A property path is a sequence of property names concatenated by '.' character. For example, 'Parent.Page' refers to the 'Page' property of the component's 'Parent' property value (which should be a component also).

Input
string$pathproperty path
mixed$valuethe property path value
Output
Exception

__get

public mixed __get (string $name )

Returns a property value or an event handler list by property or event name.

Do not call this method. This is a PHP magic method that we override to allow using the following syntax to read a property:

  1. $value=$component->PropertyName;
and to obtain the event handler list for an event,
  1. $eventHandlerList=$component->EventName;

Input
string$namethe property name or the event name
Output
mixed the property value or the event handler list
Exception
throwsTInvalidOperationException if the property/event is not defined.

__set

public void __set (string $name , mixed $value )

Sets value of a component property.

Do not call this method. This is a PHP magic method that we override to allow using the following syntax to set a property or attach an event handler.

  1. $this->PropertyName=$value;
  2. $this->EventName=$handler;

Input
string$namethe property name or event name
mixed$valuethe property value or event handler
Output
Exception
throwsTInvalidOperationException If the property is not defined or read-only.