00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 2006-2007 by Anton E. Lebedevich * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License as * 00007 * published by the Free Software Foundation; either version 3 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 /* $Id: SimplePhpView.class.php 4687 2007-12-09 18:57:18Z voxus $ */ 00012 00016 class SimplePhpView implements View, Stringable 00017 { 00018 protected $templatePath = null; 00019 protected $partViewResolver = null; 00020 00021 public function __construct($templatePath, ViewResolver $partViewResolver) 00022 { 00023 $this->templatePath = $templatePath; 00024 $this->partViewResolver = $partViewResolver; 00025 } 00026 00027 public function render($model = null) 00028 { 00029 Assert::isTrue($model === null || $model instanceof Model); 00030 00031 if ($model) 00032 extract($model->getList()); 00033 00034 $partViewer = new PartViewer($this->partViewResolver, $model); 00035 00036 $this->preRender(); 00037 00038 include $this->templatePath; 00039 00040 $this->postRender(); 00041 } 00042 00043 public function toString($model = null) 00044 { 00045 ob_start(); 00046 $this->render($model); 00047 return ob_get_clean(); 00048 } 00049 00050 protected function preRender() 00051 { 00052 return $this; 00053 } 00054 00055 protected function postRender() 00056 { 00057 return $this; 00058 } 00059 } 00060 ?>