Completed
Push — master ( b3dcb6...928b4e )
by Fabio
07:08
created
framework/Web/Services/TPageService.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	/**
105 105
 	 * Prefix of Pages used for instantiating new pages
106 106
 	 */
107
-	const PAGE_NAMESPACE_PREFIX = 'Application\\Pages\\';
107
+	const PAGE_NAMESPACE_PREFIX='Application\\Pages\\';
108 108
 	/**
109 109
 	 * @var string root path of pages
110 110
 	 */
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	public function init($config)
156 156
 	{
157
-		Prado::trace("Initializing TPageService",'\Prado\Web\Services\TPageService');
157
+		Prado::trace("Initializing TPageService", '\Prado\Web\Services\TPageService');
158 158
 
159 159
 		$pageConfig=$this->loadPageConfig($config);
160 160
 
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
 		// external configurations
193 193
 		foreach($config->getExternalConfigurations() as $filePath=>$params)
194 194
 		{
195
-			list($configPagePath,$condition)=$params;
195
+			list($configPagePath, $condition)=$params;
196 196
 			if($condition!==true)
197 197
 				$condition=$this->evaluateExpression($condition);
198 198
 			if($condition)
199 199
 			{
200
-				if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path))
201
-					throw new TConfigurationException('pageservice_includefile_invalid',$filePath);
200
+				if(($path=Prado::getPathOfNamespace($filePath, Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path))
201
+					throw new TConfigurationException('pageservice_includefile_invalid', $filePath);
202 202
 				$c=new TPageConfiguration($pagePath);
203
-				$c->loadFromFile($path,$configPagePath);
203
+				$c->loadFromFile($path, $configPagePath);
204 204
 				$this->applyConfiguration($c);
205 205
 			}
206 206
 		}
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 			if($config!==null)
235 235
 			{
236 236
 				if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
237
-					$pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
237
+					$pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), '');
238 238
 				else
239
-					$pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
239
+					$pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), '');
240 240
 			}
241 241
 			$pageConfig->loadFromFiles($this->getBasePath());
242 242
 		}
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			$arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath);
248 248
 			if(is_array($arr))
249 249
 			{
250
-				list($pageConfig,$timestamps)=$arr;
250
+				list($pageConfig, $timestamps)=$arr;
251 251
 				if($application->getMode()!==TApplicationMode::Performance)
252 252
 				{
253 253
 					foreach($timestamps as $fileName=>$timestamp)
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 						if($fileName===0) // application config file
256 256
 						{
257 257
 							$appConfigFile=$application->getConfigurationFile();
258
-							$currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile);
259
-							if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0]))
258
+							$currentTimestamp[0]=$appConfigFile===null ? 0 : @filemtime($appConfigFile);
259
+							if($currentTimestamp[0] > $timestamp || ($timestamp > 0 && !$currentTimestamp[0]))
260 260
 								$configCached=false;
261 261
 						}
262 262
 						else
263 263
 						{
264 264
 							$currentTimestamp[$fileName]=@filemtime($fileName);
265
-							if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName]))
265
+							if($currentTimestamp[$fileName] > $timestamp || ($timestamp > 0 && !$currentTimestamp[$fileName]))
266 266
 								$configCached=false;
267 267
 						}
268 268
 					}
@@ -271,9 +271,9 @@  discard block
 block discarded – undo
271 271
 			else
272 272
 			{
273 273
 				$configCached=false;
274
-				$paths=explode('.',$pagePath);
274
+				$paths=explode('.', $pagePath);
275 275
 				$configPath=$this->getBasePath();
276
-				$fileName = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
276
+				$fileName=$this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
277 277
 					? self::CONFIG_FILE_PHP
278 278
 					: self::CONFIG_FILE_XML;
279 279
 				foreach($paths as $path)
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 					$configPath.=DIRECTORY_SEPARATOR.$path;
284 284
 				}
285 285
 				$appConfigFile=$application->getConfigurationFile();
286
-				$currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile);
286
+				$currentTimestamp[0]=$appConfigFile===null ? 0 : @filemtime($appConfigFile);
287 287
 			}
288 288
 			if(!$configCached)
289 289
 			{
@@ -291,12 +291,12 @@  discard block
 block discarded – undo
291 291
 				if($config!==null)
292 292
 				{
293 293
 					if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
294
-						$pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
294
+						$pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), '');
295 295
 					else
296
-						$pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
296
+						$pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), '');
297 297
 				}
298 298
 				$pageConfig->loadFromFiles($this->getBasePath());
299
-				$cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp));
299
+				$cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath, array($pageConfig, $currentTimestamp));
300 300
 			}
301 301
 		}
302 302
 		return $pageConfig;
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
 	{
352 352
 		if($this->_pagePath===null)
353 353
 		{
354
-			$this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..');
354
+			$this->_pagePath=strtr($this->determineRequestedPagePath(), '/\\', '..');
355 355
 			if(empty($this->_pagePath))
356
-				throw new THttpException(404,'pageservice_page_required');
356
+				throw new THttpException(404, 'pageservice_page_required');
357 357
 		}
358 358
 		return $this->_pagePath;
359 359
 	}
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 			{
407 407
 				$basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH;
408 408
 				if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath))
