summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2006-02-17 04:28:06 +0000
committerxue <>2006-02-17 04:28:06 +0000
commitae1c1995b2fec431afe7cca23b2697e1bef17baf (patch)
tree43fb70539492615022e434435a70e35241a898f2 /framework/Web
parent31807816360c93080a6a0da55b858d708cd85c8b (diff)
moved shortcut methods from TComponent to TControl.
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Services/TPageService.php6
-rw-r--r--framework/Web/THttpRequest.php19
-rw-r--r--framework/Web/THttpResponse.php9
-rw-r--r--framework/Web/THttpSession.php8
-rw-r--r--framework/Web/UI/TClientScriptManager.php4
-rw-r--r--framework/Web/UI/TControl.php83
-rw-r--r--framework/Web/UI/TPageStatePersister.php13
-rw-r--r--framework/Web/UI/TTemplateManager.php12
-rw-r--r--framework/Web/UI/TThemeManager.php12
9 files changed, 138 insertions, 28 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index bb80b902..013bb35f 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -202,7 +202,7 @@ class TPageService extends TService
*/
protected function determineRequestedPagePath()
{
- $pagePath=$this->getRequest()->getServiceParameter();
+ $pagePath=$this->getApplication()->getRequest()->getServiceParameter();
if(empty($pagePath))
$pagePath=$this->getDefaultPage();
return $pagePath;
@@ -441,7 +441,7 @@ class TPageService extends TService
else
throw new THttpException(404,'pageservice_page_unknown',$this->getRequestedPagePath());
- $this->_page->run($this->getResponse()->createHtmlWriter());
+ $this->_page->run($this->getApplication()->getResponse()->createHtmlWriter());
}
/**
@@ -453,7 +453,7 @@ class TPageService extends TService
*/
public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=false)
{
- return $this->getRequest()->constructUrl($this->_id,$pagePath,$getParams,$encodeAmpersand);
+ return $this->getApplication()->getRequest()->constructUrl($this->_id,$pagePath,$getParams,$encodeAmpersand);
}
}
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index a0fa50e4..201addd1 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -533,6 +533,22 @@ class THttpRequest extends TMap implements IModule
{
$this->_serviceParam=$value;
}
+
+ /**
+ * @return THttpResponse response module
+ */
+ public function getResponse()
+ {
+ return Prado::getApplication()->getResponse();
+ }
+
+ /**
+ * @return TApplication application instance
+ */
+ public function getApplication()
+ {
+ return Prado::getApplication();
+ }
}
/**
@@ -558,7 +574,6 @@ class THttpCookieCollection extends TList
*/
public function __construct($owner=null)
{
- parent::__construct();
$this->_o=$owner;
}
@@ -643,7 +658,6 @@ class THttpCookie extends TComponent
*/
public function __construct($name,$value)
{
- parent::__construct();
$this->_name=$name;
$this->_value=$value;
}
@@ -825,7 +839,6 @@ class TUri extends TComponent
*/
public function __construct($uri)
{
- parent::__construct();
if(($ret=@parse_url($uri))!==false)
{
// decoding???
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index 1607b9d5..3da9a5d5 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -79,7 +79,6 @@ class THttpResponse extends TModule implements ITextWriter
{
if($this->_bufferOutput)
@ob_end_flush();
- parent::__destruct();
}
/**
@@ -396,6 +395,14 @@ class THttpResponse extends TModule implements ITextWriter
$type=$this->_htmlWriterType;
return Prado::createComponent($type,$this);
}
+
+ /**
+ * @return THttpRequest request module
+ */
+ public function getRequest()
+ {
+ return $this->getApplication()->getRequest();
+ }
}
?> \ No newline at end of file
diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php
index 8d35b008..605b858a 100644
--- a/framework/Web/THttpSession.php
+++ b/framework/Web/THttpSession.php
@@ -606,6 +606,14 @@ class THttpSession extends TComponent implements IteratorAggregate,ArrayAccess,I
{
unset($_SESSION[$offset]);
}
+
+ /**
+ * @return TApplication application instance
+ */
+ public function getApplication()
+ {
+ return Prado::getApplication();
+ }
}
/**
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 1ea4175d..fd5a6eec 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -140,7 +140,7 @@ class TClientScriptManager extends TComponent
$base = Prado::getFrameworkPath();
$clientScripts = self::SCRIPT_DIR;
$file = "{$base}/{$clientScripts}/{$lib}.js";
- $this->publishFilePath($file);
+ Prado::getApplication()->getAssetManager()->publishFilePath($file);
$this->_publishedScriptFiles[$lib] = true;
}
}
@@ -159,7 +159,7 @@ class TClientScriptManager extends TComponent
$base = Prado::getFrameworkPath();
$clientScripts = self::SCRIPT_DIR;
$file = "{$base}/{$clientScripts}/{$scriptFile}";
- $url= $this->publishFilePath($file);
+ $url= Prado::getApplication()->getAssetManager()->publishFilePath($file);
$this->_publishedScriptFiles[$scriptFile] = $url;
return $url;
}
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 4f905a1a..ded7049b 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -165,6 +165,13 @@ class TControl extends TComponent
private $_rf=array();
/**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ }
+
+ /**
* Returns a property value by name or a control by ID.
* This overrides the parent implementation by allowing accessing
* a control via its ID using the following syntax,
@@ -1549,6 +1556,80 @@ class TControl extends TComponent
}
}
}
+
+
+ /**
+ * @return TApplication current application instance
+ */
+ public function getApplication()
+ {
+ return Prado::getApplication();
+ }
+
+ /**
+ * @return IService the current service
+ */
+ public function getService()
+ {
+ return Prado::getApplication()->getService();
+ }
+
+ /**
+ * @return THttpRequest the current user request
+ */
+ public function getRequest()
+ {
+ return Prado::getApplication()->getRequest();
+ }
+
+ /**
+ * @return THttpResponse the response
+ */
+ public function getResponse()
+ {
+ return Prado::getApplication()->getResponse();
+ }
+
+ /**
+ * @return THttpSession user session
+ */
+ public function getSession()
+ {
+ return Prado::getApplication()->getSession();
+ }
+
+ /**
+ * @return IUser user
+ */
+ public function getUser()
+ {
+ return Prado::getApplication()->getUser();
+ }
+
+ /**
+ * Publishes a private asset and gets its URL.
+ * This method will publish a private asset (file or directory)
+ * and gets the URL to the asset. Note, if the asset refers to
+ * a directory, all contents under that directory will be published.
+ * @param string path of the asset that is relative to the directory containing the control class file.
+ * @return string URL to the asset path.
+ */
+ public function publishAsset($assetPath)
+ {
+ $class=new ReflectionClass(get_class($this));
+ $fullPath=dirname($class->getFileName()).'/'.$assetPath;
+ return $this->publishFilePath($fullPath);
+ }
+
+ /**
+ * Publishes a file or directory and returns its URL.
+ * @param string absolute path of the file or directory to be published
+ * @return string URL to the published file or directory
+ */
+ public function publishFilePath($fullPath)
+ {
+ return $this->getApplication()->getAssetManager()->publishFilePath($fullPath);
+ }
}
@@ -1577,7 +1658,6 @@ class TControlList extends TList
*/
public function __construct(TControl $owner)
{
- parent::__construct();
$this->_o=$owner;
}
@@ -1661,7 +1741,6 @@ class TEmptyControlList extends TList
*/
public function __construct(TControl $owner)
{
- parent::__construct();
$this->_o=$owner;
}
diff --git a/framework/Web/UI/TPageStatePersister.php b/framework/Web/UI/TPageStatePersister.php
index 49321ff5..90af9665 100644
--- a/framework/Web/UI/TPageStatePersister.php
+++ b/framework/Web/UI/TPageStatePersister.php
@@ -55,12 +55,13 @@ class TPageStatePersister extends TComponent implements IPageStatePersister
public function save($state)
{
Prado::trace("Saving state",'System.Web.UI.TPageStatePersister');
+ $sm=Prado::getApplication()->getSecurityManager();
if($this->_page->getEnableStateValidation())
- $data=$this->getApplication()->getSecurityManager()->hashData(Prado::serialize($state));
+ $data=$sm->hashData(Prado::serialize($state));
else
$data=Prado::serialize($state);
if($this->_page->getEnableStateEncryption())
- $data=$this->getApplication()->getSecurityManager()->encrypt($data);
+ $data=$sm->encrypt($data);
if(extension_loaded('zlib'))
$data=gzcompress($data);
$this->_page->getClientScript()->registerHiddenField(TPage::FIELD_PAGESTATE,base64_encode($data));
@@ -74,7 +75,9 @@ class TPageStatePersister extends TComponent implements IPageStatePersister
public function load()
{
Prado::trace("Loading state",'System.Web.UI.TPageStatePersister');
- $str=base64_decode($this->getRequest()->itemAt(TPage::FIELD_PAGESTATE));
+ $application=Prado::getApplication();
+ $sm=$application->getSecurityManager();
+ $str=base64_decode($application->getRequest()->itemAt(TPage::FIELD_PAGESTATE));
if($str==='')
return null;
if(extension_loaded('zlib'))
@@ -84,10 +87,10 @@ class TPageStatePersister extends TComponent implements IPageStatePersister
if($data!==false)
{
if($this->_page->getEnableStateEncryption())
- $data=$this->getApplication()->getSecurityManager()->decrypt($data);
+ $data=$sm->decrypt($data);
if($this->_page->getEnableStateValidation())
{
- if(($data=$this->getApplication()->getSecurityManager()->validateData($data))!==false)
+ if(($data=$sm->validateData($data))!==false)
return Prado::unserialize($data);
}
else
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index 67bda1b2..e87a23eb 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -50,7 +50,7 @@ class TTemplateManager extends TModule
*/
public function init($config)
{
- $this->getService()->setTemplateManager($this);
+ $this->getApplication()->getPageService()->setTemplateManager($this);
}
/**
@@ -259,7 +259,7 @@ class TTemplate extends TComponent implements ITemplate
public function instantiateIn($tplControl)
{
if(($page=$tplControl->getPage())===null)
- $page=$this->getService()->getRequestedPage();
+ $page=Prado::getApplication()->getPageService()->getRequestedPage();
$controls=array();
foreach($this->_tpl as $key=>$object)
{
@@ -371,11 +371,11 @@ class TTemplate extends TComponent implements ITemplate
$component->$setter($value[1]);
break;
case self::CONFIG_ASSET: // asset URL
- $url=$this->publishFilePath($this->_contextPath.'/'.$value[1]);
+ $url=Prado::getApplication()->getAssetManager()->publishFilePath($this->_contextPath.'/'.$value[1]);
$component->$setter($url);
break;
case self::CONFIG_PARAMETER: // application parameter
- $component->$setter($this->getApplication()->getParameters()->itemAt($value[1]));
+ $component->$setter(Prado::getApplication()->getParameters()->itemAt($value[1]));
break;
case self::CONFIG_LOCALIZATION:
Prado::using('System.I18N.Translation');
@@ -411,11 +411,11 @@ class TTemplate extends TComponent implements ITemplate
$component->setSubProperty($name,$value[1]);
break;
case self::CONFIG_ASSET: // asset URL
- $url=$this->publishFilePath($this->_contextPath.'/'.$value[1]);
+ $url=Prado::getApplication()->getAssetManager()->publishFilePath($this->_contextPath.'/'.$value[1]);
$component->setSubProperty($name,$url);
break;
case self::CONFIG_PARAMETER: // application parameter
- $component->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($value[1]));
+ $component->setSubProperty($name,Prado::getApplication()->getParameters()->itemAt($value[1]));
break;
case self::CONFIG_LOCALIZATION:
$component->setSubProperty($name,localize($value[1]));
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index 37e477d9..9110db7f 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -63,7 +63,7 @@ class TThemeManager extends TModule
public function init($config)
{
$this->_initialized=true;
- $this->getService()->setThemeManager($this);
+ $this->getApplication()->getPageService()->setThemeManager($this);
}
/**
@@ -86,7 +86,7 @@ class TThemeManager extends TModule
{
if($this->_basePath===null)
{
- $this->_basePath=dirname($this->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_BASEPATH;
+ $this->_basePath=dirname($this->getApplication()->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_BASEPATH;
if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath))
throw new TConfigurationException('thememanager_basepath_invalid',$this->_basePath);
$this->_basePath=$basePath;
@@ -119,11 +119,11 @@ class TThemeManager extends TModule
{
if($this->_baseUrl===null)
{
- $appPath=dirname($this->getRequest()->getPhysicalApplicationPath());
+ $appPath=dirname($this->getApplication()->getRequest()->getPhysicalApplicationPath());
$basePath=$this->getBasePath();
if(strpos($basePath,$appPath)===false)
throw new TConfigurationException('thememanager_baseurl_required');
- $appUrl=rtrim(dirname($this->getRequest()->getApplicationPath()),'/\\');
+ $appUrl=rtrim(dirname($this->getApplication()->getRequest()->getApplicationPath()),'/\\');
$this->_baseUrl=$appUrl.strtr(substr($basePath,strlen($appPath)),'\\','/');
}
return $this->_baseUrl;
@@ -209,14 +209,14 @@ class TTheme extends TComponent implements ITheme
{
$this->_themeUrl=$themeUrl;
$this->_name=basename($themePath);
- if(($cache=$this->getApplication()->getCache())!==null)
+ if(($cache=Prado::getApplication()->getCache())!==null)
{
$array=$cache->get(self::THEME_CACHE_PREFIX.$themePath);
if(is_array($array))
{
list($skins,$cssFiles,$jsFiles,$timestamp)=$array;
$cacheValid=true;
- if($this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE)
+ if(Prado::getApplication()->getMode()!==TApplication::STATE_PERFORMANCE)
{
if(($dir=opendir($themePath))===false)
throw new TIOException('theme_path_inexistent',$themePath);