From f25b3b4272a2571247457eb2926af0f88cfca838 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 12 Jan 2014 21:33:46 +0100 Subject: Big quickstart doc overhaul, pt. 1 --- .../protected/pages/Fundamentals/Applications.page | 4 + .../protected/pages/Fundamentals/Architecture.page | 25 +- .../protected/pages/Fundamentals/Components.page | 360 --------------------- .../protected/pages/Fundamentals/Components1.page | 157 +++++++++ .../protected/pages/Fundamentals/Components2.page | 207 ++++++++++++ .../protected/pages/Fundamentals/Pages.page | 14 +- .../protected/pages/Fundamentals/Services.page | 5 +- 7 files changed, 407 insertions(+), 365 deletions(-) delete mode 100755 demos/quickstart/protected/pages/Fundamentals/Components.page create mode 100755 demos/quickstart/protected/pages/Fundamentals/Components1.page create mode 100644 demos/quickstart/protected/pages/Fundamentals/Components2.page (limited to 'demos/quickstart/protected/pages/Fundamentals') diff --git a/demos/quickstart/protected/pages/Fundamentals/Applications.page b/demos/quickstart/protected/pages/Fundamentals/Applications.page index 8e0b9e9a..71901170 100755 --- a/demos/quickstart/protected/pages/Fundamentals/Applications.page +++ b/demos/quickstart/protected/pages/Fundamentals/Applications.page @@ -7,7 +7,11 @@ An application is an instance of TApplication or its derived class. It

Applications are configured via application configurations. They are usually created in entry scripts like the following, +// load the prado entry script require_once('/path/to/prado.php'); +// or, if using composer: +require_once('vendor/autoload.php'); + $application = new TApplication; $application->run(); diff --git a/demos/quickstart/protected/pages/Fundamentals/Architecture.page b/demos/quickstart/protected/pages/Fundamentals/Architecture.page index 10f16c3f..c6bee7de 100755 --- a/demos/quickstart/protected/pages/Fundamentals/Architecture.page +++ b/demos/quickstart/protected/pages/Fundamentals/Architecture.page @@ -2,12 +2,31 @@

Architecture

-PRADO is primarily a presentational framework, although it is not limited to be so. The framework focuses on making Web programming, which deals most of the time with user interactions, to be component-based and event-driven so that developers can be more productive. The following class tree depicts some of the major classes provided by PRADO, +PRADO is primarily a presentational framework, although it is not limited to be so. The framework focuses on making Web programming, which deals most of the time with user interactions, to be component-based and event-driven so that developers can be more productive. The following class tree depicts some of the major classes provided by PRADO:

-When a PRADO application is processing a page request, its static object diagram can be shown as follows, +When a PRADO application is processing a page request, its static object diagram can be shown as follows:

- + +

+Once the main Application object gets created, it load the application configuration. +The minimal configuration defines a set of basic modules to parse the Request, create a proper Response, mantain the user Session, handle any Error and publish the needed Assets (images, css, javascript, etc). These helpers module will be available from anywhere inside the application code. +
+Additionally, any 3rd-party or custom module can be loaded, and external Parameters can be loaded from external configurations. +

+ +

+Once the basic infrastructure has been set up, the Request module parses the request trying to identify the requested route. Different routes can be handled by different services, but the default route for http requests is the Page Service. +
+The Page Service's role is to instanciate the requested Page, run it, apply any defined Theme and grab the result in order to build the Response. +

+ +

+A Page can be a simple script (.php), a Template (.page), or both. PRADO uses a very powerful template engine where Controls can be instanciated directly. +
+A Control is an self-contained widget that fullfills a specific task; they can be a simple script (.php), a Template (.page), or both. +

+ \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/Components.page b/demos/quickstart/protected/pages/Fundamentals/Components.page deleted file mode 100755 index 11235b56..00000000 --- a/demos/quickstart/protected/pages/Fundamentals/Components.page +++ /dev/null @@ -1,360 +0,0 @@ - -

Components

-

-A component is an instance of TComponent or its child class. The base class TComponent implements the mechanism of component properties and events. -

- -

Component Properties

-