409
-					throw new TConfigurationException('pageservice_basepath_invalid',$basePath);
409
+					throw new TConfigurationException('pageservice_basepath_invalid', $basePath);
410 410
 			}
411 411
 		}
412 412
 		return $this->_basePath;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 		if($this->_initialized)
422 422
 			throw new TInvalidOperationException('pageservice_basepath_unchangeable');
423 423
 		else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path))
424
-			throw new TConfigurationException('pageservice_basepath_invalid',$value);
424
+			throw new TConfigurationException('pageservice_basepath_invalid', $value);
425 425
 		$this->_basePath=realpath($path);
426 426
 	}
427 427
 
@@ -470,9 +470,9 @@  discard block
 block discarded – undo
470 470
 	 */
471 471
 	public function run()
472 472
 	{
473
-		Prado::trace("Running page service",'Prado\Web\Services\TPageService');
473
+		Prado::trace("Running page service", 'Prado\Web\Services\TPageService');
474 474
 		$this->_page=$this->createPage($this->getRequestedPagePath());
475
-		$this->runPage($this->_page,$this->_properties);
475
+		$this->runPage($this->_page, $this->_properties);
476 476
 	}
477 477
 
478 478
 	/**
@@ -484,34 +484,34 @@  discard block
 block discarded – undo
484 484
 	 */
485 485
 	protected function createPage($pagePath)
486 486
 	{
487
-		$path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR);
487
+		$path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath, '.', DIRECTORY_SEPARATOR);
488 488
 		$hasTemplateFile=is_file($path.self::PAGE_FILE_EXT);
489 489
 		$hasClassFile=is_file($path.Prado::CLASS_FILE_EXT);
490 490
 
491 491
 		if(!$hasTemplateFile && !$hasClassFile)
492
-			throw new THttpException(404,'pageservice_page_unknown',$pagePath);
492
+			throw new THttpException(404, 'pageservice_page_unknown', $pagePath);
493 493
 
494 494
 		if($hasClassFile)
495 495
 		{
496 496
 			$className=basename($path);
497
-			$namespacedClassName = static::PAGE_NAMESPACE_PREFIX .str_replace('.', '\\', $pagePath);
497
+			$namespacedClassName=static::PAGE_NAMESPACE_PREFIX.str_replace('.', '\\', $pagePath);
498 498
 
499
-            if(!class_exists($className,false) && !class_exists($namespacedClassName, false))
499
+            if(!class_exists($className, false) && !class_exists($namespacedClassName, false))
500 500
                 include_once($path.Prado::CLASS_FILE_EXT);
501 501
 
502
-			if(!class_exists($className,false))
503
-				$className = $namespacedClassName;
502
+			if(!class_exists($className, false))
503
+				$className=$namespacedClassName;
504 504
 		}
505 505
 		else
506 506
 		{
507 507
 			$className=$this->getBasePageClass();
508 508
 			Prado::using($className);
509
-			if(($pos=strrpos($className,'.'))!==false)
510
-				$className=substr($className,$pos+1);
509
+			if(($pos=strrpos($className, '.'))!==false)
510
+				$className=substr($className, $pos + 1);
511 511
 		}
512 512
 
513
- 		if($className!=='\Prado\Web\UI\TPage' && !is_subclass_of($className,'\Prado\Web\UI\TPage'))
514
-			throw new THttpException(404,'pageservice_page_unknown',$pagePath);
513
+ 		if($className!=='\Prado\Web\UI\TPage' && !is_subclass_of($className, '\Prado\Web\UI\TPage'))
514
+			throw new THttpException(404, 'pageservice_page_unknown', $pagePath);
515 515
 
516 516
 		$page=Prado::createComponent($className);
517 517
 		$page->setPagePath($pagePath);
@@ -527,10 +527,10 @@  discard block
 block discarded – undo
527 527
 	 * @param TPage the page instance to be run
528 528
 	 * @param array list of initial page properties
529 529
 	 */
530
-	protected function runPage($page,$properties)
530
+	protected function runPage($page, $properties)
531 531
 	{
532 532
 		foreach($properties as $name=>$value)
533
-			$page->setSubProperty($name,$value);
533
+			$page->setSubProperty($name, $value);
534 534
 		$page->run($this->getResponse()->createHtmlWriter());
535 535
 	}
536 536
 
@@ -542,8 +542,8 @@  discard block
 block discarded – undo
542 542
 	 * @param boolean whether to encode the GET parameters (their names and values), defaults to true.
543 543
 	 * @return string URL for the page and GET parameters
544 544
 	 */
545
-	public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true)
545
+	public function constructUrl($pagePath, $getParams=null, $encodeAmpersand=true, $encodeGetItems=true)
546 546
 	{
547
-		return $this->getRequest()->constructUrl($this->getID(),$pagePath,$getParams,$encodeAmpersand,$encodeGetItems);
547
+		return $this->getRequest()->constructUrl($this->getID(), $pagePath, $getParams, $encodeAmpersand, $encodeGetItems);
548 548
 	}
549 549
 }
550 550
\ No newline at end of file
Please login to merge, or discard this patch.