summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2005-12-28 20:17:54 +0000
committerxue <>2005-12-28 20:17:54 +0000
commite8b60312037e54c34a06d6f57d7c21946cf3cd1f (patch)
treea6f35f5d4bb921998ca306602a33fc03ba47c4b5
parent930c51a6d618d487105cd46c517f36c3b1fe3b44 (diff)
Modified the way to access application singleton.
IService and IModule interfaces are also adjusted accordingly.
-rw-r--r--framework/Data/TMemCache.php11
-rw-r--r--framework/Data/TSqliteCache.php11
-rw-r--r--framework/Exceptions/TErrorHandler.php18
-rw-r--r--framework/Security/TAuthManager.php50
-rw-r--r--framework/Security/TUserManager.php5
-rw-r--r--framework/TApplication.php39
-rw-r--r--framework/TComponent.php48
-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
-rw-r--r--framework/core.php14
20 files changed, 167 insertions, 227 deletions
diff --git a/framework/Data/TMemCache.php b/framework/Data/TMemCache.php
index e4e9ffa3..a34cd9a6 100644
--- a/framework/Data/TMemCache.php
+++ b/framework/Data/TMemCache.php
@@ -44,7 +44,7 @@
* Some usage examples of TMemCache are as follows,
* <code>
* $cache=new TMemCache; // TMemCache may also be loaded as a Prado application module
- * $cache->init(null);
+ * $cache->init();
* $cache->add('object',$object);
* $object2=$cache->get('object');
* </code>
@@ -105,19 +105,18 @@ class TMemCache extends TModule implements ICache
* @param TXmlElement configuration for this module, can be null
* @throws TConfigurationException if memcache extension is not installed or memcache sever connection fails
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
if(!extension_loaded('memcache'))
throw new TConfigurationException('memcache_extension_required');
$this->_cache=new Memcache;
if($this->_cache->connect($this->_host,$this->_port)===false)
throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port);
- if($application instanceof TApplication)
- $this->_prefix=$application->getUniqueID();
+ $this->_prefix=$this->getApplication()->getUniqueID();
$this->_initialized=true;
- $application->setCache($this);
+ $this->getApplication()->setCache($this);
}
/**
diff --git a/framework/Data/TSqliteCache.php b/framework/Data/TSqliteCache.php
index 865c2a47..d2955ccd 100644
--- a/framework/Data/TSqliteCache.php
+++ b/framework/Data/TSqliteCache.php
@@ -47,7 +47,7 @@
* <code>
* $cache=new TSqliteCache; // TSqliteCache may also be loaded as a Prado application module
* $cache->setDbFile($dbFilePath);
- * $cache->init(null);
+ * $cache->init();
* $cache->add('object',$object);
* $object2=$cache->get('object');
* </code>
@@ -109,19 +109,18 @@ class TSqliteCache extends TModule implements ICache
* property is set, and creates a SQLiteDatabase instance for it.
* The database or the cache table does not exist, they will be created.
* Expired values are also deleted.
- * @param TApplication Prado application, can be null
* @param TXmlElement configuration for this module, can be null
* @throws TConfigurationException if sqlite extension is not installed,
* DbFile is set invalid, or any error happens during creating database or cache table.
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
if(!function_exists('sqlite_open'))
throw new TConfigurationException('sqlitecache_extension_required');
if($this->_file===null)
- $this->_file=$application->getRuntimePath().'/sqlite.cache';
+ $this->_file=$this->getApplication()->getRuntimePath().'/sqlite.cache';
$error='';
if(($this->_db=new SQLiteDatabase($this->_file,0666,$error))===false)
throw new TConfigurationException('sqlitecache_connection_failed',$error);
@@ -137,7 +136,7 @@ class TSqliteCache extends TModule implements ICache
throw new TConfigurationException('sqlitecache_table_creation_failed',sqlite_error_string(sqlite_last_error()));
$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time());
$this->_initialized=true;
- $application->setCache($this);
+ $this->getApplication()->setCache($this);
}
/**
diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php
index ca42c8ff..c8137a09 100644
--- a/framework/Exceptions/TErrorHandler.php
+++ b/framework/Exceptions/TErrorHandler.php
@@ -65,10 +65,6 @@ class TErrorHandler extends TModule
const SOURCE_LINES=12;
/**
- * @var TApplication application instance
- */
- private $_application;
- /**
* @var string error template directory
*/
private $_templatePath=null;
@@ -76,15 +72,13 @@ class TErrorHandler 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->setErrorHandler($this);
+ $this->getApplication()->setErrorHandler($this);
}
/**
@@ -132,13 +126,13 @@ class TErrorHandler extends TModule
else
{
$handling=true;
- if(($response=Prado::getApplication()->getResponse())!==null)
+ if(($response=$this->getResponse())!==null)
$response->clear();
if(!headers_sent())
header('Content-Type: text/html; charset=UTF-8');
if($param instanceof THttpException)
$this->handleExternalError($param->getStatusCode(),$param);
- else if(Prado::getApplication()->getMode()===TApplication::STATE_DEBUG)
+ else if($this->getApplication()->getMode()===TApplication::STATE_DEBUG)
$this->displayException($param);
else
$this->handleExternalError(500,$param);
@@ -192,7 +186,7 @@ class TErrorHandler extends TModule
*/
protected function handleRecursiveError($exception)
{
- if(Prado::getApplication()->getMode()===TApplication::STATE_DEBUG)
+ if($this->getApplication()->getMode()===TApplication::STATE_DEBUG)
{
echo "<html><head><title>Recursive Error</title></head>\n";
echo "<body><h1>Recursive Error</h1>\n";
diff --git a/framework/Security/TAuthManager.php b/framework/Security/TAuthManager.php
index 3bf6964e..d0dc6718 100644
--- a/framework/Security/TAuthManager.php
+++ b/framework/Security/TAuthManager.php
@@ -45,10 +45,6 @@ class TAuthManager extends TModule
*/
private $_initialized=false;
/**
- * @var TApplication application instance
- */
- private $_application;
- /**
* @var TUserManager user manager instance
*/
private $_userManager=null;
@@ -64,16 +60,16 @@ class TAuthManager extends TModule
/**
* Initializes this module.
* This method is required by the IModule interface.
- * @param TApplication Prado application, can be null
* @param TXmlElement configuration for this module, can be null
* @throws TConfigurationException if user manager does not exist or is not TUserManager
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
+ parent::init($config);
if($this->_userManager===null)
throw new TConfigurationException('authmanager_usermanager_required');
+ $application=$this->getApplication();
if(is_string($this->_userManager))
{
if(($users=$application->getModule($this->_userManager))===null)
@@ -82,7 +78,6 @@ class TAuthManager extends TModule
throw new TConfigurationException('authmanager_usermanager_invalid',$this->_userManager);
$this->_userManager=$users;
}
- $this->_application=$application;
$application->attachEventHandler('Authentication',array($this,'doAuthentication'));
$application->attachEventHandler('EndRequest',array($this,'leave'));
$application->attachEventHandler('Authorization',array($this,'doAuthorization'));
@@ -140,7 +135,7 @@ class TAuthManager extends TModule
{
$this->onAuthenticate($param);
- $service=$this->_application->getService();
+ $service=$this->getService();
if(($service instanceof TPageService) && $service->getRequestedPagePath()===$this->getLoginPage())
$this->_skipAuthorization=true;
}
@@ -169,14 +164,15 @@ class TAuthManager extends TModule
*/
public function leave($sender,$param)
{
- if($this->_application->getResponse()->getStatusCode()===401)
+ $application=$this->getApplication();
+ if($application->getResponse()->getStatusCode()===401)
{
- $service=$this->_application->getService();
+ $service=$application->getService();
if($service instanceof TPageService)
{
- $returnUrl=$this->_application->getRequest()->getRequestUri();
+ $returnUrl=$application->getRequest()->getRequestUri();
$url=$service->constructUrl($this->getLoginPage(),array(self::RETURN_URL_VAR=>$returnUrl));
- $this->_application->getResponse()->redirect($url);
+ $application->getResponse()->redirect($url);
}
}
}
@@ -191,17 +187,18 @@ class TAuthManager extends TModule
*/
public function onAuthenticate($param)
{
+ $application=$this->getApplication();
if($this->hasEventHandler('Authenticate'))
- $this->raiseEvent('Authenticate',$this,$this->_application);
- if($this->_application->getUser()!==null)
+ $this->raiseEvent('Authenticate',$this,$application);
+ if($application->getUser()!==null)
return;
- if(($session=$this->_application->getSession())===null)
+ if(($session=$application->getSession())===null)
throw new TConfigurationException('authmanager_session_required');
$session->open();
$sessionInfo=$session->getItems()->itemAt($this->generateUserSessionKey());
$user=$this->_userManager->getUser(null)->loadFromString($sessionInfo);
- $this->_application->setUser($user);
+ $application->setUser($user);
}
/**
@@ -213,12 +210,13 @@ class TAuthManager extends TModule
*/
public function onAuthorize($param)
{
+ $application=$this->getApplication();
if($this->hasEventHandler('Authorize'))
- $this->raiseEvent('Authorize',$this,$this->_application);
- if(!$this->_application->getAuthorizationRules()->isUserAllowed($this->_application->getUser(),$this->_application->getRequest()->getRequestType()))
+ $this->raiseEvent('Authorize',$this,$application);
+ if(!$application->getAuthorizationRules()->isUserAllowed($application->getUser(),$application->getRequest()->getRequestType()))
{
- $this->_application->getResponse()->setStatusCode(401);
- $this->_application->completeRequest();
+ $application->getResponse()->setStatusCode(401);
+ $application->completeRequest();
}
}
@@ -227,7 +225,7 @@ class TAuthManager extends TModule
*/
protected function generateUserSessionKey()
{
- return md5($this->_application->getUniqueID().'prado:user');
+ return md5($this->getApplication()->getUniqueID().'prado:user');
}
/**
@@ -239,7 +237,7 @@ class TAuthManager extends TModule
{
if(!$user->getIsGuest())
{
- if(($session=$this->_application->getSession())===null)
+ if(($session=$this->getSession())===null)
throw new TConfigurationException('authmanager_session_required');
else
$session->getItems()->add($this->generateUserSessionKey(),$user->saveToString());
@@ -260,7 +258,7 @@ class TAuthManager extends TModule
{
$user=$this->_userManager->getUser($username);
$this->updateSessionUser($user);
- $this->_application->setUser($user);
+ $this->getApplication()->setUser($user);
return true;
}
else
@@ -274,11 +272,11 @@ class TAuthManager extends TModule
*/
public function logout()
{
- if(($session=$this->_application->getSession())===null)
+ if(($session=$this->getSession())===null)
throw new TConfigurationException('authmanager_session_required');
else
{
- $this->_userManager->switchToGuest($this->_application->getUser());
+ $this->_userManager->switchToGuest($this->getUser());
$session->destroy();
}
}
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php
index 8faa7f96..7ecf357d 100644
--- a/framework/Security/TUserManager.php
+++ b/framework/Security/TUserManager.php
@@ -225,12 +225,11 @@ class TUserManager extends TModule
* Initializes the module.
* This method is required by IModule and is invoked by application.
* It loads user/role information from the module configuration.
- * @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->_userFile!==null)
{
diff --git a/framework/TApplication.php b/framework/TApplication.php
index e2743c6d..c28c3da9 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -536,7 +536,7 @@ class TApplication extends TComponent
if(!$this->_pageService)
{
$this->_pageService=new TPageService;
- $this->_pageService->init($this,null);
+ $this->_pageService->init();
}
return $this->_pageService;
}
@@ -559,7 +559,7 @@ class TApplication extends TComponent
if(!$this->_request)
{
$this->_request=new THttpRequest;
- $this->_request->init($this,null);
+ $this->_request->init();
}
return $this->_request;
}
@@ -580,7 +580,7 @@ class TApplication extends TComponent
if(!$this->_response)
{
$this->_response=new THttpResponse;
- $this->_response->init($this,null);
+ $this->_response->init();
}
return $this->_response;
}
@@ -601,7 +601,7 @@ class TApplication extends TComponent
if(!$this->_session)
{
$this->_session=new THttpSession;
- $this->_session->init($this,null);
+ $this->_session->init();
}
return $this->_session;
}
@@ -622,7 +622,7 @@ class TApplication extends TComponent
if(!$this->_errorHandler)
{
$this->_errorHandler=new TErrorHandler;
- $this->_errorHandler->init($this,null);
+ $this->_errorHandler->init();
}
return $this->_errorHandler;
}
@@ -643,7 +643,7 @@ class TApplication extends TComponent
if(!$this->_statePersister)
{
$this->_statePersister=new TApplicationStatePersister;
- $this->_statePersister->init($this,null);
+ $this->_statePersister->init();
}
return $this->_statePersister;
}
@@ -771,7 +771,7 @@ class TApplication extends TComponent
$this->_modules[$id]=$module;
foreach($moduleConfig[1] as $name=>$value)
$module->setSubProperty($name,$value);
- $module->init($this,$moduleConfig[2]);
+ $module->init($moduleConfig[2]);
}
// load service
@@ -792,7 +792,7 @@ class TApplication extends TComponent
$this->_service=$service;
foreach($serviceConfig[1] as $name=>$value)
$service->setSubProperty($name,$value);
- $service->init($this,$serviceConfig[2]);
+ $service->init($serviceConfig[2]);
}
else
$this->_service=$this->getPageService();
@@ -1118,11 +1118,6 @@ class TApplicationConfiguration extends TComponent
/**
* @return array list of service configurations
*/
- public function getService($id)
- {
- return isset($this->_services[$id])?$this->_services[$id]:null;
- }
-
public function getServices()
{
return $this->_services;
@@ -1155,21 +1150,15 @@ class TApplicationStatePersister extends TModule implements IStatePersister
* Name of the value stored in cache
*/
const CACHE_NAME='prado:appstate';
- /**
- * @var TApplication application instance
- */
- private $_application;
/**
* Initializes module.
- * @param TApplication application instance
* @param TXmlElement module configuration (may be null)
*/
- public function init($application,$config)
+ public function init($config=null)
{
- parent::init($application,$config);
- $this->_application=$application;
- $application->setApplicationStatePersister($this);
+ parent::init($config);
+ $this->getApplication()->setApplicationStatePersister($this);
}
/**
@@ -1177,7 +1166,7 @@ class TApplicationStatePersister extends TModule implements IStatePersister
*/
protected function getStateFilePath()
{
- return $this->_application->getRuntimePath().'/global.cache';
+ return $this->getApplication()->getRuntimePath().'/global.cache';
}
/**
@@ -1186,7 +1175,7 @@ class TApplicationStatePersister extends TModule implements IStatePersister
*/
public function load()
{
- if(($cache=$this->_application->getCache())!==null && ($value=$cache->get(self::CACHE_NAME))!==false)
+ if(($cache=$this->getApplication()->getCache())!==null && ($value=$cache->get(self::CACHE_NAME))!==false)
return unserialize($value);
else
{
@@ -1205,7 +1194,7 @@ class TApplicationStatePersister extends TModule implements IStatePersister
{
$content=serialize($state);
$saveFile=true;
- if(($cache=$this->_application->getCache())!==null)
+ if(($cache=$this->getApplication()->getCache())!==null)
{
if($cache->get(self::CACHE_NAME)===$content)
$saveFile=false;
diff --git a/framework/TComponent.php b/framework/TComponent.php
index 0282be3a..432dba66 100644
--- a/framework/TComponent.php
+++ b/framework/TComponent.php
@@ -426,6 +426,54 @@ class TComponent
throw new TInvalidOperationException('component_statements_invalid',get_class($this),$statements,$e->getMessage());
}
}
+
+ /**
+ * @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();
+ }
}
/**
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);
diff --git a/framework/core.php b/framework/core.php
index 8288f82f..c864dbfa 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -56,10 +56,9 @@ interface IModule
{
/**
* Initializes the module.
- * @param TApplication the application object
* @param TXmlElement the configuration for the module
*/
- public function init($application,$configuration);
+ public function init($configuration=null);
/**
* @return string ID of the module
*/
@@ -84,10 +83,9 @@ interface IService
{
/**
* Initializes the service.
- * @param TApplication the application object
* @param TXmlElement the configuration for the service
*/
- public function init($application,$configuration);
+ public function init($configuration=null);
/**
* @return string ID of the service
*/
@@ -322,7 +320,7 @@ interface IStatePersister
* @package System
* @since 3.0
*/
-class TModule extends TComponent implements IModule
+abstract class TModule extends TComponent implements IModule
{
/**
* @var string module id
@@ -332,10 +330,9 @@ class TModule extends TComponent implements IModule
/**
* 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)
{
}
@@ -377,10 +374,9 @@ abstract class TService extends TComponent implements IService
/**
* Initializes the service and attaches {@link run} to the RunService event of application.
* This method is required by IService and is invoked by application.
- * @param TApplication application
* @param TXmlElement module configuration
*/
- public function init($application,$config)
+ public function init($config=null)
{
}