-A component property can be viewed as a public variable describing a specific aspect of the component, such as the background color, the font size, etc. A property is defined by the existence of a getter and/or a setter method in the component class. For example, in TControl, we define its ID property using the following getter and setter methods, - -class TControl extends TComponent { - public function getID() { - ... - } - public function setID($value) { - ... - } -} - -

-

-To get or set the ID property, do as follows, just like working with a variable, - -$id = $component->ID; -$component->ID = $id; - -This is equivalent to the following, - -$id = $component->getID(); -$component->setID( $id ); - -

-

-A property is read-only if it has a getter method but no setter method. Since PHP method names are case-insensitive, property names are also case-insensitive. A component class inherits all its ancestor classes' properties. -

- -

Subproperties

-

-A subproperty is a property of some object-typed property. For example, TWebControl has a Font property which is of TFont type. Then the Name property of Font is referred to as a subproperty (with respect to TWebControl). -

-

-To get or set the Name subproperty, use the following method, - -$name = $component->getSubProperty('Font.Name'); -$component->setSubProperty('Font.Name', $name); - -This is equivalent to the following, - -$name = $component->getFont()->getName(); -$component->getFont()->setName( $name ); - -

- -

Js-friendly properties

-

-A JavaScript-friendly property is a property that can accept both simple strings and raw javascript. -Prado automatically encodes all properties sent clientside inside javascript blocks to avoid security problems (like injections or cross site scripting). -If a property is known to always contain only safe javascript code and its value needs to bypass this encoding, that property can be defined in a special way that will make Prado mark its value as "safe". -Js-friendly properties are identified by their name starting with 'js' (case insensitive): - -// getter, defines a readable property 'Text' -function getJsText() { … } -// setter, defines a writable property 'Text', with $value being the value to be set to the property -function setJsText(TJavaScriptLiteral $value) { … } - -Js-friendly properties can be accessed using both their Js-less name and their Js-enabled name: - -// set some simple text as property value -$component->Text = 'text'; -// set some javascript code as property value -$component->JsText = 'raw javascript'; - -In the first case, the property value will automatically gets encoded when sent clientside inside a javascript block. -In the second case, the property will be 'marked' as being a safe javascript statement and will not be encoded when rendered inside a javascript block. -This special handling makes use of the TJavaScriptLiteral class. -

- - -

Component Events

-

-Component events are special properties that take method names as their values. Attaching (setting) a method to an event will hook up the method to the places at which the event is raised. Therefore, the behavior of a component can be modified in a way that may not be foreseen during the development of the component. -

-

-A component event is defined by the existence of a method whose name starts with the word on. The event name is the method name and is thus case-insensitve. For example, in TButton, we have - -class TButton extends TWebControl { - public function onClick( $param ) { - ... - } -} - -This defines an event named OnClick, and a handler can be attached to the event using one of the following ways, - -$button->OnClick = $callback; -$button->OnClick->add( $callback ); -$button->OnClick[] = $callback; -$button->attachEventHandler( 'OnClick' , $callback ); - -

- 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. -

- - -

Global events

-

-With the addition of behaviors, a more expansive event model is needed. There -are two new event types (global and dynamic events) as well as a more comprehensive -behavior model that includes class wide behaviors. -

-

-A global event is defined by all events whose name starts with 'fx'. -The event name is potentially a method name and is thus case-insensitive. All 'fx' events -are valid as the whole 'fx' event/method space is global in nature. Any object may patch into -any global event by defining that event as a method. Global events have priorities -just like 'on' events; so as to be able to order the event execution. Due to the -nature of all events which start with 'fx' being valid, in effect, every object -has every 'fx' global event. It is simply an issue of tapping into the desired -global event. -

-

-A global event that starts with 'fx' can be called even if the object does not -implement the method of the global event. A call to a non-existing 'fx' method -will, at minimal, function and return null. If a method argument list has a first -parameter, it will be returned instead of null. This allows filtering and chaining. -'fx' methods do not automatically install and uninstall. To install and uninstall an -object's global event listeners, call the object's listen and -unlisten methods, respectively. An object may auto-install its global event -during __construct by overriding getAutoGlobalListen and returning true. -

-

-As of PHP version 5.3, nulled objects without code references will still continue to persist -in the global event queue because __destruct is not automatically called. In the common -__destruct method, if an object is listening to global events, then unlisten is called. -unlisten is required to be manually called before an object is -left without references if it is currently listening to any global events. This includes -class wide behaviors. -

