00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 2006-2008 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 00015 class SimplePhpView extends EmptyView 00016 { 00017 protected $templatePath = null; 00018 protected $partViewResolver = null; 00019 00020 public function __construct($templatePath, ViewResolver $partViewResolver) 00021 { 00022 $this->templatePath = $templatePath; 00023 $this->partViewResolver = $partViewResolver; 00024 } 00025 00029 public function render(/* Model */ $model = null) 00030 { 00031 Assert::isTrue($model === null || $model instanceof Model); 00032 00033 if ($model) 00034 extract($model->getList()); 00035 00036 $partViewer = new PartViewer($this->partViewResolver, $model); 00037 00038 $this->preRender(); 00039 00040 include $this->templatePath; 00041 00042 $this->postRender(); 00043 00044 return $this; 00045 } 00046 00047 public function toString($model = null) 00048 { 00049 ob_start(); 00050 $this->render($model); 00051 return ob_get_clean(); 00052 } 00053 00057 protected function preRender() 00058 { 00059 return $this; 00060 } 00061 00065 protected function postRender() 00066 { 00067 return $this; 00068 } 00069 } 00070 ?>