diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-20 22:54:21 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-20 22:54:21 +0100 |
commit | f6b22febb41b3f552e36d5d0190ce8672b4d6d6e (patch) | |
tree | 71b9633c8848437fb7ea50ae96ee1e295ec5a721 /framework | |
parent | e2d11c31ca2671e812a8206627dffd00bfd192ea (diff) |
one class per file: framework/Web/UI/*.php
Diffstat (limited to 'framework')
23 files changed, 974 insertions, 1091 deletions
diff --git a/framework/Web/UI/IBroadcastEventReceiver.php b/framework/Web/UI/IBroadcastEventReceiver.php new file mode 100644 index 00000000..d0d86e8e --- /dev/null +++ b/framework/Web/UI/IBroadcastEventReceiver.php @@ -0,0 +1,33 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * IBroadcastEventReceiver interface + * + * If a control wants to check broadcast event, it must implement this interface. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface IBroadcastEventReceiver +{ + /** + * Handles broadcast event. + * This method is invoked automatically when an event is broadcasted. + * Within this method, you may check the event name given in + * the event parameter to determine whether you should respond to + * this event. + * @param TControl sender of the event + * @param TBroadCastEventParameter event parameter + */ + public function broadcastEventReceived($sender,$param); +}
\ No newline at end of file diff --git a/framework/Web/UI/IButtonControl.php b/framework/Web/UI/IButtonControl.php new file mode 100644 index 00000000..146ab1da --- /dev/null +++ b/framework/Web/UI/IButtonControl.php @@ -0,0 +1,96 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * IButtonControl interface + * + * IButtonControl specifies the common properties and events that must + * be implemented by a button control, such as {@link TButton}, {@link TLinkButton}, + * {@link TImageButton}. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface IButtonControl +{ + /** + * @return string caption of the button + */ + public function getText(); + + /** + * @param string caption of the button + */ + public function setText($value); + + /** + * @return boolean whether postback event trigger by this button will cause input validation + */ + public function getCausesValidation(); + + /** + * @param boolean whether postback event trigger by this button will cause input validation + */ + public function setCausesValidation($value); + + /** + * @return string the command name associated with the {@link onCommand OnCommand} event. + */ + public function getCommandName(); + + /** + * @param string the command name associated with the {@link onCommand OnCommand} event. + */ + public function setCommandName($value); + + /** + * @return string the parameter associated with the {@link onCommand OnCommand} event + */ + public function getCommandParameter(); + + /** + * @param string the parameter associated with the {@link onCommand OnCommand} event. + */ + public function setCommandParameter($value); + + /** + * @return string the group of validators which the button causes validation upon postback + */ + public function getValidationGroup(); + + /** + * @param string the group of validators which the button causes validation upon postback + */ + public function setValidationGroup($value); + + /** + * Raises <b>OnClick</b> event. + * @param TEventParameter event parameter to be passed to the event handlers + */ + public function onClick($param); + + /** + * Raises <b>OnCommand</b> event. + * @param TCommandEventParameter event parameter to be passed to the event handlers + */ + public function onCommand($param); + + /** + * @param boolean set by a panel to register this button as the default button for the panel. + */ + public function setIsDefaultButton($value); + + /** + * @return boolean true if this button is registered as a default button for a panel. + */ + public function getIsDefaultButton(); +}
\ No newline at end of file diff --git a/framework/Web/UI/INamingContainer.php b/framework/Web/UI/INamingContainer.php new file mode 100644 index 00000000..dd2634c0 --- /dev/null +++ b/framework/Web/UI/INamingContainer.php @@ -0,0 +1,22 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * INamingContainer interface. + * INamingContainer marks a control as a naming container. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface INamingContainer +{ +}
\ No newline at end of file diff --git a/framework/Web/UI/IPageStatePersister.php b/framework/Web/UI/IPageStatePersister.php new file mode 100644 index 00000000..e1c4e8b1 --- /dev/null +++ b/framework/Web/UI/IPageStatePersister.php @@ -0,0 +1,42 @@ +<?php +/** + * TPage class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * IPageStatePersister interface. + * + * IPageStatePersister interface is required for all page state persister + * classes. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.1 + */ +interface IPageStatePersister +{ + /** + * @param TPage the page that this persister works for + */ + public function getPage(); + /** + * @param TPage the page that this persister works for + */ + public function setPage(TPage $page); + /** + * Saves state to persistent storage. + * @param mixed state to be stored + */ + public function save($state); + /** + * Loads page state from persistent storage + * @return mixed the restored state + */ + public function load(); +}
\ No newline at end of file diff --git a/framework/Web/UI/IPostBackDataHandler.php b/framework/Web/UI/IPostBackDataHandler.php new file mode 100644 index 00000000..77da5080 --- /dev/null +++ b/framework/Web/UI/IPostBackDataHandler.php @@ -0,0 +1,42 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * IPostBackDataHandler interface + * + * If a control wants to load post data, it must implement this interface. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface IPostBackDataHandler +{ + /** + * Loads user input data. + * The implementation of this function can use $values[$key] to get the user input + * data that are meant for the particular control. + * @param string the key that can be used to retrieve data from the input data collection + * @param array the input data collection + * @return boolean whether the data of the control has been changed + */ + public function loadPostData($key,$values); + /** + * Raises postdata changed event. + * The implementation of this function should raise appropriate event(s) (e.g. OnTextChanged) + * indicating the control data is changed. + */ + public function raisePostDataChangedEvent(); + /** + * @return boolean whether postback causes the data change. Defaults to false for non-postback state. + */ + public function getDataChanged(); +}
\ No newline at end of file diff --git a/framework/Web/UI/IPostBackEventHandler.php b/framework/Web/UI/IPostBackEventHandler.php new file mode 100644 index 00000000..9ab2cb94 --- /dev/null +++ b/framework/Web/UI/IPostBackEventHandler.php @@ -0,0 +1,30 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * IPostBackEventHandler interface + * + * If a control wants to respond to postback event, it must implement this interface. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface IPostBackEventHandler +{ + /** + * Raises postback event. + * The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand) + * indicating the component is responsible for the postback event. + * @param string the parameter associated with the postback event + */ + public function raisePostBackEvent($param); +}
\ No newline at end of file diff --git a/framework/Web/UI/ISurroundable.php b/framework/Web/UI/ISurroundable.php new file mode 100644 index 00000000..42be16bb --- /dev/null +++ b/framework/Web/UI/ISurroundable.php @@ -0,0 +1,27 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * ISurroundable interface + * + * Identifies controls that may create an additional surrounding tag. The id of the + * tag can be obtained with {@link getSurroundingTagID}. + * + * @package System.Web.UI + * @since 3.1.2 + */ +interface ISurroundable +{ + /** + * @return string the id of the embedding tag of the control or the control's clientID if not surrounded + */ + public function getSurroundingTagID(); +}
\ No newline at end of file diff --git a/framework/Web/UI/ITemplate.php b/framework/Web/UI/ITemplate.php new file mode 100644 index 00000000..91701aab --- /dev/null +++ b/framework/Web/UI/ITemplate.php @@ -0,0 +1,31 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * ITemplate interface + * + * ITemplate specifies the interface for classes encapsulating + * parsed template structures. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface ITemplate +{ + /** + * Instantiates the template. + * Content in the template will be instantiated as components and text strings + * and passed to the specified parent control. + * @param TControl the parent control + */ + public function instantiateIn($parent); +}
\ No newline at end of file diff --git a/framework/Web/UI/ITheme.php b/framework/Web/UI/ITheme.php new file mode 100644 index 00000000..af9452b1 --- /dev/null +++ b/framework/Web/UI/ITheme.php @@ -0,0 +1,28 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * ITheme interface. + * + * This interface must be implemented by theme. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface ITheme +{ + /** + * Applies this theme to the specified control. + * @param TControl the control to be applied with this theme + */ + public function applySkin($control); +}
\ No newline at end of file diff --git a/framework/Web/UI/IValidatable.php b/framework/Web/UI/IValidatable.php new file mode 100644 index 00000000..5b8967e5 --- /dev/null +++ b/framework/Web/UI/IValidatable.php @@ -0,0 +1,36 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + + +/** + * IValidatable interface + * + * If a control wants to be validated by a validator, it must implement this interface. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface IValidatable +{ + /** + * @return mixed the value of the property to be validated. + */ + public function getValidationPropertyValue(); + /** + * @return boolean wether this control's validators validated successfully (must default to true) + */ + public function getIsValid(); + /** + * @return boolean wether this control's validators validated successfully + */ + public function setIsValid($value); +}
\ No newline at end of file diff --git a/framework/Web/UI/IValidator.php b/framework/Web/UI/IValidator.php new file mode 100644 index 00000000..d6e43146 --- /dev/null +++ b/framework/Web/UI/IValidator.php @@ -0,0 +1,47 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + + +/** + * IValidator interface + * + * If a control wants to validate user input, it must implement this interface. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +interface IValidator +{ + /** + * Validates certain data. + * The implementation of this function should validate certain data + * (e.g. data entered into TTextBox control). + * @return boolean whether the data passes the validation + */ + public function validate(); + /** + * @return boolean whether the previous {@link validate()} is successful. + */ + public function getIsValid(); + /** + * @param boolean whether the validator validates successfully + */ + public function setIsValid($value); + /** + * @return string error message during last validate + */ + public function getErrorMessage(); + /** + * @param string error message for the validation + */ + public function setErrorMessage($value); +}
\ No newline at end of file diff --git a/framework/Web/UI/TBroadcastEventParameter.php b/framework/Web/UI/TBroadcastEventParameter.php new file mode 100644 index 00000000..72cb4d82 --- /dev/null +++ b/framework/Web/UI/TBroadcastEventParameter.php @@ -0,0 +1,71 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * TBroadcastEventParameter class + * + * TBroadcastEventParameter encapsulates the parameter data for + * events that are broadcasted. The name of of the event is specified via + * {@link setName Name} property while the event parameter is via + * {@link setParameter Parameter} property. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +class TBroadcastEventParameter extends TEventParameter +{ + private $_name; + private $_param; + + /** + * Constructor. + * @param string name of the broadcast event + * @param mixed parameter of the broadcast event + */ + public function __construct($name='',$parameter=null) + { + $this->_name=$name; + $this->_param=$parameter; + } + + /** + * @return string name of the broadcast event + */ + public function getName() + { + return $this->_name; + } + + /** + * @param string name of the broadcast event + */ + public function setName($value) + { + $this->_name=$value; + } + + /** + * @return mixed parameter of the broadcast event + */ + public function getParameter() + { + return $this->_param; + } + + /** + * @param mixed parameter of the broadcast event + */ + public function setParameter($value) + { + $this->_param=$value; + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index 937bd84e..0bd96ab9 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -773,77 +773,3 @@ class TClientScriptManager extends TApplicationComponent throw new Exception('Operation invalid when page is already rendering'); } } - -/** - * TClientSideOptions abstract class. - * - * TClientSideOptions manages client-side options for components that have - * common client-side javascript behaviours and client-side events such as - * between ActiveControls and validators. - * - * @author <weizhuo[at]gmail[dot]com> - * @package System.Web.UI - * @since 3.0 - */ -abstract class TClientSideOptions extends TComponent -{ - /** - * @var TMap list of client-side options. - */ - private $_options; - - /** - * Adds on client-side event handler by wrapping the code within a - * javascript function block. If the code begins with "javascript:", the - * code is assumed to be a javascript function block rather than arbiturary - * javascript statements. - * @param string option name - * @param string javascript statements. - */ - protected function setFunction($name, $code) - { - if(!TJavaScript::isJsLiteral($code)) - $code = TJavaScript::quoteJsLiteral($this->ensureFunction($code)); - $this->setOption($name, $code); - } - - /** - * @return string gets a particular option, null if not set. - */ - protected function getOption($name) - { - if ($this->_options) - return $this->_options->itemAt($name); - else - return null; - } - - /** - * @param string option name - * @param mixed option value. - */ - protected function setOption($name, $value) - { - $this->getOptions()->add($name, $value); - } - - /** - * @return TMap gets the list of options as TMap - */ - public function getOptions() - { - if (!$this->_options) - $this->_options = Prado::createComponent('System.Collections.TMap'); - return $this->_options; - } - - /** - * Ensure that the javascript statements are wrapped in a javascript - * function block as <code>function(sender, parameter){ //code }</code>. - */ - protected function ensureFunction($javascript) - { - return "function(sender, parameter){ {$javascript} }"; - } -} - diff --git a/framework/Web/UI/TClientSideOptions.php b/framework/Web/UI/TClientSideOptions.php new file mode 100644 index 00000000..180e1025 --- /dev/null +++ b/framework/Web/UI/TClientSideOptions.php @@ -0,0 +1,84 @@ +<?php +/** + * TClientScriptManager and TClientSideOptions class file. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @author Gabor Berczi <gabor.berczi@devworx.hu> (lazyload additions & progressive rendering) + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * TClientSideOptions abstract class. + * + * TClientSideOptions manages client-side options for components that have + * common client-side javascript behaviours and client-side events such as + * between ActiveControls and validators. + * + * @author <weizhuo[at]gmail[dot]com> + * @package System.Web.UI + * @since 3.0 + */ +abstract class TClientSideOptions extends TComponent +{ + /** + * @var TMap list of client-side options. + */ + private $_options; + + /** + * Adds on client-side event handler by wrapping the code within a + * javascript function block. If the code begins with "javascript:", the + * code is assumed to be a javascript function block rather than arbiturary + * javascript statements. + * @param string option name + * @param string javascript statements. + */ + protected function setFunction($name, $code) + { + if(!TJavaScript::isJsLiteral($code)) + $code = TJavaScript::quoteJsLiteral($this->ensureFunction($code)); + $this->setOption($name, $code); + } + + /** + * @return string gets a particular option, null if not set. + */ + protected function getOption($name) + { + if ($this->_options) + return $this->_options->itemAt($name); + else + return null; + } + + /** + * @param string option name + * @param mixed option value. + */ + protected function setOption($name, $value) + { + $this->getOptions()->add($name, $value); + } + + /** + * @return TMap gets the list of options as TMap + */ + public function getOptions() + { + if (!$this->_options) + $this->_options = Prado::createComponent('System.Collections.TMap'); + return $this->_options; + } + + /** + * Ensure that the javascript statements are wrapped in a javascript + * function block as <code>function(sender, parameter){ //code }</code>. + */ + protected function ensureFunction($javascript) + { + return "function(sender, parameter){ {$javascript} }"; + } +} diff --git a/framework/Web/UI/TCommandEventParameter.php b/framework/Web/UI/TCommandEventParameter.php new file mode 100644 index 00000000..4357ce8e --- /dev/null +++ b/framework/Web/UI/TCommandEventParameter.php @@ -0,0 +1,55 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * TCommandEventParameter class + * + * TCommandEventParameter encapsulates the parameter data for <b>Command</b> + * event of button controls. You can access the name of the command via + * {@link getCommandName CommandName} property, and the parameter carried + * with the command via {@link getCommandParameter CommandParameter} property. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +class TCommandEventParameter extends TEventParameter +{ + private $_name; + private $_param; + + /** + * Constructor. + * @param string name of the command + * @param string parameter of the command + */ + public function __construct($name='',$parameter='') + { + $this->_name=$name; + $this->_param=$parameter; + } + + /** + * @return string name of the command + */ + public function getCommandName() + { + return $this->_name; + } + + /** + * @return string parameter of the command + */ + public function getCommandParameter() + { + return $this->_param; + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TCompositeLiteral.php b/framework/Web/UI/TCompositeLiteral.php new file mode 100644 index 00000000..d9af1174 --- /dev/null +++ b/framework/Web/UI/TCompositeLiteral.php @@ -0,0 +1,108 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + + +/** + * TCompositeLiteral class + * + * TCompositeLiteral is used internally by {@link TTemplate} for representing + * consecutive static strings, expressions and statements. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +class TCompositeLiteral extends TComponent implements IRenderable, IBindable +{ + const TYPE_EXPRESSION=0; + const TYPE_STATEMENTS=1; + const TYPE_DATABINDING=2; + private $_container=null; + private $_items=array(); + private $_expressions=array(); + private $_statements=array(); + private $_bindings=array(); + + /** + * Constructor. + * @param array list of items to be represented by TCompositeLiteral + */ + public function __construct($items) + { + $this->_items=array(); + $this->_expressions=array(); + $this->_statements=array(); + foreach($items as $id=>$item) + { + if(is_array($item)) + { + if($item[0]===self::TYPE_EXPRESSION) + $this->_expressions[$id]=$item[1]; + else if($item[0]===self::TYPE_STATEMENTS) + $this->_statements[$id]=$item[1]; + else if($item[0]===self::TYPE_DATABINDING) + $this->_bindings[$id]=$item[1]; + $this->_items[$id]=''; + } + else + $this->_items[$id]=$item; + } + } + + /** + * @return TComponent container of this component. It serves as the evaluation context of expressions and statements. + */ + public function getContainer() + { + return $this->_container; + } + + /** + * @param TComponent container of this component. It serves as the evaluation context of expressions and statements. + */ + public function setContainer(TComponent $value) + { + $this->_container=$value; + } + + /** + * Evaluates the expressions and/or statements in the component. + */ + public function evaluateDynamicContent() + { + $context=$this->_container===null?$this:$this->_container; + foreach($this->_expressions as $id=>$expression) + $this->_items[$id]=$context->evaluateExpression($expression); + foreach($this->_statements as $id=>$statement) + $this->_items[$id]=$context->evaluateStatements($statement); + } + + /** + * Performs databindings. + * This method is required by {@link IBindable} + */ + public function dataBind() + { + $context=$this->_container===null?$this:$this->_container; + foreach($this->_bindings as $id=>$binding) + $this->_items[$id]=$context->evaluateExpression($binding); + } + + /** + * Renders the content stored in this component. + * This method is required by {@link IRenderable} + * @param ITextWriter + */ + public function render($writer) + { + $writer->write(implode('',$this->_items)); + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index e5e6fa18..e32fb371 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -1749,620 +1749,4 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable } } } -} - - -/** - * TControlCollection class - * - * TControlCollection implements a collection that enables - * controls to maintain a list of their child controls. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TControlCollection extends TList -{ - /** - * the control that owns this collection. - * @var TControl - */ - private $_o; - - /** - * Constructor. - * @param TControl the control that owns this collection. - * @param boolean whether the list is read-only - */ - public function __construct(TControl $owner,$readOnly=false) - { - $this->_o=$owner; - parent::__construct(null,$readOnly); - } - - /** - * @return TControl the control that owns this collection. - */ - protected function getOwner() - { - return $this->_o; - } - - /** - * Inserts an item at the specified position. - * This overrides the parent implementation by performing additional - * operations for each newly added child control. - * @param integer the speicified position. - * @param mixed new item - * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl. - */ - public function insertAt($index,$item) - { - 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'); - } - - /** - * Removes an item at the specified position. - * This overrides the parent implementation by performing additional - * cleanup work when removing a child control. - * @param integer the index of the item to be removed. - * @return mixed the removed item. - */ - public function removeAt($index) - { - $item=parent::removeAt($index); - if($item instanceof TControl) - $this->_o->removedControl($item); - return $item; - } - - /** - * Overrides the parent implementation by invoking {@link TControl::clearNamingContainer} - */ - public function clear() - { - parent::clear(); - if($this->_o instanceof INamingContainer) - $this->_o->clearNamingContainer(); - } -} - -/** - * TEmptyControlCollection class - * - * TEmptyControlCollection implements an empty control list that prohibits adding - * controls to it. This is useful for controls that do not allow child controls. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TEmptyControlCollection extends TControlCollection -{ - /** - * Constructor. - * @param TControl the control that owns this collection. - */ - public function __construct(TControl $owner) - { - parent::__construct($owner,true); - } - - /** - * Inserts an item at the specified position. - * This overrides the parent implementation by ignoring new addition. - * @param integer the speicified position. - * @param mixed new item - */ - public function insertAt($index,$item) - { - if(!is_string($item)) // string is possible if property tag is used. we simply ignore it in this case - parent::insertAt($index,$item); // this will generate an exception in parent implementation - } -} - -/** - * INamingContainer interface. - * INamingContainer marks a control as a naming container. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface INamingContainer -{ -} - -/** - * IPostBackEventHandler interface - * - * If a control wants to respond to postback event, it must implement this interface. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface IPostBackEventHandler -{ - /** - * Raises postback event. - * The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand) - * indicating the component is responsible for the postback event. - * @param string the parameter associated with the postback event - */ - public function raisePostBackEvent($param); -} - -/** - * IPostBackDataHandler interface - * - * If a control wants to load post data, it must implement this interface. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface IPostBackDataHandler -{ - /** - * Loads user input data. - * The implementation of this function can use $values[$key] to get the user input - * data that are meant for the particular control. - * @param string the key that can be used to retrieve data from the input data collection - * @param array the input data collection - * @return boolean whether the data of the control has been changed - */ - public function loadPostData($key,$values); - /** - * Raises postdata changed event. - * The implementation of this function should raise appropriate event(s) (e.g. OnTextChanged) - * indicating the control data is changed. - */ - public function raisePostDataChangedEvent(); - /** - * @return boolean whether postback causes the data change. Defaults to false for non-postback state. - */ - public function getDataChanged(); -} - - -/** - * IValidator interface - * - * If a control wants to validate user input, it must implement this interface. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface IValidator -{ - /** - * Validates certain data. - * The implementation of this function should validate certain data - * (e.g. data entered into TTextBox control). - * @return boolean whether the data passes the validation - */ - public function validate(); - /** - * @return boolean whether the previous {@link validate()} is successful. - */ - public function getIsValid(); - /** - * @param boolean whether the validator validates successfully - */ - public function setIsValid($value); - /** - * @return string error message during last validate - */ - public function getErrorMessage(); - /** - * @param string error message for the validation - */ - public function setErrorMessage($value); -} - - -/** - * IValidatable interface - * - * If a control wants to be validated by a validator, it must implement this interface. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface IValidatable -{ - /** - * @return mixed the value of the property to be validated. - */ - public function getValidationPropertyValue(); - /** - * @return boolean wether this control's validators validated successfully (must default to true) - */ - public function getIsValid(); - /** - * @return boolean wether this control's validators validated successfully - */ - public function setIsValid($value); -} - -/** - * IBroadcastEventReceiver interface - * - * If a control wants to check broadcast event, it must implement this interface. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface IBroadcastEventReceiver -{ - /** - * Handles broadcast event. - * This method is invoked automatically when an event is broadcasted. - * Within this method, you may check the event name given in - * the event parameter to determine whether you should respond to - * this event. - * @param TControl sender of the event - * @param TBroadCastEventParameter event parameter - */ - public function broadcastEventReceived($sender,$param); -} - -/** - * ITheme interface. - * - * This interface must be implemented by theme. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface ITheme -{ - /** - * Applies this theme to the specified control. - * @param TControl the control to be applied with this theme - */ - public function applySkin($control); -} - -/** - * ITemplate interface - * - * ITemplate specifies the interface for classes encapsulating - * parsed template structures. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface ITemplate -{ - /** - * Instantiates the template. - * Content in the template will be instantiated as components and text strings - * and passed to the specified parent control. - * @param TControl the parent control - */ - public function instantiateIn($parent); -} - -/** - * IButtonControl interface - * - * IButtonControl specifies the common properties and events that must - * be implemented by a button control, such as {@link TButton}, {@link TLinkButton}, - * {@link TImageButton}. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -interface IButtonControl -{ - /** - * @return string caption of the button - */ - public function getText(); - - /** - * @param string caption of the button - */ - public function setText($value); - - /** - * @return boolean whether postback event trigger by this button will cause input validation - */ - public function getCausesValidation(); - - /** - * @param boolean whether postback event trigger by this button will cause input validation - */ - public function setCausesValidation($value); - - /** - * @return string the command name associated with the {@link onCommand OnCommand} event. - */ - public function getCommandName(); - - /** - * @param string the command name associated with the {@link onCommand OnCommand} event. - */ - public function setCommandName($value); - - /** - * @return string the parameter associated with the {@link onCommand OnCommand} event - */ - public function getCommandParameter(); - - /** - * @param string the parameter associated with the {@link onCommand OnCommand} event. - */ - public function setCommandParameter($value); - - /** - * @return string the group of validators which the button causes validation upon postback - */ - public function getValidationGroup(); - - /** - * @param string the group of validators which the button causes validation upon postback - */ - public function setValidationGroup($value); - - /** - * Raises <b>OnClick</b> event. - * @param TEventParameter event parameter to be passed to the event handlers - */ - public function onClick($param); - - /** - * Raises <b>OnCommand</b> event. - * @param TCommandEventParameter event parameter to be passed to the event handlers - */ - public function onCommand($param); - - /** - * @param boolean set by a panel to register this button as the default button for the panel. - */ - public function setIsDefaultButton($value); - - /** - * @return boolean true if this button is registered as a default button for a panel. - */ - public function getIsDefaultButton(); -} - -/** - * ISurroundable interface - * - * Identifies controls that may create an additional surrounding tag. The id of the - * tag can be obtained with {@link getSurroundingTagID}. - * - * @package System.Web.UI - * @since 3.1.2 - */ -interface ISurroundable -{ - /** - * @return string the id of the embedding tag of the control or the control's clientID if not surrounded - */ - public function getSurroundingTagID(); -} - -/** - * TBroadcastEventParameter class - * - * TBroadcastEventParameter encapsulates the parameter data for - * events that are broadcasted. The name of of the event is specified via - * {@link setName Name} property while the event parameter is via - * {@link setParameter Parameter} property. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TBroadcastEventParameter extends TEventParameter -{ - private $_name; - private $_param; - - /** - * Constructor. - * @param string name of the broadcast event - * @param mixed parameter of the broadcast event - */ - public function __construct($name='',$parameter=null) - { - $this->_name=$name; - $this->_param=$parameter; - } - - /** - * @return string name of the broadcast event - */ - public function getName() - { - return $this->_name; - } - - /** - * @param string name of the broadcast event - */ - public function setName($value) - { - $this->_name=$value; - } - - /** - * @return mixed parameter of the broadcast event - */ - public function getParameter() - { - return $this->_param; - } - - /** - * @param mixed parameter of the broadcast event - */ - public function setParameter($value) - { - $this->_param=$value; - } -} - -/** - * TCommandEventParameter class - * - * TCommandEventParameter encapsulates the parameter data for <b>Command</b> - * event of button controls. You can access the name of the command via - * {@link getCommandName CommandName} property, and the parameter carried - * with the command via {@link getCommandParameter CommandParameter} property. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TCommandEventParameter extends TEventParameter -{ - private $_name; - private $_param; - - /** - * Constructor. - * @param string name of the command - * @param string parameter of the command - */ - public function __construct($name='',$parameter='') - { - $this->_name=$name; - $this->_param=$parameter; - } - - /** - * @return string name of the command - */ - public function getCommandName() - { - return $this->_name; - } - - /** - * @return string parameter of the command - */ - public function getCommandParameter() - { - return $this->_param; - } -} - - -/** - * TCompositeLiteral class - * - * TCompositeLiteral is used internally by {@link TTemplate} for representing - * consecutive static strings, expressions and statements. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TCompositeLiteral extends TComponent implements IRenderable, IBindable -{ - const TYPE_EXPRESSION=0; - const TYPE_STATEMENTS=1; - const TYPE_DATABINDING=2; - private $_container=null; - private $_items=array(); - private $_expressions=array(); - private $_statements=array(); - private $_bindings=array(); - - /** - * Constructor. - * @param array list of items to be represented by TCompositeLiteral - */ - public function __construct($items) - { - $this->_items=array(); - $this->_expressions=array(); - $this->_statements=array(); - foreach($items as $id=>$item) - { - if(is_array($item)) - { - if($item[0]===self::TYPE_EXPRESSION) - $this->_expressions[$id]=$item[1]; - else if($item[0]===self::TYPE_STATEMENTS) - $this->_statements[$id]=$item[1]; - else if($item[0]===self::TYPE_DATABINDING) - $this->_bindings[$id]=$item[1]; - $this->_items[$id]=''; - } - else - $this->_items[$id]=$item; - } - } - - /** - * @return TComponent container of this component. It serves as the evaluation context of expressions and statements. - */ - public function getContainer() - { - return $this->_container; - } - - /** - * @param TComponent container of this component. It serves as the evaluation context of expressions and statements. - */ - public function setContainer(TComponent $value) - { - $this->_container=$value; - } - - /** - * Evaluates the expressions and/or statements in the component. - */ - public function evaluateDynamicContent() - { - $context=$this->_container===null?$this:$this->_container; - foreach($this->_expressions as $id=>$expression) - $this->_items[$id]=$context->evaluateExpression($expression); - foreach($this->_statements as $id=>$statement) - $this->_items[$id]=$context->evaluateStatements($statement); - } - - /** - * Performs databindings. - * This method is required by {@link IBindable} - */ - public function dataBind() - { - $context=$this->_container===null?$this:$this->_container; - foreach($this->_bindings as $id=>$binding) - $this->_items[$id]=$context->evaluateExpression($binding); - } - - /** - * Renders the content stored in this component. - * This method is required by {@link IRenderable} - * @param ITextWriter - */ - public function render($writer) - { - $writer->write(implode('',$this->_items)); - } -} - +}
\ No newline at end of file diff --git a/framework/Web/UI/TControlCollection.php b/framework/Web/UI/TControlCollection.php new file mode 100644 index 00000000..9fc3cfad --- /dev/null +++ b/framework/Web/UI/TControlCollection.php @@ -0,0 +1,95 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + + +/** + * TControlCollection class + * + * TControlCollection implements a collection that enables + * controls to maintain a list of their child controls. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +class TControlCollection extends TList +{ + /** + * the control that owns this collection. + * @var TControl + */ + private $_o; + + /** + * Constructor. + * @param TControl the control that owns this collection. + * @param boolean whether the list is read-only + */ + public function __construct(TControl $owner,$readOnly=false) + { + $this->_o=$owner; + parent::__construct(null,$readOnly); + } + + /** + * @return TControl the control that owns this collection. + */ + protected function getOwner() + { + return $this->_o; + } + + /** + * Inserts an item at the specified position. + * This overrides the parent implementation by performing additional + * operations for each newly added child control. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl. + */ + public function insertAt($index,$item) + { + 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'); + } + + /** + * Removes an item at the specified position. + * This overrides the parent implementation by performing additional + * cleanup work when removing a child control. + * @param integer the index of the item to be removed. + * @return mixed the removed item. + */ + public function removeAt($index) + { + $item=parent::removeAt($index); + if($item instanceof TControl) + $this->_o->removedControl($item); + return $item; + } + + /** + * Overrides the parent implementation by invoking {@link TControl::clearNamingContainer} + */ + public function clear() + { + parent::clear(); + if($this->_o instanceof INamingContainer) + $this->_o->clearNamingContainer(); + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TEmptyControlCollection.php b/framework/Web/UI/TEmptyControlCollection.php new file mode 100644 index 00000000..22a2fff6 --- /dev/null +++ b/framework/Web/UI/TEmptyControlCollection.php @@ -0,0 +1,44 @@ +<?php +/** + * TControl, TControlCollection, TEventParameter and INamingContainer class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + +/** + * TEmptyControlCollection class + * + * TEmptyControlCollection implements an empty control list that prohibits adding + * controls to it. This is useful for controls that do not allow child controls. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Web.UI + * @since 3.0 + */ +class TEmptyControlCollection extends TControlCollection +{ + /** + * Constructor. + * @param TControl the control that owns this collection. + */ + public function __construct(TControl $owner) + { + parent::__construct($owner,true); + } + + /** + * Inserts an item at the specified position. + * This overrides the parent implementation by ignoring new addition. + * @param integer the speicified position. + * @param mixed new item + */ + public function insertAt($index,$item) + { + if(!is_string($item)) // string is possible if property tag is used. we simply ignore it in this case + parent::insertAt($index,$item); // this will generate an exception in parent implementation + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 903711e4..2331d3fb 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -1297,105 +1297,4 @@ class TPage extends TTemplateControl } } -} - -/** - * IPageStatePersister interface. - * - * IPageStatePersister interface is required for all page state persister - * classes. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.1 - */ -interface IPageStatePersister -{ - /** - * @param TPage the page that this persister works for - */ - public function getPage(); - /** - * @param TPage the page that this persister works for - */ - public function setPage(TPage $page); - /** - * Saves state to persistent storage. - * @param mixed state to be stored - */ - public function save($state); - /** - * Loads page state from persistent storage - * @return mixed the restored state - */ - public function load(); -} - - -/** - * TPageStateFormatter class. - * - * TPageStateFormatter is a utility class to transform the page state - * into and from a string that can be properly saved in persistent storage. - * - * Depending on the {@link TPage::getEnableStateValidation() EnableStateValidation} - * and {@link TPage::getEnableStateEncryption() EnableStateEncryption}, - * TPageStateFormatter may do HMAC validation and encryption to prevent - * the state data from being tampered or viewed. - * The private keys and hashing/encryption methods are determined by - * {@link TApplication::getSecurityManager() SecurityManager}. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @version $Revision: $ $Date: $ - * @package System.Web.UI - * @since 3.1 - */ -class TPageStateFormatter -{ - /** - * @param TPage - * @param mixed state data - * @return string serialized data - */ - public static function serialize($page,$data) - { - $sm=$page->getApplication()->getSecurityManager(); - if($page->getEnableStateValidation()) - $str=$sm->hashData(serialize($data)); - else - $str=serialize($data); - if($page->getEnableStateCompression() && extension_loaded('zlib')) - $str=gzcompress($str); - if($page->getEnableStateEncryption()) - $str=$sm->encrypt($str); - return base64_encode($str); - } - - /** - * @param TPage - * @param string serialized data - * @return mixed unserialized state data, null if data is corrupted - */ - public static function unserialize($page,$data) - { - $str=base64_decode($data); - if($str==='') - return null; - if($str!==false) - { - $sm=$page->getApplication()->getSecurityManager(); - if($page->getEnableStateEncryption()) - $str=$sm->decrypt($str); - if($page->getEnableStateCompression() && extension_loaded('zlib')) - $str=@gzuncompress($str); - if($page->getEnableStateValidation()) - { - if(($str=$sm->validateData($str))!==false) - return unserialize($str); - } - else - return unserialize($str); - } - return null; - } -} +}
\ No newline at end of file diff --git a/framework/Web/UI/TPageStateFormatter.php b/framework/Web/UI/TPageStateFormatter.php new file mode 100644 index 00000000..77f3316d --- /dev/null +++ b/framework/Web/UI/TPageStateFormatter.php @@ -0,0 +1,79 @@ +<?php +/** + * TPage class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI + */ + + +/** + * TPageStateFormatter class. + * + * TPageStateFormatter is a utility class to transform the page state + * into and from a string that can be properly saved in persistent storage. + * + * Depending on the {@link TPage::getEnableStateValidation() EnableStateValidation} + * and {@link TPage::getEnableStateEncryption() EnableStateEncryption}, + * TPageStateFormatter may do HMAC validation and encryption to prevent + * the state data from being tampered or viewed. + * The private keys and hashing/encryption methods are determined by + * {@link TApplication::getSecurityManager() SecurityManager}. + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @version $Revision: $ $Date: $ + * @package System.Web.UI + * @since 3.1 + */ +class TPageStateFormatter +{ + /** + * @param TPage + * @param mixed state data + * @return string serialized data + */ + public static function serialize($page,$data) + { + $sm=$page->getApplication()->getSecurityManager(); + if($page->getEnableStateValidation()) + $str=$sm->hashData(serialize($data)); + else + $str=serialize($data); + if($page->getEnableStateCompression() && extension_loaded('zlib')) + $str=gzcompress($str); + if($page->getEnableStateEncryption()) + $str=$sm->encrypt($str); + return base64_encode($str); + } + + /** + * @param TPage + * @param string serialized data + * @return mixed unserialized state data, null if data is corrupted + */ + public static function unserialize($page,$data) + { + $str=base64_decode($data); + if($str==='') + return null; + if($str!==false) + { + $sm=$page->getApplication()->getSecurityManager(); + if($page->getEnableStateEncryption()) + $str=$sm->decrypt($str); + if($page->getEnableStateCompression() && extension_loaded('zlib')) + $str=@gzuncompress($str); + if($page->getEnableStateValidation()) + { + if(($str=$sm->validateData($str))!==false) + return unserialize($str); + } + else + return unserialize($str); + } + return null; + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplate.php index 0ffb6bec..c90fab82 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplate.php @@ -10,127 +10,6 @@ */ /** - * Includes TOutputCache class file - */ -Prado::using('System.Web.UI.WebControls.TOutputCache'); - -/** - * TTemplateManager class - * - * TTemplateManager manages the loading and parsing of control templates. - * - * There are two ways of loading a template, either by the associated template - * control class name, or the template file name. - * The former is via calling {@link getTemplateByClassName}, which tries to - * locate the corresponding template file under the directory containing - * the class file. The name of the template file is the class name with - * the extension '.tpl'. To load a template from a template file path, - * call {@link getTemplateByFileName}. - * - * By default, TTemplateManager is registered with {@link TPageService} as the - * template manager module that can be accessed via {@link TPageService::getTemplateManager()}. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TTemplateManager extends TModule -{ - /** - * Template file extension - */ - const TEMPLATE_FILE_EXT='.tpl'; - /** - * Prefix of the cache variable name for storing parsed templates - */ - const TEMPLATE_CACHE_PREFIX='prado:template:'; - - /** - * Initializes the module. - * This method is required by IModule and is invoked by application. - * It starts output buffer if it is enabled. - * @param TXmlElement module configuration - */ - public function init($config) - { - $this->getService()->setTemplateManager($this); - } - - /** - * Loads the template corresponding to the specified class name. - * @return ITemplate template for the class name, null if template doesn't exist. - */ - public function getTemplateByClassName($className) - { - $class=new ReflectionClass($className); - $tplFile=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$className.self::TEMPLATE_FILE_EXT; - return $this->getTemplateByFileName($tplFile); - } - - /** - * Loads the template from the specified file. - * @return ITemplate template parsed from the specified file, null if the file doesn't exist. - */ - public function getTemplateByFileName($fileName) - { - if(($fileName=$this->getLocalizedTemplate($fileName))!==null) - { - Prado::trace("Loading template $fileName",'System.Web.UI.TTemplateManager'); - if(($cache=$this->getApplication()->getCache())===null) - return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName); - else - { - $array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName); - if(is_array($array)) - { - list($template,$timestamps)=$array; - if($this->getApplication()->getMode()===TApplicationMode::Performance) - return $template; - $cacheValid=true; - foreach($timestamps as $tplFile=>$timestamp) - { - if(!is_file($tplFile) || filemtime($tplFile)>$timestamp) - { - $cacheValid=false; - break; - } - } - if($cacheValid) - return $template; - } - $template=new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName); - $includedFiles=$template->getIncludedFiles(); - $timestamps=array(); - $timestamps[$fileName]=filemtime($fileName); - foreach($includedFiles as $includedFile) - $timestamps[$includedFile]=filemtime($includedFile); - $cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,$timestamps)); - return $template; - } - } - else - return null; - } - - /** - * Finds a localized template file. - * @param string template file. - * @return string|null a localized template file if found, null otherwise. - */ - protected function getLocalizedTemplate($filename) - { - if(($app=$this->getApplication()->getGlobalization(false))===null) - return is_file($filename)?$filename:null; - foreach($app->getLocalizedResource($filename) as $file) - { - if(($file=realpath($file))!==false && is_file($file)) - return $file; - } - return null; - } -} - -/** * TTemplate implements PRADO template parsing logic. * A TTemplate object represents a parsed PRADO control template. * It can instantiate the template as child controls of a specified control. @@ -1068,5 +947,4 @@ class TTemplate extends TApplicationComponent implements ITemplate return $input; } -} - +}
\ No newline at end of file diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TTheme.php index f8c86bb7..72c87da1 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TTheme.php @@ -9,179 +9,6 @@ * @package System.Web.UI */ -Prado::using('System.Web.Services.TPageService'); - -/** - * TThemeManager class - * - * TThemeManager manages the themes used in a Prado application. - * - * Themes are stored under the directory specified by the - * {@link setBasePath BasePath} property. The themes can be accessed - * via URL {@link setBaseUrl BaseUrl}. Each theme is represented by a subdirectory - * and all the files under that directory. The name of a theme is the name - * of the corresponding subdirectory. - * By default, the base path of all themes is a directory named "themes" - * under the directory containing the application entry script. - * To get a theme (normally you do not need to), call {@link getTheme}. - * - * TThemeManager may be configured within page service tag in application - * configuration file as follows, - * <module id="themes" class="System.Web.UI.TThemeManager" - * BasePath="Application.themes" BaseUrl="/themes" /> - * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl} - * and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse. - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Web.UI - * @since 3.0 - */ -class TThemeManager extends TModule -{ - /** - * default themes base path - */ - const DEFAULT_BASEPATH='themes'; - - /** - * default theme class - */ - const DEFAULT_THEMECLASS = 'TTheme'; - - /** - * @var string - */ - private $_themeClass=self::DEFAULT_THEMECLASS; - - /** - * @var boolean whether this module has been initialized - */ - private $_initialized=false; - /** - * @var string the directory containing all themes - */ - private $_basePath=null; - /** - * @var string the base URL for all themes - */ - private $_baseUrl=null; - - /** - * Initializes the module. - * This method is required by IModule and is invoked by application. - * @param TXmlElement module configuration - */ - public function init($config) - { - $this->_initialized=true; - $service=$this->getService(); - if($service instanceof TPageService) - $service->setThemeManager($this); - else - throw new TConfigurationException('thememanager_service_unavailable'); - } - - /** - * @param string name of the theme to be retrieved - * @return TTheme the theme retrieved - */ - public function getTheme($name) - { - $themePath=$this->getBasePath().DIRECTORY_SEPARATOR.$name; - $themeUrl=rtrim($this->getBaseUrl(),'/').'/'.$name; - return Prado::createComponent($this->getThemeClass(), $themePath, $themeUrl); - } - - /** - * @param string|null $class Theme class name in namespace format - */ - public function setThemeClass($class) { - $this->_themeClass = $class===null ? self::DEFAULT_THEMECLASS : (string)$class; - } - - /** - * @return string Theme class name in namespace format. Defaults to {@link TThemeManager::DEFAULT_THEMECLASS DEFAULT_THEMECLASS}. - */ - public function getThemeClass() { - return $this->_themeClass; - } - - /** - * @return array list of available theme names - */ - public function getAvailableThemes() - { - $themes=array(); - $basePath=$this->getBasePath(); - $folder=@opendir($basePath); - while($file=@readdir($folder)) - { - if($file!=='.' && $file!=='..' && $file!=='.svn' && is_dir($basePath.DIRECTORY_SEPARATOR.$file)) - $themes[]=$file; - } - closedir($folder); - return $themes; - } - - /** - * @return string the base path for all themes. It is returned as an absolute path. - * @throws TConfigurationException if base path is not set and "themes" directory does not exist. - */ - public function getBasePath() - { - if($this->_basePath===null) - { - $this->_basePath=dirname($this->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; - if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath)) - throw new TConfigurationException('thememanager_basepath_invalid2',$this->_basePath); - $this->_basePath=$basePath; - } - return $this->_basePath; - } - - /** - * @param string the base path for all themes. It must be in the format of a namespace. - * @throws TInvalidDataValueException if the base path is not a proper namespace. - */ - public function setBasePath($value) - { - if($this->_initialized) - throw new TInvalidOperationException('thememanager_basepath_unchangeable'); - else - { - $this->_basePath=Prado::getPathOfNamespace($value); - if($this->_basePath===null || !is_dir($this->_basePath)) - throw new TInvalidDataValueException('thememanager_basepath_invalid',$value); - } - } - - /** - * @return string the base URL for all themes. - * @throws TConfigurationException If base URL is not set and a correct one cannot be determined by Prado. - */ - public function getBaseUrl() - { - if($this->_baseUrl===null) - { - $appPath=dirname($this->getRequest()->getApplicationFilePath()); - $basePath=$this->getBasePath(); - if(strpos($basePath,$appPath)===false) - throw new TConfigurationException('thememanager_baseurl_required'); - $appUrl=rtrim(dirname($this->getRequest()->getApplicationUrl()),'/\\'); - $this->_baseUrl=$appUrl.strtr(substr($basePath,strlen($appPath)),'\\','/'); - } - return $this->_baseUrl; - } - - /** - * @param string the base URL for all themes. - */ - public function setBaseUrl($value) - { - $this->_baseUrl=rtrim($value,'/'); - } -} - /** * TTheme class * @@ -509,5 +336,4 @@ class TTheme extends TApplicationComponent implements ITheme { $this->_jsFiles=$value; } -} - +}
\ No newline at end of file |