summaryrefslogtreecommitdiff
path: root/framework/Web/UI
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/UI
parent930c51a6d618d487105cd46c517f36c3b1fe3b44 (diff)
Modified the way to access application singleton.
IService and IModule interfaces are also adjusted accordingly.
Diffstat (limited to 'framework/Web/UI')
-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
8 files changed, 36 insertions, 111 deletions
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);