summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2005-12-28 20:17:54 +0000
committerxue <>2005-12-28 20:17:54 +0000
commite8b60312037e54c34a06d6f57d7c21946cf3cd1f (patch)
treea6f35f5d4bb921998ca306602a33fc03ba47c4b5 /framework/Web
parent930c51a6d618d487105cd46c517f36c3b1fe3b44 (diff)
Modified the way to access application singleton.
IService and IModule interfaces are also adjusted accordingly.
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Services/TPageService.php29
-rw-r--r--framework/Web/THttpRequest.php7
-rw-r--r--framework/Web/THttpResponse.php7
-rw-r--r--framework/Web/THttpSession.php8
-rw-r--r--framework/Web/UI/TAssetManager.php11
-rw-r--r--framework/Web/UI/TControl.php48
-rw-r--r--framework/Web/UI/TForm.php2
-rw-r--r--framework/Web/UI/TPage.php20
-rw-r--r--framework/Web/UI/TPageStatePersister.php17
-rw-r--r--framework/Web/UI/TTemplateControl.php2
-rw-r--r--framework/Web/UI/TTemplateManager.php20
-rw-r--r--framework/Web/UI/TThemeManager.php27
12 files changed, 58 insertions, 140 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 19a744a4..6288da5c 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -123,10 +123,6 @@ class TPageService extends TService
*/
private $_initialized=false;
/**
- * @var TApplication application
- */
- private $_application;
- /**
* @var TAssetManager asset manager
*/
private $_assetManager=null;
@@ -146,14 +142,15 @@ class TPageService extends TService
/**
* Initializes the service.
* This method is required by IService interface and is invoked by application.
- * @param TApplication application
* @param TXmlElement service configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- $application->setPageService($this);
+ parent::init($config);
- $this->_application=$application;
+ $application=$this->getApplication();
+
+ $application->setPageService($this);
if($this->_basePath===null)
{
@@ -259,14 +256,12 @@ class TPageService extends TService
$application->setModule($id,$module);
foreach($moduleConfig[1] as $name=>$value)
$module->setSubProperty($name,$value);
- $module->init($this->_application,$moduleConfig[2]);
+ $module->init($moduleConfig[2]);
}
$application->getAuthorizationRules()->mergeWith($pageConfig->getRules());
$this->_initialized=true;
-
- parent::init($application,$config);
}
/**
@@ -293,7 +288,7 @@ class TPageService extends TService
if(!$this->_templateManager)
{
$this->_templateManager=new TTemplateManager;
- $this->_templateManager->init($this->_application,null);
+ $this->_templateManager->init();
}
return $this->_templateManager;
}
@@ -314,7 +309,7 @@ class TPageService extends TService
if(!$this->_assetManager)
{
$this->_assetManager=new TAssetManager;
- $this->_assetManager->init($this->_application,null);
+ $this->_assetManager->init();
}
return $this->_assetManager;
}
@@ -335,7 +330,7 @@ class TPageService extends TService
if(!$this->_themeManager)
{
$this->_themeManager=new TThemeManager;
- $this->_themeManager->init($this->_application,null);
+ $this->_themeManager->init();
}
return $this->_themeManager;
}
@@ -356,7 +351,7 @@ class TPageService extends TService
if(!$this->_pageStatePersister)
{
$this->_pageStatePersister=new TPageStatePersister;
- $this->_pageStatePersister->init($this->_application,null);
+ $this->_pageStatePersister->init();
}
return $this->_pageStatePersister;
}
@@ -452,7 +447,7 @@ class TPageService extends TService
else
throw new THttpException(404,'pageservice_page_unknown',$this->_pagePath);
- $writer=$this->_application->getResponse()->createHtmlWriter();
+ $writer=$this->getResponse()->createHtmlWriter();
$this->_page->run($writer);
$writer->flush();
}
@@ -466,7 +461,7 @@ class TPageService extends TService
*/
public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=false)
{
- return $this->_application->getRequest()->constructUrl($this->_id,$pagePath,$getParams,$encodeAmpersand);
+ return $this->getRequest()->constructUrl($this->_id,$pagePath,$getParams,$encodeAmpersand);
}
}
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index a6fcdf55..df8c8c3d 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -70,12 +70,11 @@ class THttpRequest extends TModule
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
// Info about server variables:
// PHP_SELF contains real URI (w/ path info, w/o query string)
// SCRIPT_NAME is the real URI for the requested script (w/o path info and query string)
@@ -109,7 +108,7 @@ class THttpRequest extends TModule
$this->_items=new TMap(array_merge($_POST,$_GET));
$this->_initialized=true;
- $application->setRequest($this);
+ $this->getApplication()->setRequest($this);
}
/**
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index ad290fb0..c947f9fb 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -75,17 +75,16 @@ class THttpResponse extends TModule implements ITextWriter
* Initializes the module.
* This method is required by IModule and is invoked by application.
* It starts output buffer if it is enabled.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
if($this->_bufferOutput)
ob_start();
$this->_initialized=true;
- $application->setResponse($this);
+ $this->getApplication()->setResponse($this);
}
/**
diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php
index 0698d4d8..d7b1acfa 100644
--- a/framework/Web/THttpSession.php
+++ b/framework/Web/THttpSession.php
@@ -81,16 +81,16 @@ class THttpSession extends TModule
* Initializes the module.
* This method is required by IModule.
* If AutoStart is true, the session will be started.
- * @param TApplication prado application instance
+ * @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
if($this->_autoStart)
session_start();
$this->_initialized=true;
- $application->setSession($this);
+ $this->getApplication()->setSession($this);
}
/**
diff --git a/framework/Web/UI/TAssetManager.php b/framework/Web/UI/TAssetManager.php
index f9a9dcb8..d15e4788 100644
--- a/framework/Web/UI/TAssetManager.php
+++ b/framework/Web/UI/TAssetManager.php
@@ -71,14 +71,13 @@ class TAssetManager extends TModule
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
- $this->_application=$application;
+ $application=$this->getApplication();
if($this->_basePath===null)
$this->_basePath=dirname($application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_BASEPATH;
if(!is_writable($this->_basePath) || !is_dir($this->_basePath))
@@ -152,7 +151,7 @@ class TAssetManager extends TModule
{
$dir=$this->hash(dirname($fullpath));
$file=$this->_basePath.'/'.$dir.'/'.basename($fullpath);
- if(!is_file($file) || $checkTimestamp || $this->_application->getMode()!==TApplication::STATE_PERFORMANCE)
+ if(!is_file($file) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE)
{
if(!is_dir($this->_basePath.'/'.$dir))
@mkdir($this->_basePath.'/'.$dir);
@@ -165,7 +164,7 @@ class TAssetManager extends TModule
else
{
$dir=$this->hash($fullpath);
- if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->_application->getMode()!==TApplication::STATE_PERFORMANCE)
+ if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE)
$this->copyDirectory($fullpath,$this->_basePath.'/'.$dir);
$this->_published[$path]=$this->_baseUrl.'/'.$dir;
return $this->_published[$path];
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index db25cbfc..a70e2c75 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -251,54 +251,6 @@ class TControl extends TComponent
}
/**
- * @return TApplication the application object that the current page is using
- */
- public function getApplication()
- {
- return Prado::getApplication();
- }
-
- /**
- * @return TPageService the page 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
diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php
index dc19fc6d..4cb97911 100644
--- a/framework/Web/UI/TForm.php
+++ b/framework/Web/UI/TForm.php
@@ -13,7 +13,7 @@ class TForm extends TControl
$attributes=$this->getAttributes();
// $writer->addAttribute('name',$this->getName());
$writer->addAttribute('method',$this->getMethod());
- $writer->addAttribute('action',$this->getApplication()->getRequest()->getRequestURI());
+ $writer->addAttribute('action',$this->getRequest()->getRequestURI());
if(($enctype=$this->getEnctype())!=='')
$writer->addAttribute('enctype',$enctype);
$attributes->remove('name');
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 7fe72434..624ed550 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -29,14 +29,6 @@ class TPage extends TTemplateControl
'__PREVPAGE','__CALLBACKID','__CALLBACKPARAM'
);
/**
- * @var TApplication application instance
- */
- private $_application;
- /**
- * @var TPageService page service instance
- */
- private $_pageService;
- /**
* @var TForm form instance
*/
private $_form=null;
@@ -125,8 +117,6 @@ class TPage extends TTemplateControl
*/
public function __construct($initProperties=null)
{
- $this->_application=Prado::getApplication();
- $this->_pageService=$this->_application->getService();
$this->setPage($this);
if(is_array($initProperties))
{
@@ -190,7 +180,7 @@ class TPage extends TTemplateControl
return parent::loadTemplate();
else
{
- $template=$this->_pageService->getTemplateManager()->getTemplateByFileName($this->_templateFile);
+ $template=$this->getService()->getTemplateManager()->getTemplateByFileName($this->_templateFile);
$this->setTemplate($template);
return $template;
}
@@ -315,7 +305,7 @@ class TPage extends TTemplateControl
public function getTheme()
{
if(is_string($this->_theme))
- $this->_theme=$this->_pageService->getThemeManager()->getTheme($this->_theme);
+ $this->_theme=$this->getService()->getThemeManager()->getTheme($this->_theme);
return $this->_theme;
}
@@ -336,7 +326,7 @@ class TPage extends TTemplateControl
public function getStyleSheetTheme()
{
if(is_string($this->_styleSheet))
- $this->_styleSheet=$this->_pageService->getThemeManager()->getTheme($this->_styleSheet);
+ $this->_styleSheet=$this->getService()->getThemeManager()->getTheme($this->_styleSheet);
return $this->_styleSheet;
}
@@ -481,7 +471,7 @@ class TPage extends TTemplateControl
*/
private function determinePostBackMode()
{
- $postData=$this->_application->getRequest()->getItems();
+ $postData=$this->getApplication()->getRequest()->getItems();
if($postData->contains(self::FIELD_PAGESTATE) || $postData->contains(self::FIELD_POSTBACK_TARGET))
$this->_postData=$postData;
}
@@ -499,7 +489,7 @@ class TPage extends TTemplateControl
*/
protected function getPageStatePersister()
{
- return $this->_pageService->getPageStatePersister();
+ return $this->getService()->getPageStatePersister();
}
/**
diff --git a/framework/Web/UI/TPageStatePersister.php b/framework/Web/UI/TPageStatePersister.php
index 07e1eba1..988a2938 100644
--- a/framework/Web/UI/TPageStatePersister.php
+++ b/framework/Web/UI/TPageStatePersister.php
@@ -2,20 +2,17 @@
class TPageStatePersister extends TModule implements IStatePersister
{
- private $_application;
private $_privateKey=null;
/**
* Initializes the service.
* This method is required by IModule interface.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application, $config)
+ public function init($config=null)
{
- parent::init($application,$config);
- $this->_application=$application;
- $application->getService()->setPageStatePersister($this);
+ parent::init($config);
+ $this->getService()->setPageStatePersister($this);
}
public function save($state)
@@ -26,12 +23,12 @@ class TPageStatePersister extends TModule implements IStatePersister
$data=gzcompress($hmac.$data);
else
$data=$hmac.$data;
- $this->_application->getService()->getRequestedPage()->getClientScript()->registerHiddenField(TPage::FIELD_PAGESTATE,base64_encode($data));
+ $this->getService()->getRequestedPage()->getClientScript()->registerHiddenField(TPage::FIELD_PAGESTATE,base64_encode($data));
}
public function load()
{
- $str=base64_decode($this->_application->getRequest()->getItems()->itemAt(TPage::FIELD_PAGESTATE));
+ $str=base64_decode($this->getApplication()->getRequest()->getItems()->itemAt(TPage::FIELD_PAGESTATE));
if($str==='')
return null;
if(extension_loaded('zlib'))
@@ -60,10 +57,10 @@ class TPageStatePersister extends TModule implements IStatePersister
{
if(empty($this->_privateKey))
{
- if(($this->_privateKey=$this->_application->getGlobalState('prado:pagestatepersister:privatekey'))===null)
+ if(($this->_privateKey=$this->getApplication()->getGlobalState('prado:pagestatepersister:privatekey'))===null)
{
$this->_privateKey=$this->generatePrivateKey();
- $this->_application->setGlobalState('prado:pagestatepersister:privatekey',$this->_privateKey,null);
+ $this->getApplication()->setGlobalState('prado:pagestatepersister:privatekey',$this->_privateKey,null);
}
}
return $this->_privateKey;
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php
index dc4bc567..9987bc9c 100644
--- a/framework/Web/UI/TTemplateControl.php
+++ b/framework/Web/UI/TTemplateControl.php
@@ -101,7 +101,7 @@ class TTemplateControl extends TControl implements INamingContainer
*/
protected function loadTemplate()
{
- $template=Prado::getApplication()->getService()->getTemplateManager()->getTemplateByClassName(get_class($this));
+ $template=$this->getService()->getTemplateManager()->getTemplateByClassName(get_class($this));
self::$_template[get_class($this)]=$template;
return $template;
}
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index 21a01b25..544c346f 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -37,24 +37,18 @@ class TTemplateManager extends TModule
* Prefix of the cache variable name for storing parsed templates
*/
const TEMPLATE_CACHE_PREFIX='prado:template:';
- /**
- * @var TApplication application instance
- */
- private $_application;
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
* It starts output buffer if it is enabled.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
- $this->_application=$application;
- $application->getService()->setTemplateManager($this);
+ $this->getService()->setTemplateManager($this);
}
/**
@@ -76,7 +70,7 @@ class TTemplateManager extends TModule
{
if(($fileName=realpath($fileName))!==false && is_file($fileName))
{
- if(($cache=$this->_application->getCache())===null)
+ if(($cache=$this->getApplication()->getCache())===null)
return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
else
{
@@ -351,7 +345,7 @@ class TTemplate extends TComponent implements ITemplate
$component->$setter($url);
break;
case self::CONFIG_PARAMETER: // application parameter
- $component->$setter(Prado::getApplication()->getParameters()->itemAt($v));
+ $component->$setter($this->getApplication()->getParameters()->itemAt($v));
break;
default: // an error if reaching here
break;
@@ -388,7 +382,7 @@ class TTemplate extends TComponent implements ITemplate
$component->setSubProperty($name,$url);
break;
case self::CONFIG_PARAMETER: // application parameter
- $component->setSubProperty($name,Prado::getApplication()->getParameters()->itemAt($v));
+ $component->setSubProperty($name,$this->getApplication()->getParameters()->itemAt($v));
break;
default: // an error if reaching here
break;
@@ -419,7 +413,7 @@ class TTemplate extends TComponent implements ITemplate
$value=$this->_assetManager->publishFilePath($this->_contextPath.'/'.ltrim($value[1],'/'));
break;
case self::CONFIG_PARAMETER:
- $value=Prado::getApplication()->getParameters()->itemAt($value[1]);
+ $value=$this->getApplication()->getParameters()->itemAt($value[1]);
break;
default:
break;
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index afe3f02a..8c7f40a7 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -54,23 +54,17 @@ class TThemeManager extends TModule
* @var string the base URL for all themes
*/
private $_baseUrl=null;
- /**
- * @var TApplication application
- */
- private $_application;
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
- $this->_application=$application;
+ parent::init($config);
$this->_initialized=true;
- $application->getService()->setThemeManager($this);
+ $this->getService()->setThemeManager($this);
}
/**
@@ -81,7 +75,7 @@ class TThemeManager extends TModule
{
$themePath=$this->getBasePath().'/'.$name;
$themeUrl=$this->getBaseUrl().'/'.$name;
- return new TTheme($this->_application,$themePath,$themeUrl);
+ return new TTheme($themePath,$themeUrl);
}
@@ -93,7 +87,7 @@ class TThemeManager extends TModule
{
if($this->_basePath===null)
{
- $this->_basePath=dirname($this->_application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_BASEPATH;
+ $this->_basePath=dirname($this->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;
@@ -126,11 +120,11 @@ class TThemeManager extends TModule
{
if($this->_baseUrl===null)
{
- $appPath=dirname($this->_application->getRequest()->getPhysicalApplicationPath());
+ $appPath=dirname($this->getRequest()->getPhysicalApplicationPath());
$basePath=$this->getBasePath();
if(strpos($basePath,$appPath)===false)
throw new TConfigurationException('thememanager_baseurl_required');
- $appUrl=dirname($this->_application->getRequest()->getApplicationPath());
+ $appUrl=dirname($this->getRequest()->getApplicationPath());
$this->_baseUrl=$appUrl.strtr(substr($basePath,strlen($appPath)),'\\','/');
}
return $this->_baseUrl;
@@ -208,23 +202,22 @@ class TTheme extends TComponent
/**
* Constructor.
- * @param TApplication application instance
* @param string theme path
* @param string theme URL
* @throws TConfigurationException if theme path does not exist or any parsing error of the skin files
*/
- public function __construct($application,$themePath,$themeUrl)
+ public function __construct($themePath,$themeUrl)
{
$this->_themeUrl=$themeUrl;
$this->_name=basename($themePath);
- if(($cache=$application->getCache())!==null)
+ if(($cache=$this->getApplication()->getCache())!==null)
{
$array=$cache->get(self::THEME_CACHE_PREFIX.$themePath);
if(is_array($array))
{
list($skins,$cssFiles,$jsFiles,$timestamp)=$array;
$cacheValid=true;
- if($application->getMode()!==TApplication::STATE_PERFORMANCE)
+ if($this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE)
{
if(($dir=opendir($themePath))===false)
throw new TIOException('theme_path_inexistent',$themePath);