-

-An object that contains a method that starts with 'fx' will have those functions -automatically receive those events of the same name after listen is called on the object. -

-

-An object may listen to a global event without defining an 'fx' method of the same name by -adding an object method to the global event list. For example -

- -$component->fxGlobalCheck=$callback; // or $component->OnClick->add($callback); -$component->attachEventHandler('fxGlobalCheck',array($object, 'someMethod')); - -

Events between Objects and their behaviors, Dynamic Events

-

-An intra-object/behavior event is defined by methods that start with 'dy'. Just as with -'fx' global events, every object has every dynamic event. Any call to a method that -starts with 'dy' will be handled, regardless of whether it is implemented. These -events are for communicating with attached behaviors. -

-

-Dynamic events can be used in a variety of ways. They can be used to tell behaviors -when a non-behavior method is called. Dynamic events could be used as data filters. -They could also be used to specify when a piece of code is to be run, eg. should the -loop process be performed on a particular piece of data. In this way, some control -is handed to the behaviors over the process and/or data. -

-

-If there are no handlers for an 'fx' or 'dy' event, it will return the first -parameter of the argument list. If there are no arguments, these events -will return null. If there are handlers an 'fx' method will be called directly -within the object. Global 'fx' events are triggered by calling raiseEvent. -For dynamic events where there are behaviors that respond to the dynamic events, a -TCallChain is developed. A call chain allows the behavior dynamic event -implementations to call further implementing behaviors within a chain. -

-

-If an object implements IDynamicMethods, all global and object dynamic -events will be sent to __dycall. In the case of global events, all -global events will trigger this method. In the case of behaviors, all undefined -dynamic events which are called will be passed through to this method. -

-

-

Behaviors

-

-There are two types of behaviors. There are individual object behaviors and -there are class wide behaviors. Class behaviors depend upon object behaviors. -

-

-When a new class implements IBehavior or IClassBehavior or -extends TBehavior or TClassBehavior, it may be added to an -object by calling the object's attachBehavior. The behaviors associated -name can then be used to enableBehavior or disableBehavior -the specific behavior. -

-

-All behaviors may be turned on and off via enableBehaviors and -disableBehaviors, respectively. To check if behaviors are on or off -a call to getBehaviorsEnabled will provide the variable. -

-

-Attaching and detaching whole sets of behaviors is done using -attachBehaviors and detachBehaviors. clearBehaviors -removes all of an object's behaviors. -

-

-asa returns a behavior of a specific name. isa is the -behavior inclusive function that acts as the PHP operator instanceof. -A behavior could provide the functionality of a specific class thus causing -the host object to act similarly to a completely different class. A behavior -would then implement IInstanceCheck to provide the identity of the -different class. -

-

-Class behaviors are similar to object behaviors except that the class behavior -is the implementation for all instances of the class. A class behavior -will have the object upon which is being called be prepended to the parameter -list. This way the object is known across the class behavior implementation. -

-

-Class behaviors are attached using attachClassBehavior and detached -using detachClassBehavior. Class behaviors are important in that -they will be applied to all new instances of a particular class. In this way -class behaviors become default behaviors to a new instances of a class in -__construct. Detaching a class behavior will remove the behavior -from the default set of behaviors created for an object when the object -is instanced. -

-

-Class behaviors are also added to all existing instances via the global 'fx' -event mechanism. When a new class behavior is added, the event -fxAttachClassBehavior is raised and all existing instances that are -listening to this global event (primarily after listen is called) -will have this new behavior attached. A similar process is used when -detaching class behaviors. Any objects listening to the global 'fx' event -fxDetachClassBehavior will have a class behavior removed. -

-

Dynamic Intra-Object Events

-

-Dynamic events start with 'dy'. This mechanism is used to allow objects -to communicate with their behaviors directly. The entire 'dy' event space -is valid. All attached, enabled behaviors that implement a dynamic event -are called when the host object calls the dynamic event. If there is no -implementation or behaviors, this returns null when no parameters are -supplied and will return the first parameter when there is at least one -parameter in the dynamic event. -

- - null == $this->dyBehaviorEvent(); - 5 == $this->dyBehaviorEvent(5); //when no behaviors implement this dynamic event - -

