summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2005-11-16 22:32:52 +0000
committerxue <>2005-11-16 22:32:52 +0000
commit6c1b05deafd9940da5d473800032558df90b118e (patch)
tree3435de08a595fab3ca71ed41f3a88cc9ab6e2995 /framework
parent65acec4f65ddefcb3e9f9762d958be0539f3f71a (diff)
Key modules are now using registered to application rather than using reserved module names.
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/TMemCache.php1
-rw-r--r--framework/Data/TSqliteCache.php3
-rw-r--r--framework/Exceptions/TErrorHandler.php1
-rw-r--r--framework/Security/TAuthManager.php16
-rw-r--r--framework/TApplication.php114
-rw-r--r--framework/Web/Services/TPageService.php3
-rw-r--r--framework/Web/THttpRequest.php45
-rw-r--r--framework/Web/THttpResponse.php1
-rw-r--r--framework/Web/THttpSession.php1
-rw-r--r--framework/core.php4
10 files changed, 115 insertions, 74 deletions
diff --git a/framework/Data/TMemCache.php b/framework/Data/TMemCache.php
index 73eec99f..4d952551 100644
--- a/framework/Data/TMemCache.php
+++ b/framework/Data/TMemCache.php
@@ -111,6 +111,7 @@ class TMemCache extends TComponent implements IModule, ICache
if($application instanceof IApplication)
$this->_prefix=$application->getUniqueID();
$this->_initialized=true;
+ $application->setCache($this);
}
/**
diff --git a/framework/Data/TSqliteCache.php b/framework/Data/TSqliteCache.php
index 8d59b035..f589f93d 100644
--- a/framework/Data/TSqliteCache.php
+++ b/framework/Data/TSqliteCache.php
@@ -129,8 +129,9 @@ class TSqliteCache extends TComponent implements IModule, ICache
}
else
throw new TConfigurationException('sqlitecache_table_creation_failed',sqlite_error_string(sqlite_last_error()));
- $this->_initialized=true;
$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time());
+ $this->_initialized=true;
+ $application->setCache($this);
}
/**
diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php
index 458d3169..f88396ce 100644
--- a/framework/Exceptions/TErrorHandler.php
+++ b/framework/Exceptions/TErrorHandler.php
@@ -21,6 +21,7 @@ class TErrorHandler extends TComponent implements IErrorHandler
{
$application->attachEventHandler('Error',array($this,'handle'));
$this->_initialized=true;
+ $application->setErrorHandler($this);
}
/**
diff --git a/framework/Security/TAuthManager.php b/framework/Security/TAuthManager.php
index c12ee245..57288c0f 100644
--- a/framework/Security/TAuthManager.php
+++ b/framework/Security/TAuthManager.php
@@ -3,10 +3,6 @@
class TAuthManager extends TComponent implements IModule
{
const RETURN_URL_VAR='ReturnUrl';
- /**
- * @var TAuthorizationRuleCollection list of authorization rules
- */
- private $_authRules=null;
private $_guest='Guest';
private $_initialized=false;
private $_application;
@@ -137,7 +133,7 @@ class TAuthManager extends TComponent implements IModule
{
if($this->hasEventHandler('Authenticate'))
$this->raiseEvent('Authorize',$this,$this->_application);
- if($this->_authRules!==null && !$this->_authRules->isUserAllowed($this->_application->getUser(),$this->_application->getRequest()->getRequestType()))
+ if(!$this->_application->getAuthorizationRules()->isUserAllowed($this->_application->getUser(),$this->_application->getRequest()->getRequestType()))
{
$this->_application->getResponse()->setStatusCode(401);
$this->_application->completeRequest();
@@ -190,16 +186,6 @@ class TAuthManager extends TComponent implements IModule
$session->destroy();
}
}
- /**
- * @return TAuthorizationRuleCollection list of authorization rules that may be applied
- */
-
- public function getAuthorizationRules()
- {
- if($this->_authRules===null)
- $this->_authRules=new TAuthorizationRuleCollection;
- return $this->_authRules;
- }
}
?> \ No newline at end of file
diff --git a/framework/TApplication.php b/framework/TApplication.php
index f1a7d316..441de82e 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -72,16 +72,6 @@ class TApplication extends TComponent implements IApplication
'PostSaveState',
'EndRequest'
);
- /**
- * @var array list of types that the named modules must be of
- */
- private static $_moduleTypes=array(
- 'request'=>'THttpRequest',
- 'response'=>'THttpResponse',
- 'session'=>'THttpSession',
- 'cache'=>'ICache',
- 'error'=>'IErrorHandler'
- );
/**
* @var string application ID
@@ -124,9 +114,33 @@ class TApplication extends TComponent implements IApplication
*/
private $_userType='System.Security.TUser';
/**
- * @var IUser user instance
+ * @var TErrorHandler error handler module
+ */
+ private $_errorHandler=null;
+ /**
+ * @var THttpRequest request module
+ */
+ private $_request=null;
+ /**
+ * @var THttpResponse response module
+ */
+ private $_response=null;
+ /**
+ * @var THttpSession session module, could be null
+ */
+ private $_session=null;
+ /**
+ * @var ICache cache module, could be null
+ */
+ private $_cache=null;
+ /**
+ * @var IUser user instance, could be null
*/
private $_user=null;
+ /**
+ * @var TAuthorizationRuleCollection collection of authorization rules
+ */
+ private $_authRules=null;
/**
* Constructor.
@@ -264,51 +278,83 @@ class TApplication extends TComponent implements IApplication
}
/**
- * @return THttpRequest the request object
+ * @return THttpRequest the request module
*/
public function getRequest()
{
- return isset($this->_modules['request'])?$this->_modules['request']:null;
+ return $this->_request;
}
/**
- * @return THttpResponse the response object
+ * @param THttpRequest the request module
+ */
+ public function setRequest(THttpRequest $request)
+ {
+ $this->_request=$request;
+ }
+
+ /**
+ * @return THttpResponse the response module
*/
public function getResponse()
{
- return isset($this->_modules['response'])?$this->_modules['response']:null;
+ return $this->_response;
+ }
+
+ /**
+ * @param THttpRequest the request module
+ */
+ public function setResponse(THttpResponse $response)
+ {
+ $this->_response=$response;
+ }
+
+ /**
+ * @return TErrorHandler the error hanlder module
+ */
+ public function getErrorHandler()
+ {
+ return $this->_errorHandler;
+ }
+
+ /**
+ * @param TErrorHandler the error hanlder module
+ */
+ public function setErrorHandler(TErrorHandler $handler)
+ {
+ $this->_errorHandler=$handler;
}
/**
- * @return THttpSession the session object
+ * @return THttpSession the session module, null if session module is not installed
*/
public function getSession()
{
- return isset($this->_modules['session'])?$this->_modules['session']:null;
+ return $this->_session;
}
/**
- * @return ICache the cache object, null if not exists
+ * @param THttpSession the session module
*/
- public function getCache()
+ public function setSession(THttpSession $session)
{
- return isset($this->_modules['cache'])?$this->_modules['cache']:null;
+ $this->_session=$session;
}
/**
- * @return IErrorHandler the error hanlder module
+ * @return ICache the cache module, null if cache module is not installed
*/
- public function getErrorHandler()
+ public function getCache()
{
- return isset($this->_modules['error'])?$this->_modules['error']:null;
+ return $this->_cache;
}
/**
- * @return IRoleProvider provider for user auth management
+ * @param ICache the cache module
*/
- public function getAuthManager()
+ public function setCache(ICache $cache)
{
- return isset($this->_modules['auth'])?$this->_modules['auth']:null;
+ $this->_cache=$cache;
}
/**
@@ -328,6 +374,16 @@ class TApplication extends TComponent implements IApplication
}
/**
+ * @return TAuthorizationRuleCollection list of authorization rules that may be applied
+ */
+ public function getAuthorizationRules()
+ {
+ if($this->_authRules===null)
+ $this->_authRules=new TAuthorizationRuleCollection;
+ return $this->_authRules;
+ }
+
+ /**
* Loads configuration and initializes application.
* Configuration file will be read and parsed (if a valid cache version exists,
* it will be used instead). Then, modules are created and initialized;
@@ -395,8 +451,6 @@ class TApplication extends TComponent implements IApplication
if(isset($this->_modules[$id]))
throw new TConfigurationException('application_module_redefined',$id);
$module=Prado::createComponent($moduleConfig[0]);
- if(isset(self::$_moduleTypes[$id]) && !($module instanceof self::$_moduleTypes[$id]))
- throw new TConfigurationException('application_module_invalid',$id,self::$_moduleTypes[$id]);
$this->_modules[$id]=$module;
foreach($moduleConfig[1] as $name=>$value)
$module->setSubProperty($name,$value);
@@ -597,9 +651,9 @@ class TApplicationConfiguration extends TComponent
* @var array list of module configurations
*/
private $_modules=array(
+ 'error'=>array('TErrorHandler',array(),null),
'request'=>array('THttpRequest',array(),null),
- 'response'=>array('THttpResponse',array(),null),
- 'error'=>array('TErrorHandler',array(),null)
+ 'response'=>array('THttpResponse',array(),null)
);
/**
* @var array list of service configurations
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index f32e8ee7..0fb39dfb 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -165,8 +165,7 @@ class TPageService extends TComponent implements IService
$module->init($this->_application,$moduleConfig[2]);
}
- if(($auth=$application->getAuthManager())!==null)
- $auth->getAuthorizationRules()->mergeWith($pageConfig->getRules());
+ $application->getAuthorizationRules()->mergeWith($pageConfig->getRules());
$this->_initialized=true;
}
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index f87111ba..9be0db8a 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -68,6 +68,28 @@ class THttpRequest extends TComponent implements IModule
*/
public function __construct()
{
+ }
+
+ /**
+ * Strips slashes from input data.
+ * This method is applied when magic quotes is enabled.
+ * Do not call this method.
+ * @param mixed input data to be processed
+ * @param mixed processed data
+ */
+ public function stripSlashes(&$data)
+ {
+ return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data);
+ }
+
+ /**
+ * Initializes the module.
+ * This method is required by IModule and is invoked by application.
+ * @param IApplication application
+ * @param TXmlElement module configuration
+ */
+ public function init($application,$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)
@@ -101,29 +123,8 @@ class THttpRequest extends TComponent implements IModule
$this->_items=new TMap(array_merge($_POST,$_GET));
$this->resolveRequest();
- }
-
- /**
- * Strips slashes from input data.
- * This method is applied when magic quotes is enabled.
- * Do not call this method.
- * @param mixed input data to be processed
- * @param mixed processed data
- */
- public function stripSlashes(&$data)
- {
- return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data);
- }
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param IApplication application
- * @param TXmlElement module configuration
- */
- public function init($application,$config)
- {
$this->_initialized=true;
+ $application->setRequest($this);
}
/**
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index 4dd81868..777c6621 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -68,6 +68,7 @@ class THttpResponse extends TComponent implements IModule, ITextWriter
if($this->_bufferOutput)
ob_start();
$this->_initialized=true;
+ $application->setResponse($this);
}
/**
diff --git a/framework/Web/THttpSession.php b/framework/Web/THttpSession.php
index fc8f99c6..ff3af560 100644
--- a/framework/Web/THttpSession.php
+++ b/framework/Web/THttpSession.php
@@ -79,6 +79,7 @@ class THttpSession extends TComponent implements IModule
if($this->_autoStart)
session_start();
$this->_initialized=true;
+ $application->setSession($this);
}
/**
diff --git a/framework/core.php b/framework/core.php
index 16ddb62a..095eea97 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -191,10 +191,6 @@ interface IApplication
* @return IErrorHandler error handler
*/
public function getErrorHandler();
- /**
- * @return IAuthManager the auth (authentication/authorization) manager
- */
- public function getAuthManager();
}
/**