Created
April 30, 2015 07:33
-
-
Save madr/f94d26209cc01bbe824b to your computer and use it in GitHub Desktop.
view.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* view.php | |
* | |
* simple view class, template-based. | |
* @todo indent markup using tidy? | |
* | |
* $Rev$ | |
* $Author$ | |
* $Date$ | |
*/ | |
class view | |
{ | |
protected $hasLayout; | |
private $file; | |
public function __construct( $file_path ) { | |
if(!file_exists($file_path)) { | |
throw new Exception('file ' . $file_path . ' does not exist!', 666); | |
} else { | |
$this->file = $file_path; | |
} | |
} | |
/** | |
* Compile the view | |
* | |
* @return $HTMLSource the compiled view | |
*/ | |
public function compile($registry = false) { | |
if($registry === false){ | |
$registry =& registry::getInstance(); | |
} | |
$user =& user::getInstance(); | |
foreach($registry as $k=>$v){ | |
$$k = $v; | |
} | |
ob_start(); | |
require $this->file; | |
$body = ob_get_clean(); | |
(isset($contentType)) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); | |
$isFragment = isset($this->isFragment); | |
if(defined('LAYOUT') && !$isFragment){ | |
ob_start(); | |
require LAYOUT; | |
$body = ob_get_clean(); | |
} | |
return $body; | |
} | |
public function isFragment() { | |
$this->isFragment = true; | |
} | |
function __toString() { | |
return __CLASS__; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment