diff options
author | xue <> | 2005-12-23 03:31:07 +0000 |
---|---|---|
committer | xue <> | 2005-12-23 03:31:07 +0000 |
commit | 153581e1081ba4225eb93221aced493709cb606c (patch) | |
tree | 7b2a165708d6fb8e587749e3e0fe1f813c2011aa /framework/Web/Services | |
parent | 5c0517b7748dcfae1264d28df7ea111a67bd3aa4 (diff) |
Implemented new page storage method.
Diffstat (limited to 'framework/Web/Services')
-rw-r--r-- | framework/Web/Services/TPageService.php | 93 |
1 files changed, 36 insertions, 57 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index edb7c213..485346e2 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -83,6 +83,10 @@ class TPageService extends TComponent implements IService */
const CONFIG_CACHE_PREFIX='prado:pageservice:';
/**
+ * Page template file extension
+ */
+ const PAGE_FILE_EXT='.page';
+ /**
* @var string id of this service (page)
*/
private $_id;
@@ -93,16 +97,12 @@ class TPageService extends TComponent implements IService /**
* @var string default page
*/
- private $_defaultPage=null;
+ private $_defaultPage='Home';
/**
* @var string requested page (path)
*/
private $_pagePath;
/**
- * @var string requested page type
- */
- private $_pageType;
- /**
* @var TPage the requested page
*/
private $_page=null;
@@ -143,11 +143,13 @@ class TPageService extends TComponent implements IService */
public function init($application,$config)
{
+ $application->setPageService($this);
+
$this->_application=$application;
if($this->_basePath===null)
{
- $basePath=dirname($application->getConfigurationPath()).'/'.self::DEFAULT_BASEPATH;
+ $basePath=$application->getConfigurationPath().'/'.self::DEFAULT_BASEPATH;
if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath))
throw new TConfigurationException('pageservice_basepath_invalid',$basePath);
}
@@ -156,12 +158,13 @@ class TPageService extends TComponent implements IService if(empty($this->_pagePath))
$this->_pagePath=$this->_defaultPage;
if(empty($this->_pagePath))
- throw new THttpException(400,'pageservice_page_required');
+ throw new THttpException(404,'pageservice_page_required');
if(($cache=$application->getCache())===null)
{
$pageConfig=new TPageConfiguration;
- $pageConfig->loadXmlElement($config,dirname($application->getConfigurationFile()),null);
+ if($config!==null)
+ $pageConfig->loadXmlElement($config,$application->getConfigurationPath(),null);
$pageConfig->loadConfigurationFiles($this->_pagePath,$this->_basePath);
}
else
@@ -171,7 +174,7 @@ class TPageService extends TComponent implements IService if(is_array($arr))
{
list($pageConfig,$timestamp)=$arr;
- if($application->getMode()!=='Performance')
+ if($application->getMode()!==TApplication::STATE_PERFORMANCE)
{
// check to see if cache is the latest
$paths=explode('.',$this->_pagePath);
@@ -186,8 +189,12 @@ class TPageService extends TComponent implements IService }
$configPath.='/'.$path;
}
- if($configCached && (@filemtime($application->getConfigurationFile())>$timestamp || @filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp))
- $configCached=false;
+ if($configCached)
+ {
+ $appConfig=$application->getConfigurationFile();
+ if(!$appConfig || @filemtime($appConfig)>$timestamp || @filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp)
+ $configCached=false;
+ }
}
}
else
@@ -195,13 +202,13 @@ class TPageService extends TComponent implements IService if(!$configCached)
{
$pageConfig=new TPageConfiguration;
- $pageConfig->loadXmlElement($config,dirname($application->getConfigurationFile()),null);
+ if($config!==null)
+ $pageConfig->loadXmlElement($config,$application->getConfigurationPath(),null);
$pageConfig->loadConfigurationFiles($this->_pagePath,$this->_basePath);
$cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,time()));
}
}
- $this->_pageType=$pageConfig->getPageType();
// set path aliases and using namespaces
foreach($pageConfig->getAliases() as $alias=>$path)
@@ -239,6 +246,8 @@ class TPageService extends TComponent implements IService $application->getAuthorizationRules()->mergeWith($pageConfig->getRules());
$this->_initialized=true;
+
+ $application->attachEventHandler('RunService',array($this,'run'));
}
/**
@@ -405,33 +414,25 @@ class TPageService extends TComponent implements IService public function run()
{
$page=null;
- if(($pos=strpos($this->_pageType,'.'))===false)
- {
- $className=$this->_pageType;
- if(!class_exists($className,false))
- {
- $p=explode('.',$this->_pagePath);
- array_pop($p);
- array_push($p,$className);
- $path=$this->_basePath.'/'.implode('/',$p).Prado::CLASS_FILE_EXT;
- include_once($path);
- }
- }
- else
+ $path=$this->_basePath.'/'.strtr($this->_pagePath,'.','/');
+ if(is_file($path.self::PAGE_FILE_EXT))
{
- $className=substr($this->_pageType,$pos+1);
- if(($path=Prado::getPathOfNamespace($this->_pageType,Prado::CLASS_FILE_EXT))!==null)
+ if(is_file($path.Prado::CLASS_FILE_EXT))
{
+ $className=basename($path);
if(!class_exists($className,false))
- {
- include_once($path);
- }
+ include_once($path.Prado::CLASS_FILE_EXT);
+ if(!class_exists($className,false))
+ throw new TConfigurationException('pageservice_pageclass_unknown',$className);
}
- }
- if(class_exists($className,false))
+ else
+ $className='TPage';
+ $this->_properties['Template']=$this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT);
$this->_page=new $className($this->_properties);
+ }
else
- throw new THttpException(404,'pageservice_page_unknown',$this->_pageType);
+ throw new THttpException(404,'pageservice_page_unknown',$this->_pagePath);
+
$writer=$this->_application->getResponse()->createHtmlWriter();
$this->_page->run($writer);
$writer->flush();
@@ -469,10 +470,6 @@ class TPageConfiguration extends TComponent */
private $_properties=array();
/**
- * @var string page type
- */
- private $_pageType=null;
- /**
* @var array list of namespaces to be used
*/
private $_usings=array();
@@ -505,14 +502,6 @@ class TPageConfiguration extends TComponent }
/**
- * @return string the requested page type
- */
- public function getPageType()
- {
- return $this->_pageType;
- }
-
- /**
* Returns list of path alias definitions.
* The definitions are aggregated (top-down) from configuration files along the path
* to the specified page. Each array element represents a single alias definition,
@@ -610,10 +599,7 @@ class TPageConfiguration extends TComponent private function loadFromFile($fname,$page)
{
if(empty($fname) || !is_file($fname))
- {
- if($page===null)
- return;
- }
+ return;
$dom=new TXmlDocument;
if($dom->loadFromFile($fname))
$this->loadXmlElement($dom,dirname($fname),$page);
@@ -742,20 +728,13 @@ class TPageConfiguration extends TComponent foreach($pagesNode->getElementsByTagName('page') as $node)
{
$properties=$node->getAttributes();
- if(($type=$properties->remove('class'))===null)
- $type='TPage';
if(($id=$properties->itemAt('id'))===null)
throw new TConfigurationException('pageserviceconf_page_invalid',$configPath);
if($id===$page)
- {
$this->_properties=array_merge($this->_properties,$properties->toArray());
- $this->_pageType=$type;
- }
}
}
}
- if($page!==null && $this->_pageType===null)
- throw new THttpException(404,'pageservice_page_unknown',$page);
}
}
|