From 4226093cc034dfbd25a5b9e9aee2778e795ee42a Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 7 Apr 2006 03:46:10 +0000 Subject: Merge from 3.0 till 868. --- HISTORY | 2 + UPGRADE | 18 ++- .../protected/pages/Configurations/Templates2.page | 30 ++-- .../protected/pages/Controls/Expression.page | 13 +- .../pages/Controls/Samples/TDataGrid/Sample2.page | 2 +- .../pages/Controls/Samples/TDataGrid/Sample2.php | 2 + .../pages/Controls/Samples/TDataGrid/Sample6.page | 1 + .../pages/Controls/Samples/TDataList/Sample1.page | 10 +- .../pages/Controls/Samples/TDataList/Sample2.page | 12 +- .../pages/Controls/Samples/TExpression/Home.page | 6 - .../pages/Controls/Samples/TRepeater/Sample1.page | 20 +-- .../pages/Controls/Samples/TRepeater/Sample2.page | 8 +- .../pages/Controls/Samples/TRepeater/Sample3.page | 12 +- .../pages/Controls/Samples/TStatements/Home.page | 9 -- .../protected/pages/Controls/Statements.page | 19 +-- framework/Web/UI/TControl.php | 18 ++- framework/Web/UI/TTemplateManager.php | 166 +++++++++++++++++++-- framework/interfaces.php | 38 +++++ .../quickstart/Controls/DataGrid3TestCase.php | 8 +- .../quickstart/Controls/DataList2TestCase.php | 8 +- 20 files changed, 292 insertions(+), 110 deletions(-) diff --git a/HISTORY b/HISTORY index 3115e35f..b418a495 100644 --- a/HISTORY +++ b/HISTORY @@ -5,6 +5,8 @@ ENH: Format string in TDataGrid columns can now evaluate an expression (Qiang) Version 3.0RC2 April 16, 2006 ============================= BUG: Ticket#118 - Variables that may not have been initialized (Qiang) +CHG: Moved localize() into PradoBase (Qiang) +ENH: Optimized the representation and evaluation of template expressions (Qiang) Version 3.0RC1 April 5, 2006 ============================ diff --git a/UPGRADE b/UPGRADE index a811738d..391c55ff 100644 --- a/UPGRADE +++ b/UPGRADE @@ -1,6 +1,6 @@ - Upgrading Instructions for PRADO Framework v3.0RC1 - ================================================== + Upgrading Instructions for PRADO Framework v3.0.0 RC2 + ===================================================== !!!IMPORTANT!!! @@ -14,8 +14,14 @@ version B between A and C, you need to following the instructions for both A and B. -Upgrading from v3.0b --------------------- +Upgrading from v3.0.0 RC1 +------------------------- +- !!! The context of template expression/statements/databinding tags + is changed to the control owning the template. Previously, it was + the control representing the tag. + +Upgrading from v3.0.0 beta +-------------------------- - THttpSession.UseCustomStorage replaces the previous Storage. - Pagers in TDataGrid are now enclosed within panels. The event indicating their creation is changed to OnPagerCreated instead of OnItemCreated. @@ -27,8 +33,8 @@ Upgrading from v3.0b TLogger, TLogRouter, TDataFieldAccessor, TSimpleDateFormatter are moved to System.Util -Upgrading from v3.0a --------------------- +Upgrading from v3.0.0 alpha +--------------------------- All event names must start with 'On'. diff --git a/demos/quickstart/protected/pages/Configurations/Templates2.page b/demos/quickstart/protected/pages/Configurations/Templates2.page index f4f68b69..0971c828 100644 --- a/demos/quickstart/protected/pages/Configurations/Templates2.page +++ b/demos/quickstart/protected/pages/Configurations/Templates2.page @@ -10,52 +10,59 @@ Dynamic content tags are introduced as shortcuts to some commonly used
-An expression tag represents a PHP expression that is evaluated when the template control is being rendered. The expression evaluation result is inserted at the place where the tag resides in the template. Its format is as follows, +An expression tag represents a PHP expression that is evaluated when the template control is being rendered. The expression evaluation result is inserted at the place where the tag resides in the template. The context (namely $this) of the expression is the control owning the template. +
++The format of an expression tag is as follows, +
+For example, the following expression tag will display the current page title at the place, +
-Statement tags are similar to expression tags, except that statement tags contain PHP statements rather than expressions. The output of the PHP statements (using for example echo or print in PHP) are displayed at the place where the statement tag resides in the template. Inernally, a statement tag is represented by a TStatements control. Therefore, in the statements $this refers to the TStatements control. The format of statement tags is as follows, +Statement tags are similar to expression tags, except that statement tags contain PHP statements rather than expressions. The output of the PHP statements (using for example echo or print in PHP) are displayed at the place where the statement tag resides in the template. The context (namely $this) of the statements is the control owning the template. The format of statement tags is as follows, +
The following example displays the current time in Dutch at the place, +
-Databind tags are similar to expression tags, except that the expressions are evaluated only when a dataBind() call is invoked on the controls representing the databind tags. Internally, a TLiteral control is used to represent a databind tag and $this in the expression would refer to the control. The format of databind tags is as follows, +Databind tags are similar to expression tags, except that the expressions are evaluated only when a dataBind() call is invoked on the controls representing the databind tags. The context (namely $this) of a databind expression is the control owning the template. The format of databind tags is as follows, +
Parameter tags are used to insert application parameters at the place where they appear in the template. The format of parameter tags is as follows, +
Note, application parameters are usually defined in application configurations or page directory configurations. The parameters are evaluated when the template is instantiated.
@@ -66,9 +73,11 @@ Asset tags are used to publish private files and display the corresponding the UThe format of asset tags is as follows, +
where LocalFileName refers to a file path that is relative to the directory containing the current template file. The file path can be a single file or a directory. If the latter, the content in the whole directory will be made accessible by end-users.
@@ -79,9 +88,12 @@ BE VERY CAUTIOUS when you are using asset tags as it may expose to end-users fil
Localization tags represent localized texts. They are in the following format, +
where string will be translated to different languages according to the end-user's language preference. +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Expression.page b/demos/quickstart/protected/pages/Controls/Expression.page index c87f0ba4..80a45a3a 100644 --- a/demos/quickstart/protected/pages/Controls/Expression.page +++ b/demos/quickstart/protected/pages/Controls/Expression.page @@ -4,23 +4,14 @@-TExpression evaluates a PHP expression and displays the evaluation result. To specify the expression to be evaluated, set the Expression property. In a control template, expression tags are often used instead of the complete component tags when the main purpose is to display the evaluation result of some PHP expression. For example, the following two tags are equivalent, -
--TExpression evaluates the expression during the rendering control lifecycle. +TExpression evaluates a PHP expression and displays the evaluation result. To specify the expression to be evaluated, set the Expression property. Note, TExpression evaluates the expression during the rendering control lifecycle.
-The context of the expression in a TExpression control is the control itself. That is, $this represents the control object if it is present in the expression. For example, both of the following template tags will display the title of the page containing the TExpression control. +The context of the expression in a TExpression control is the control itself. That is, $this represents the control object if it is present in the expression. For example, the following template tag will display the title of the page containing the TExpression control.
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.page
index 6de3063a..79c1890c 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.page
@@ -42,7 +42,7 @@
+
ID | -<%#$this->Parent->DataItem['id']%> | +<%#$this->DataItem['id']%> |
Name | diff --git a/demos/quickstart/protected/pages/Controls/Samples/TExpression/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TExpression/Home.page index 2273f3c1..8c736ca9 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TExpression/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TExpression/Home.page @@ -10,12 +10,6 @@ Using expression component tag:||
-Using shortcut expression tag: - | -<%= $this->Page->PagePath %> - |
-TStatements evaluates a sequence of PHP statements and displays the content rendered by the statements. To specify the PHP statements to be evaluated, set the Statements property. In a control template, statement tags are often used instead of the complete component tags when the main purpose is to display the result rendered by some PHP statements. For example, the following two tags are equivalent, +TStatements evaluates a sequence of PHP statements and displays the content rendered by the statements. To specify the PHP statements to be evaluated, set the Statements property. For example, the following component tag displays the current time on the Web page,
-TStatements evaluates the PHP statements during the rendering control lifecycle. Unlike TExpression, TStatements only displays the content 'echoed' within the statements. +Note, TStatements evaluates the PHP statements during the rendering control lifecycle. Unlike TExpression, TStatements only displays the content 'echoed' within the statements.
The context of the statements in a TStatements control is the control itself. That is, $this represents the control object if it is present in the statements. For example, the following statement tag will display the title of the page containing the TStatements control.
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 52ec9bb1..15965a74 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -68,7 +68,7 @@ Prado::using('System.Web.UI.TControlAdapter');
* @package System.Web.UI
* @since 3.0
*/
-class TControl extends TApplicationComponent
+class TControl extends TApplicationComponent implements IRenderable, IBindable
{
/**
* format of control ID
@@ -772,7 +772,7 @@ class TControl extends TApplicationComponent
if(isset($this->_rf[self::RF_CONTROLS]))
{
foreach($this->_rf[self::RF_CONTROLS] as $control)
- if($control instanceof TControl)
+ if($control instanceof IBindable)
$control->dataBind();
}
}
@@ -1416,10 +1416,12 @@ class TControl extends TApplicationComponent
{
foreach($this->_rf[self::RF_CONTROLS] as $control)
{
- if($control instanceof TControl)
- $control->renderControl($writer);
- else if(is_string($control))
+ if(is_string($control))
$writer->write($control);
+ else if($control instanceof TControl)
+ $control->renderControl($writer);
+ else if($control instanceof IRenderable)
+ $control->render($writer);
}
}
}
@@ -1660,13 +1662,13 @@ class TControlCollection extends TList
*/
public function insertAt($index,$item)
{
- if(is_string($item))
- parent::insertAt($index,$item);
- else if($item instanceof TControl)
+ if($item instanceof TControl)
{
parent::insertAt($index,$item);
$this->_o->addedControl($item);
}
+ else if(is_string($item) || ($item instanceof IRenderable))
+ parent::insertAt($index,$item);
else
throw new TInvalidDataTypeException('controlcollection_control_required');
}
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index 26cc9c3a..fa4cbcbf 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -126,8 +126,7 @@ class TTemplateManager extends TModule
* can be a property name, an event name or a regular tag attribute name.
* - directive: directive specifies the property values for the template owner.
* It is in the format of <% property name-value pairs %>
- * - expressions: expressions are shorthand of {@link TExpression} and {@link TStatements}
- * controls. They are in the formate of <= PHP expression > and < PHP statements >
+ * - expressions: They are in the formate of <= PHP expression > and <% PHP statements >
* - comments: There are two kinds of comments, regular HTML comments and special template comments.
* The former is in the format of <!-- comments -->, which will be treated as text strings.
* The latter is in the format of <%* comments %>, which will be stripped out.
@@ -310,7 +309,16 @@ class TTemplate extends TApplicationComponent implements ITemplate
}
}
else // string
- $parent->addParsedObject($object[1]);
+ {
+ if($object[1] instanceof TCompositeLiteral)
+ {
+ $o=clone $object[1];
+ $o->setContainer($tplControl);
+ $parent->addParsedObject($o);
+ }
+ else
+ $parent->addParsedObject($object[1]);
+ }
}
}
@@ -388,8 +396,7 @@ class TTemplate extends TApplicationComponent implements ITemplate
$component->$setter($this->getApplication()->getParameters()->itemAt($value[1]));
break;
case self::CONFIG_LOCALIZATION:
- Prado::using('System.I18N.Translation');
- $component->$setter(localize(trim($value[1])));
+ $component->$setter(Prado::localize($value[1]));
break;
default: // an error if reaching here
break;
@@ -532,12 +539,22 @@ class TTemplate extends TApplicationComponent implements ITemplate
if($matchStart>$textStart)
$tpl[$c++]=array($container,substr($input,$textStart,$matchStart-$textStart));
$textStart=$matchEnd+1;
+ $literal=trim(THttpUtility::htmlDecode($match[5][0]));
if($str[2]==='=') // expression
- $tpl[$c++]=array($container,'TExpression',array('Expression'=>THttpUtility::htmlDecode($match[5][0])));
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,$literal));
else if($str[2]==='%') // statements
- $tpl[$c++]=array($container,'TStatements',array('Statements'=>THttpUtility::htmlDecode($match[5][0])));
- else
- $tpl[$c++]=array($container,'TLiteral',array('Text'=>$this->parseAttribute($str)));
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_STATEMENTS,$literal));
+ else if($str[2]==='#')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_DATABINDING,$literal));
+ else if($str[2]==='$')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"));
+ else if($str[2]==='~')
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"));
+ else if($str[2]==='[')
+ {
+ $literal=trim(substr($literal,0,strlen($literal)-1));
+ $tpl[$c++]=array($container,array(TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')"));
+ }
}
else if(strpos($str,'