summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Services/TPageService.php93
-rw-r--r--framework/Web/UI/TAssetManager.php4
-rw-r--r--framework/Web/UI/TThemeManager.php2
3 files changed, 39 insertions, 60 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);
}
}
diff --git a/framework/Web/UI/TAssetManager.php b/framework/Web/UI/TAssetManager.php
index 78b84177..f9a9dcb8 100644
--- a/framework/Web/UI/TAssetManager.php
+++ b/framework/Web/UI/TAssetManager.php
@@ -152,7 +152,7 @@ class TAssetManager extends TModule
{
$dir=$this->hash(dirname($fullpath));
$file=$this->_basePath.'/'.$dir.'/'.basename($fullpath);
- if(!is_file($file) || $checkTimestamp || $this->_application->getMode()!=='Performance')
+ if(!is_file($file) || $checkTimestamp || $this->_application->getMode()!==TApplication::STATE_PERFORMANCE)
{
if(!is_dir($this->_basePath.'/'.$dir))
@mkdir($this->_basePath.'/'.$dir);
@@ -165,7 +165,7 @@ class TAssetManager extends TModule
else
{
$dir=$this->hash($fullpath);
- if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->_application->getMode()!=='Performance')
+ if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->_application->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/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index 6c7457ee..afe3f02a 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -224,7 +224,7 @@ class TTheme extends TComponent
{
list($skins,$cssFiles,$jsFiles,$timestamp)=$array;
$cacheValid=true;
- if($application->getMode()!=='Performance')
+ if($application->getMode()!==TApplication::STATE_PERFORMANCE)
{
if(($dir=opendir($themePath))===false)
throw new TIOException('theme_path_inexistent',$themePath);