-Dynamic events can be chained together within behaviors to allow for data -filtering. Dynamic events are implemented within behaviors by defining the -event as a method. -

- -class TObjectBehavior extends TBehavior { - public function dyBehaviorEvent($param1, $callchain) { - //Do something, eg: $param1 += 13; - return $callchain->dyBehaviorEvent($param1); - } -} - -

-This implementation of a behavior and dynamic event will flow through to the -next behavior implementing the dynamic event. The first parameter is always -return when it is supplied. Otherwise a dynamic event returns null. -

-

-In the case of a class behavior, the object is also prepended to the dynamic -event. -

- -class TObjectClassBehavior extends TClassBehavior { - public function dyBehaviorEvent($hostobject, $param1, $callchain) { - //Do something, eg: $param1 += $hostobject->getNumber(); - return $callchain->dyBehaviorEvent($param1); - } -} - -

-

-When calling a dynamic event, only the parameters are passed. The host object -and the call chain are built into the framework. -

- -

Global Event and Dynamic event catching

- -

-Given that all global 'fx' events and dynamic 'dy' events are valid and -operational, there is a mechanism for catching events called that are not -implemented (similar to the built-in PHP method __call). When -a dynamic or global event is called but a behavior does not implement it, -yet desires to know when an undefined dynamic event is run, the behavior -implements the interface IDynamicMethods and method __dycall. -

-

-In the case of dynamic events, __dycall is supplied with the method -name and its parameters. When a global event is raised, via raiseEvent, -the method is the event name and the parameters are supplied. -

-

-When implemented, this catch-all mechanism is called for event global event event -when implemented outside of a behavior. Within a behavior, it will also be called -when the object to which the behavior is attached calls any unimplemented dynamic -event. This is the fall-back mechanism for informing a class and/or behavior -of when an global and/or undefined dynamic event is executed. -

- -

Namespaces

-

-A namespace refers to a logical grouping of some class names so that they can be differentiated from other class names even if their names are the same. Since PHP does not support namespace intrinsically, you cannot create instances of two classes who have the same name but with different definitions. To differentiate from user defined classes, all PRADO classes are prefixed with a letter 'T' (meaning 'Type'). Users are advised not to name their classes like this. Instead, they may prefix their class names with any other letter(s). -

-

-A namespace in PRADO is considered as a directory containing one or several class files. A class may be specified without ambiguity using such a namespace followed by the class name. Each namespace in PRADO is specified in the following format, -

-PathAlias.Dir1.Dir2 -
-where PathAlias is an alias of some directory, while Dir1 and Dir2 are subdirectories under that directory. A class named MyClass defined under Dir2 may now be fully qualified as PathAlias.Dir1.Dir2.MyClass. -

-

-To use a namespace in code, do as follows, - -Prado::using('PathAlias.Dir1.Dir2.*'); - -which appends the directory referred to by PathAlias.Dir1.Dir2 into PHP include path so that classes defined under that directory may be instantiated without the namespace prefix. You may also include an individual class definition by - -Prado::using('PathAlias.Dir1.Dir2.MyClass'); - -which will include the class file if MyClass is not defined. -

-

-For more details about defining path aliases, see application configuration section. -

- -

Component Instantiation

-

-Component instantiation means creating instances of component classes. There are two types of component instantation: static instantiation and dynamic instantiation. The created components are called static components and dynamic components, respectively. -

- -

Dynamic Component Instantiation

-

-Dynamic component instantiation means creating component instances in PHP code. It is the same as the commonly referred object creation in PHP. A component can be dynamically created using one of the following two methods in PHP, - -$component = new ComponentClassName; -$component = Prado::createComponent('ComponentType'); - -where ComponentType refers to a class name or a type name in namespace format (e.g. System.Web.UI.TControl). The second approach is introduced to compensate for the lack of namespace support in PHP. -

- -

Static Component Instantiation

-

-Static component instantiation is about creating components via configurations. The actual creation work is done by the PRADO framework. For example, in an application configuration, one can configure a module to be loaded when the application runs. The module is thus a static component created by the framework. Static component instantiation is more commonly used in templates. Every component tag in a template specifies a component that will be automatically created by the framework when the template is loaded. For example, in a page template, the following tag will lead to the creation of a TButton component on the page, - -<com:TButton Text="Register" /> - -

- -
diff --git a/demos/quickstart/protected/pages/Fundamentals/Components1.page b/demos/quickstart/protected/pages/Fundamentals/Components1.page new file mode 100755 index 00000000..a610045d --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Components1.page @@ -0,0 +1,157 @@ + +

Components: Part I

+

+A component is an instance of TComponent or its child class. The base class TComponent implements the mechanism of component properties and events. +

+ +

Component Properties

+

+A component property can be viewed as a public variable describing a specific aspect of the component, such as the background color, the font size, etc. A property is defined by the existence of a getter and/or a setter method in the component class. For example, in TControl, we define its ID property using the following getter and setter methods, + +class TControl extends TComponent { + public function getID() { + ... + } + public function setID($value) { + ... + } +} + +

+

+To get or set the ID property, do as follows, just like working with a variable, + +$id = $component->ID; +$component->ID = $id; + +This is equivalent to the following, + +$id = $component->getID(); +$component->setID( $id ); + +

+

+A property is read-only if it has a getter method but no setter method. Since PHP method names are case-insensitive, property names are also case-insensitive. A component class inherits all its ancestor classes' properties. +

+ +

Subproperties

+

+A subproperty is a property of some object-typed property. For example, TWebControl has a Font property which is of TFont type. Then the Name property of Font is referred to as a subproperty (with respect to TWebControl). +

+

+To get or set the Name subproperty, use the following method, + +$name = $component->getSubProperty('Font.Name'); +$component->setSubProperty('Font.Name', $name); + +This is equivalent to the following, + +$name = $component->getFont()->getName(); +$component->getFont()->setName( $name ); + +

+ +

Js-friendly properties

+

+A JavaScript-friendly property is a property that can accept both simple strings and raw javascript. +Prado automatically encodes all properties sent clientside inside javascript blocks to avoid security problems (like injections or cross site scripting). +If a property is known to always contain only safe javascript code and its value needs to bypass this encoding, that property can be defined in a special way that will make Prado mark its value as "safe". +Js-friendly properties are identified by their name starting with 'js' (case insensitive): + +// getter, defines a readable property 'Text' +function getJsText() { … } +// setter, defines a writable property 'Text', with $value being the value to be set to the property +function setJsText(TJavaScriptLiteral $value) { … } + +Js-friendly properties can be accessed using both their Js-less name and their Js-enabled name: + +// set some simple text as property value +$component->Text = 'text'; +// set some javascript code as property value +$component->JsText = 'raw javascript'; + +In the first case, the property value will automatically gets encoded when sent clientside inside a javascript block. +In the second case, the property will be 'marked' as being a safe javascript statement and will not be encoded when rendered inside a javascript block. +This special handling makes use of the TJavaScriptLiteral class. +

+ + +

Component Events

+

+Component events are special properties that take method names as their values. Attaching (setting) a method to an event will hook up the method to the places at which the event is raised. Therefore, the behavior of a component can be modified in a way that may not be foreseen during the development of the component. +

+

+A component event is defined by the existence of a method whose name starts with the word on. The event name is the method name and is thus case-insensitve. For example, in TButton, we have + +class TButton extends TWebControl { + public function onClick( $param ) { + ... + } +} + +This defines an event named OnClick, and a handler can be attached to the event using one of the following ways, + +$button->OnClick = $callback; +$button->OnClick->add( $callback ); +$button->OnClick[] = $callback; +$button->attachEventHandler( 'OnClick' , $callback ); + +

+ 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. +

+ + +

Namespaces

+

+A namespace refers to a logical grouping of some class names so that they can be differentiated from other class names even if their names are the same. Since PHP does not support namespace intrinsically, you cannot create instances of two classes who have the same name but with different definitions. To differentiate from user defined classes, all PRADO classes are prefixed with a letter 'T' (meaning 'Type'). Users are advised not to name their classes like this. Instead, they may prefix their class names with any other letter(s). +

+

+A namespace in PRADO is considered as a directory containing one or several class files. A class may be specified without ambiguity using such a namespace followed by the class name. Each namespace in PRADO is specified in the following format, +

+PathAlias.Dir1.Dir2 +
+where PathAlias is an alias of some directory, while Dir1 and Dir2 are subdirectories under that directory. A class named MyClass defined under Dir2 may now be fully qualified as PathAlias.Dir1.Dir2.MyClass. +

+

+To use a namespace in code, do as follows, + +Prado::using('PathAlias.Dir1.Dir2.*'); + +which appends the directory referred to by PathAlias.Dir1.Dir2 into PHP include path so that classes defined under that directory may be instantiated without the namespace prefix. You may also include an individual class definition by + +Prado::using('PathAlias.Dir1.Dir2.MyClass'); + +which will include the class file if MyClass is not defined. +

+

+For more details about defining path aliases, see application configuration section. +

+ +

Component Instantiation

+

+Component instantiation means creating instances of component classes. There are two types of component instantation: static instantiation and dynamic instantiation. The created components are called static components and dynamic components, respectively. +

+ +

Dynamic Component Instantiation

+

+Dynamic component instantiation means creating component instances in PHP code. It is the same as the commonly referred object creation in PHP. A component can be dynamically created using one of the following two methods in PHP, + +$component = new ComponentClassName; +$component = Prado::createComponent('ComponentType'); + +where ComponentType refers to a class name or a type name in namespace format (e.g. System.Web.UI.TControl). The second approach is introduced to compensate for the lack of namespace support in PHP. +

+ +

Static Component Instantiation

+

+Static component instantiation is about creating components via configurations. The actual creation work is done by the PRADO framework. For example, in an application configuration, one can configure a module to be loaded when the application runs. The module is thus a static component created by the framework. Static component instantiation is more commonly used in templates. Every component tag in a template specifies a component that will be automatically created by the framework when the template is loaded. For example, in a page template, the following tag will lead to the creation of a TButton component on the page, + +<com:TButton Text="Register" /> + +

+ +
diff --git a/demos/quickstart/protected/pages/Fundamentals/Components2.page b/demos/quickstart/protected/pages/Fundamentals/Components2.page new file mode 100644 index 00000000..7fc3e010 --- /dev/null +++ b/demos/quickstart/protected/pages/Fundamentals/Components2.page @@ -0,0 +1,207 @@ + +

Components: Part II

+ +

Global events

+

+With the addition of behaviors, a more expansive event model is needed. There +are two new event types (global and dynamic events) as well as a more comprehensive +behavior model that includes class wide behaviors. +

+

+A global event is defined by all events whose name starts with 'fx'. +The event name is potentially a method name and is thus case-insensitive. All 'fx' events +are valid as the whole 'fx' event/method space is global in nature. Any object may patch into +any global event by defining that event as a method. Global events have priorities +just like 'on' events; so as to be able to order the event execution. Due to the +nature of all events which start with 'fx' being valid, in effect, every object +has every 'fx' global event. It is simply an issue of tapping into the desired +global event. +

+

+A global event that starts with 'fx' can be called even if the object does not +implement the method of the global event. A call to a non-existing 'fx' method +will, at minimal, function and return null. If a method argument list has a first +parameter, it will be returned instead of null. This allows filtering and chaining. +'fx' methods do not automatically install and uninstall. To install and uninstall an +object's global event listeners, call the object's listen and +unlisten methods, respectively. An object may auto-install its global event +during __construct by overriding getAutoGlobalListen and returning true. +

+

+As of PHP version 5.3, nulled objects without code references will still continue to persist +in the global event queue because __destruct is not automatically called. In the common +__destruct method, if an object is listening to global events, then unlisten is called. +unlisten is required to be manually called before an object is +left without references if it is currently listening to any global events. This includes +class wide behaviors. +

+

+An object that contains a method that starts with 'fx' will have those functions +automatically receive those events of the same name after listen is called on the object. +

+

+An object may listen to a global event without defining an 'fx' method of the same name by +adding an object method to the global event list. For example +

+ +$component->fxGlobalCheck=$callback; // or $component->OnClick->add($callback); +$component->attachEventHandler('fxGlobalCheck',array($object, 'someMethod')); + +

Events between Objects and their behaviors, Dynamic Events

+

+An intra-object/behavior event is defined by methods that start with 'dy'. Just as with +'fx' global events, every object has every dynamic event. Any call to a method that +starts with 'dy' will be handled, regardless of whether it is implemented. These +events are for communicating with attached behaviors. +

+

+Dynamic events can be used in a variety of ways. They can be used to tell behaviors +when a non-behavior method is called. Dynamic events could be used as data filters. +They could also be used to specify when a piece of code is to be run, eg. should the +loop process be performed on a particular piece of data. In this way, some control +is handed to the behaviors over the process and/or data. +

+

+If there are no handlers for an 'fx' or 'dy' event, it will return the first +parameter of the argument list. If there are no arguments, these events +will return null. If there are handlers an 'fx' method will be called directly +within the object. Global 'fx' events are triggered by calling raiseEvent. +For dynamic events where there are behaviors that respond to the dynamic events, a +TCallChain is developed. A call chain allows the behavior dynamic event +implementations to call further implementing behaviors within a chain. +

+

+If an object implements IDynamicMethods, all global and object dynamic +events will be sent to __dycall. In the case of global events, all +global events will trigger this method. In the case of behaviors, all undefined +dynamic events which are called will be passed through to this method. +

+

+

Behaviors

+

+There are two types of behaviors. There are individual object behaviors and +there are class wide behaviors. Class behaviors depend upon object behaviors. +

+

+When a new class implements IBehavior or IClassBehavior or +extends TBehavior or TClassBehavior, it may be added to an +object by calling the object's attachBehavior. The behaviors associated +name can then be used to enableBehavior or disableBehavior +the specific behavior. +

+

+All behaviors may be turned on and off via enableBehaviors and +disableBehaviors, respectively. To check if behaviors are on or off +a call to getBehaviorsEnabled will provide the variable. +

+

+Attaching and detaching whole sets of behaviors is done using +attachBehaviors and detachBehaviors. clearBehaviors +removes all of an object's behaviors. +

+

+asa returns a behavior of a specific name. isa is the +behavior inclusive function that acts as the PHP operator instanceof. +A behavior could provide the functionality of a specific class thus causing +the host object to act similarly to a completely different class. A behavior +would then implement IInstanceCheck to provide the identity of the +different class. +

+

+Class behaviors are similar to object behaviors except that the class behavior +is the implementation for all instances of the class. A class behavior +will have the object upon which is being called be prepended to the parameter +list. This way the object is known across the class behavior implementation. +

+

+Class behaviors are attached using attachClassBehavior and detached +using detachClassBehavior. Class behaviors are important in that +they will be applied to all new instances of a particular class. In this way +class behaviors become default behaviors to a new instances of a class in +__construct. Detaching a class behavior will remove the behavior +from the default set of behaviors created for an object when the object +is instanced. +

+

+Class behaviors are also added to all existing instances via the global 'fx' +event mechanism. When a new class behavior is added, the event +fxAttachClassBehavior is raised and all existing instances that are +listening to this global event (primarily after listen is called) +will have this new behavior attached. A similar process is used when +detaching class behaviors. Any objects listening to the global 'fx' event +fxDetachClassBehavior will have a class behavior removed. +

+

Dynamic Intra-Object Events

+

+Dynamic events start with 'dy'. This mechanism is used to allow objects +to communicate with their behaviors directly. The entire 'dy' event space +is valid. All attached, enabled behaviors that implement a dynamic event +are called when the host object calls the dynamic event. If there is no +implementation or behaviors, this returns null when no parameters are +supplied and will return the first parameter when there is at least one +parameter in the dynamic event. +

+ + null == $this->dyBehaviorEvent(); + 5 == $this->dyBehaviorEvent(5); //when no behaviors implement this dynamic event + +

+Dynamic events can be chained together within behaviors to allow for data +filtering. Dynamic events are implemented within behaviors by defining the +event as a method. +

+ +class TObjectBehavior extends TBehavior { + public function dyBehaviorEvent($param1, $callchain) { + //Do something, eg: $param1 += 13; + return $callchain->dyBehaviorEvent($param1); + } +} + +

+This implementation of a behavior and dynamic event will flow through to the +next behavior implementing the dynamic event. The first parameter is always +return when it is supplied. Otherwise a dynamic event returns null. +

+

+In the case of a class behavior, the object is also prepended to the dynamic +event. +

+ +class TObjectClassBehavior extends TClassBehavior { + public function dyBehaviorEvent($hostobject, $param1, $callchain) { + //Do something, eg: $param1 += $hostobject->getNumber(); + return $callchain->dyBehaviorEvent($param1); + } +} + +

+

+When calling a dynamic event, only the parameters are passed. The host object +and the call chain are built into the framework. +

+ +

Global Event and Dynamic event catching

+ +

+Given that all global 'fx' events and dynamic 'dy' events are valid and +operational, there is a mechanism for catching events called that are not +implemented (similar to the built-in PHP method __call). When +a dynamic or global event is called but a behavior does not implement it, +yet desires to know when an undefined dynamic event is run, the behavior +implements the interface IDynamicMethods and method __dycall. +

+

+In the case of dynamic events, __dycall is supplied with the method +name and its parameters. When a global event is raised, via raiseEvent, +the method is the event name and the parameters are supplied. +

+

+When implemented, this catch-all mechanism is called for event global event event +when implemented outside of a behavior. Within a behavior, it will also be called +when the object to which the behavior is attached calls any unimplemented dynamic +event. This is the fall-back mechanism for informing a class and/or behavior +of when an global and/or undefined dynamic event is executed. +

+ +
diff --git a/demos/quickstart/protected/pages/Fundamentals/Pages.page b/demos/quickstart/protected/pages/Fundamentals/Pages.page index 19900937..0f3a8d9f 100755 --- a/demos/quickstart/protected/pages/Fundamentals/Pages.page +++ b/demos/quickstart/protected/pages/Fundamentals/Pages.page @@ -5,7 +5,7 @@ Pages are top-most controls that have no parent. The presentation of pages are directly displayed to end-users. Users access pages by sending page service requests.

-Each page must have a template file. The file name suffix must be .page. The file name (without suffix) is the page name. PRADO will try to locate a page class file under the directory containing the page template file. Such a page class file must have the same file name (suffixed with .php) as the template file. If the class file is not found, the page will take class TPage. +Each page can have a template file. The file name suffix must be .page. The file name (without suffix) is the page name. PRADO will try to locate a page class file under the directory containing the page template file. Such a page class file must have the same file name (suffixed with .php) as the template file. If the class file is not found, the page will take class TPage.

PostBack

@@ -14,6 +14,18 @@ A form submission is called postback if the submission is made to the pag

+

CallBack

+

+A callback is a special form submission that, instead of requiring a full page reload on the browser, gets executed in the background through an ajax call. So, a callback is considered a postback too, but not vice versa. +
+A callback is handled as a normal postback but, instead of re-rendering the entire page, only the specific changes occured on the page gets sent back to the client and merged with the current browser page. A typical callback response consists of: +

    +
  1. one or more pieces of html code that will replace existing content on the page;
  2. +
  3. the javascript instructions needed to update the page;
  4. +
  5. some specific fields used by prado to mantain the pagestate and add the needed external resources (stylesheets, javascript files, etc..).
  6. +
+

+

Page Lifecycles

Understanding the page lifecycles is crucial to grasp PRADO programming. Page lifecycles refer to the state transitions of a page when serving this page to end-users. They can be depicted in the following statechart, diff --git a/demos/quickstart/protected/pages/Fundamentals/Services.page b/demos/quickstart/protected/pages/Fundamentals/Services.page index 5e5889df..ee19a159 100755 --- a/demos/quickstart/protected/pages/Fundamentals/Services.page +++ b/demos/quickstart/protected/pages/Fundamentals/Services.page @@ -16,7 +16,7 @@ Developers may implement additional services for their applications. To make a s

Page Service

-PRADO implements TPageService to process users' page requests. Pages are stored under a directory specified by the BasePath property of the page service. The property defaults to pages directory under the application base path. You may change this default by configuring the service in the application configuration. +PRADO implements TPageService to process users' page requests. Pages are stored under a directory specified by the BasePath property of the page service. The property defaults to Pages directory under the application base path. You may change this default by configuring the service in the application configuration.

Pages may be organized into subdirectories under the BasePath. In each directory, there may be a page configuration file named config.xml, which contains configurations effective only when a page under that directory or a sub-directory is requested. For more details, see the page configuration section. @@ -30,5 +30,8 @@ http://hostname/index.php?page=Users.Register where the first example takes advantage of the fact that the page service is the default service and Home is the default page.

+

+More advanced url routes, like masking real page names and permitting the use of dynamic parameters can be created using the Url mapping module. +

-- cgit v1.2.3