00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 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: MultiPrefixPhpViewResolver.class.php 4687 2007-12-09 18:57:18Z voxus $ */ 00012 00021 class MultiPrefixPhpViewResolver implements ViewResolver 00022 { 00023 private $prefixes = array(); 00024 private $postfix = EXT_TPL; 00025 private $viewClassName = 'SimplePhpView'; 00026 00030 public static function create() 00031 { 00032 return new self; 00033 } 00034 00038 public function addPrefix($prefix) 00039 { 00040 $this->prefixes[] = $prefix; 00041 return $this; 00042 } 00043 00044 public function getPrefixes() 00045 { 00046 return $this->prefixes; 00047 } 00048 00052 public function dropPrefixes() 00053 { 00054 $this->prefixes = array(); 00055 return $this; 00056 } 00057 00058 public function getPostfix() 00059 { 00060 return $this->postfix; 00061 } 00062 00066 public function setPostfix($postfix) 00067 { 00068 $this->postfix = $postfix; 00069 return $this; 00070 } 00071 00075 public function resolveViewName($viewName) 00076 { 00077 Assert::isFalse( 00078 ($this->prefixes === array()), 00079 'specify at least one prefix' 00080 ); 00081 00082 foreach ($this->prefixes as $prefix) { 00083 if (file_exists($prefix.$viewName.$this->postfix)) { 00084 return 00085 new $this->viewClassName( 00086 $prefix.$viewName.$this->postfix, 00087 $this 00088 ); 00089 } 00090 } 00091 00092 throw new WrongArgumentException( 00093 'can not resolve view: '.$viewName 00094 ); 00095 } 00096 00100 public function setViewClassName($viewClassName) 00101 { 00102 $this->viewClassName = $viewClassName; 00103 00104 return $this; 00105 } 00106 00107 public function getViewClassName() 00108 { 00109 return $this->viewClassName; 00110 } 00111 } 00112 ?>