-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathPhpViewResolver.class.php
More file actions
104 lines (91 loc) · 2.47 KB
/
PhpViewResolver.class.php
File metadata and controls
104 lines (91 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/***************************************************************************
* Copyright (C) 2006-2007 by Anton E. Lebedevich *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
/**
* @ingroup Flow
**/
class PhpViewResolver implements ViewResolver
{
private $prefix = null;
private $postfix = null;
public function __construct($prefix = null, $postfix = null)
{
$this->prefix = $prefix;
$this->postfix = $postfix;
}
/**
* @return PhpViewResolver
**/
public static function create($prefix = null, $postfix = null)
{
return new self($prefix, $postfix);
}
/**
* @param $viewNameList string|string[]
* @return SimplePhpView
* @throws WrongArgumentException
**/
public function resolveViewName($viewNameList)
{
foreach ($this->getViewNameList($viewNameList) as $viewName) {
if ($this->isViewNameExists($viewName)) {
return new SimplePhpView(
$this->prefix.$viewName.$this->postfix,
$this
);
}
}
throw new WrongArgumentException(
'can not resolve views: '.implode($this->getViewNameList($viewNameList))
);
}
public function viewExists($viewNameList)
{
foreach ($this->getViewNameList($viewNameList) as $viewName) {
if ($this->isViewNameExists($viewName)) {
return true;
}
}
return false;
}
public function getPrefix()
{
return $this->prefix;
}
/**
* @return PhpViewResolver
**/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
return $this;
}
public function getPostfix()
{
return $this->postfix;
}
/**
* @return PhpViewResolver
**/
public function setPostfix($postfix)
{
$this->postfix = $postfix;
return $this;
}
private function isViewNameExists($viewName)
{
return is_readable($this->prefix.$viewName.$this->postfix);
}
private function getViewNameList($viewNameOrList)
{
return is_array($viewNameOrList) ? $viewNameOrList : [$viewNameOrList];
}
}
?>