summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjavalizard <>2010-04-18 01:36:04 +0000
committerjavalizard <>2010-04-18 01:36:04 +0000
commita77f444bbc8059c0bededc47a50f8fd9c05a1549 (patch)
tree5ce41a7988c75fdaedf7da97ef20945d0ea86785
parent98c48b76b2fdf4b99c9fad1631e52d027b965be4 (diff)
TComponent- adds a blank __construct function to unify the constructor call path for all objects.
TApplication- Adds final attribute to the parameters in the config so folder config.xml cannot override if set to true. Adds a mergeParameter function to unify parameter setting. Fixed a bug where loadParametersPhp wasn't getting the properties correctly. TControl- calls the parent::__construct, Adds render blocking. (the PRADO class using this will be added in a week or two) TParameterModule- Adds final attribute to the parameter option so folder configs cannot override if set to true. Uses the application mergeParameter function. Adds final to the php parameter loader
-rw-r--r--framework/TApplication.php93
-rw-r--r--framework/TComponent.php13
-rw-r--r--framework/Util/TParameterModule.php58
-rw-r--r--framework/Web/UI/TControl.php73
4 files changed, 180 insertions, 57 deletions
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 2eba65fb..0a028141 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -219,6 +219,10 @@ class TApplication extends TComponent
*/
private $_parameters;
/**
+ * @var TMap list of final application parameters
+ */
+ private $_parametersfinal;
+ /**
* @var string configuration file
*/
private $_configFile;
@@ -320,6 +324,7 @@ class TApplication extends TComponent
* will be looked for. If found, the file is considered as the application
* configuration file.
* @param boolean whether to cache application configuration. Defaults to true.
+ * @param string The type of configuration te app should have. Defaults to {@link CONFIG_TYPE_XML}.
* @throws TConfigurationException if configuration file cannot be read or the runtime path is invalid.
*/
public function __construct($basePath='protected',$cacheConfig=true, $configType=self::CONFIG_TYPE_XML)
@@ -335,9 +340,12 @@ class TApplication extends TComponent
// generates unique ID by hashing the runtime path
$this->_uniqueID=md5($this->_runtimePath);
$this->_parameters=new TMap;
+ $this->_parametersfinal=new TMap;
$this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null));
Prado::setPathOfAlias('Application',$this->_basePath);
+
+ parent::__construct();
}
/**
@@ -982,20 +990,8 @@ class TApplication extends TComponent
if(empty($this->_services))
$this->_services=array($this->getPageServiceID()=>array('TPageService',array(),null));
-
- // load parameters
- foreach($config->getParameters() as $id=>$parameter)
- {
- if(is_array($parameter))
- {
- $component=Prado::createComponent($parameter[0]);
- foreach($parameter[1] as $name=>$value)
- $component->setSubProperty($name,$value);
- $this->_parameters->add($id,$component);
- }
- else
- $this->_parameters->add($id,$parameter);
- }
+
+ $this->mergeParameters($config->getParameters());
// load and init modules specified in app config
$modules=array();
@@ -1036,6 +1032,47 @@ class TApplication extends TComponent
}
}
}
+
+ /**
+ * This will merge the parameters into the application
+ * The parameter looks like this:
+ * <code>
+ * $params = array(
+ * // type = 0 is a class
+ * 'paramname1' => array('type'=>0, 'class' => $type, 'properties' => $properties->toArray(),
+ * 'final' => $final, 'value' => $element),
+ * // type != 0 is a parameter with a value
+ * 'paramname1' => array('type'=>1, 'value' => $element, 'final' => $final),
+ * 'paramname2' => array('type'=>2, 'value' => $value, 'final' => $final)
+ * );
+ * </code>
+ * @param array $parameters the parameters to merge into application
+ */
+ public function mergeParameters($parameters) {
+ // load parameters
+ foreach($parameters as $id=>$parameter)
+ {
+ if(isset($this->_parametersfinal[$id]))
+ continue;
+
+ if(!$parameter['type'])
+ {
+ $component=Prado::createComponent($parameter['class']);
+ foreach($parameter['properties'] as $name=>$value)
+ $component->setSubProperty($name,$value);
+ if($component instanceof IModule && isset($parameter['value']))
+ $component->init($parameter['value']);
+ $this->_parameters->add($id,$component);
+ }
+ else
+ $this->_parameters->add($id,$parameter['value']);
+
+ // If this parameter is final, and not set yet, set it
+ if($parameter['final'] && !isset($this->_parametersfinal[$id]))
+ $this->_parametersfinal->add($id, $parameter['value']);
+ }
+ }
+
/**
* Loads configuration and initializes application.
@@ -1061,7 +1098,7 @@ class TApplication extends TComponent
}
else
$config=Prado::unserialize(file_get_contents($this->_cacheFile));
-
+
$this->applyConfiguration($config,false);
}
@@ -1627,13 +1664,20 @@ class TApplicationConfiguration extends TComponent
{
if(is_array($parameter))
{
+ $final = TPropertyValue::ensureBoolean($parameter['final']);
+ unset($parameter['final']);
if(isset($parameter['class']))
{
- $type = $parameter['class'];
- unset($parameter['class']);
- $properties = isset($service['properties']) ? $service['properties'] : array();
+ $properties = isset($parameter['properties']) ? $parameter['properties'] : array();
$properties['id'] = $id;
- $this->_parameters[$id] = array($type,$properties);
+ $this->_parameters[$id] = array('type'=>0, 'class' => $parameter['class'], 'properties' => $properties,
+ 'final' => $final, 'value' => $parameter);
+ } else {
+ if(!isset($parameter['value'])) {
+ $this->_parameters[$id]=array('type'=>1, 'value' => $parameter, 'final' => $final);
+ } else {
+ $this->_parameters[$id]=array('type'=>2, 'value' => $value, 'final' => $final);
+ }
}
}
else
@@ -1657,15 +1701,18 @@ class TApplicationConfiguration extends TComponent
$properties=$element->getAttributes();
if(($id=$properties->remove('id'))===null)
throw new TConfigurationException('appconfig_parameterid_required');
+ $final = TPropertyValue::ensureBoolean($properties->remove('final'));
if(($type=$properties->remove('class'))===null)
{
if(($value=$properties->remove('value'))===null)
- $this->_parameters[$id]=$element;
+ $this->_parameters[$id]=array('type'=>1, 'value' => $element, 'final' => $final);
else
- $this->_parameters[$id]=$value;
+ $this->_parameters[$id]=array('type'=>2, 'value' => $value, 'final' => $final);
+ }
+ else {
+ $this->_parameters[$id]=array('type'=>0, 'class' => $type, 'properties' => $properties->toArray(),
+ 'final' => $final, 'value' => $element);
}
- else
- $this->_parameters[$id]=array($type,$properties->toArray());
$this->_empty=false;
}
else
diff --git a/framework/TComponent.php b/framework/TComponent.php
index 55c19ecf..9b5331ef 100644
--- a/framework/TComponent.php
+++ b/framework/TComponent.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2010 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System
@@ -49,11 +49,12 @@
* To raise an event (assuming named as 'Click') of a component, use
* <code>
* $component->raiseEvent('OnClick');
+ * $component->raiseEvent('OnClick', $this, $param);
* </code>
* To attach an event handler to an event, use one of the following ways,
* <code>
* $component->OnClick=$callback; // or $component->OnClick->add($callback);
- * $$component->attachEventHandler('OnClick',$callback);
+ * $component->attachEventHandler('OnClick',$callback);
* </code>
* The first two ways make use of the fact that $component->OnClick refers to
* the event handler list {@link TList} for the 'OnClick' event.
@@ -83,6 +84,14 @@ class TComponent
*/
private $_m=array();
+
+ /**
+ * The Common __construct
+ */
+ public function __construct() {
+ }
+
+
/**
* Returns a property value or an event handler list by property or event name.
* Do not call this method. This is a PHP magic method that we override
diff --git a/framework/Util/TParameterModule.php b/framework/Util/TParameterModule.php
index 0109ca32..265bdd38 100644
--- a/framework/Util/TParameterModule.php
+++ b/framework/Util/TParameterModule.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2010 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Util
@@ -24,6 +24,7 @@
* <parameters>
* <parameter id="param1" value="paramValue1" />
* <parameter id="param2" Property1="Value1" Property2="Value2" ... />
+ * <parameter id="param3" value="cannot be changed" final="true" />
* </parameters>
* </code>
*
@@ -33,12 +34,19 @@
* <module class="System.Util.TParameterModule">
* <parameter id="param1" value="paramValue1" />
* <parameter id="param2" Property1="Value1" Property2="Value2" ... />
+ * <parameter id="param3" value="cannot be changed" final="true" />
* </module>
* </code>
*
+ * Setting the final attribute to true will cause that parameter to be unchangable
+ * by any future mergeParameters.
+ *
* If a parameter is defined both in the external file and within the module
* tag, the former takes precedence.
*
+ * the application parameters are processed first before the modules parameters
+ * are processed.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Carl G. Mathisen <carlgmathisen@gmail.com>
* @version $Id$
@@ -93,7 +101,7 @@ class TParameterModule extends TModule
/**
* Loads parameters into application.
- * @param mixed XML of PHP representation of the parameters
+ * @param mixed XML or PHP representation of the parameters
* @throws TConfigurationException if the parameter file format is invalid
*/
protected function loadParameters($config)
@@ -103,10 +111,23 @@ class TParameterModule extends TModule
{
foreach($config as $id => $parameter)
{
- if(is_array($parameter) && isset($parameter['class']))
+ if(is_array($parameter))
{
- $properties = isset($parameter['properties'])?$parameter['properties']:array();
- $parameters[$id]=array($parameter['class'],$properties);
+ $final = TPropertyValue::ensureBoolean($parameter['final']);
+ unset($parameter['final']);
+ if(isset($parameter['class']))
+ {
+ $properties = isset($parameter['properties']) ? $parameter['properties'] : array();
+ $properties['id'] = $id;
+ $parameters[$id] = array('type'=>0, 'class' => $parameter['class'], 'properties' => $properties,
+ 'final' => $final, 'value' => $parameter);
+ } else {
+ if(!isset($parameter['value'])) {
+ $parameters[$id]=array('type'=>1, 'value' => $parameter, 'final' => $final);
+ } else {
+ $parameters[$id]=array('type'=>2, 'value' => $value, 'final' => $final);
+ }
+ }
}
else
{
@@ -121,31 +142,22 @@ class TParameterModule extends TModule
$properties=$node->getAttributes();
if(($id=$properties->remove('id'))===null)
throw new TConfigurationException('parametermodule_parameterid_required');
+ $final = TPropertyValue::ensureBoolean($properties->remove('final'));
if(($type=$properties->remove('class'))===null)
{
if(($value=$properties->remove('value'))===null)
- $parameters[$id]=$node;
+ $parameters[$id]=array('type'=>1, 'value' => $node, 'final' => $final);
else
- $parameters[$id]=$value;
+ $parameters[$id]=array('type'=>2, 'value' => $value, 'final' => $final);
+ }
+ else {
+ $parameters[$id]=array('type'=>0, 'class' => $type, 'properties' => $properties->toArray(),
+ 'final' => $final, 'value' => $node);
}
- else
- $parameters[$id]=array($type,$properties->toArray());
- }
- }
-
- $appParams=$this->getApplication()->getParameters();
- foreach($parameters as $id=>$parameter)
- {
- if(is_array($parameter))
- {
- $component=Prado::createComponent($parameter[0]);
- foreach($parameter[1] as $name=>$value)
- $component->setSubProperty($name,$value);
- $appParams->add($id,$component);
}
- else
- $appParams->add($id,$parameter);
}
+
+ $this->getApplication()->mergeParameters($parameters);
}
/**
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 1c03a04d..79a691ec 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2010 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.UI
@@ -172,12 +172,17 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
* @var array a collection of rare control data
*/
private $_rf=array();
+ /**
+ * @var number this is how many times the control was told not to render
+ */
+ private $_renderblockcount=0;
/**
* Constructor.
*/
public function __construct()
{
+ parent::__construct();
}
/**
@@ -237,6 +242,21 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
}
/**
+ * @return TControl the parent of this control of type
+ */
+ public function getParentOfType($type,$strict=false)
+ {
+ $control = $this->Parent;
+ do {
+ if(is_object($control) && (get_class($control)===$type || (!$strict && ($control instanceof $type))))
+ return $control;
+ $control = $control->Parent;
+ } while($control);
+
+ return null;
+ }
+
+ /**
* @return TControl the naming container of this control
*/
public function getNamingContainer()
@@ -297,6 +317,32 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
}
/**
+ * This adds a block to the rendering of the control
+ */
+ public function addRenderBlock()
+ {
+ ++$this->_renderblockcount;
+ }
+
+ /**
+ * @return boolean true if the rendering is currently blocked
+ */
+ public function getIsRenderBlocked()
+ {
+ return $this->_renderblockcount > 0;
+ }
+
+ /**
+ * removes a block. This also has an interesting effect of forcing the render if called in the reverse
+ * of the typical order. eg. removeRenderBlock(); ...... addRenderBlock();
+ */
+ public function removeRenderBlock()
+ {
+ --$this->_renderblockcount;
+ }
+
+
+ /**
* @return TTemplateControl the control whose template is loaded from
* some external storage, such as file, db, and whose template ultimately
* contains this control.
@@ -445,6 +491,13 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
}
/**
+ * @return boolean whether the skin has been applied or is past the phase of skin application
+ */
+ public function getIsSkinApplied() {
+ return ($this->_flags & self::IS_SKIN_APPLIED) || $this->_stage>self::CS_CHILD_INITIALIZED;
+ }
+
+ /**
* @return boolean whether theming is enabled for this control.
* The theming is enabled if the control and all its parents have it enabled.
*/
@@ -1564,6 +1617,8 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
{
if($this->getHasControls())
{
+ if($this->IsRenderBlocked) return;
+
foreach($this->_rf[self::RF_CONTROLS] as $control)
{
if(is_string($control))
@@ -1997,14 +2052,14 @@ 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);
+ /**
+ * @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);
}
/**