1
|
|
|
<?php |
2
|
|
|
namespace Agavi\View; |
3
|
|
|
|
4
|
|
|
// +---------------------------------------------------------------------------+ |
5
|
|
|
// | This file is part of the Agavi package. | |
6
|
|
|
// | Copyright (c) 2005-2011 the Agavi Project. | |
7
|
|
|
// | | |
8
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
9
|
|
|
// | file that was distributed with this source code. You can also view the | |
10
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
11
|
|
|
// | vi: set noexpandtab: | |
12
|
|
|
// | Local Variables: | |
13
|
|
|
// | indent-tabs-mode: t | |
14
|
|
|
// | End: | |
15
|
|
|
// +---------------------------------------------------------------------------+ |
16
|
|
|
use Agavi\Config\Config; |
17
|
|
|
use Agavi\Core\Context; |
18
|
|
|
use Agavi\Exception\AgaviException; |
19
|
|
|
use Agavi\Util\Toolkit; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Template layer implementation for templates fetched using a PHP stream. |
23
|
|
|
* |
24
|
|
|
* @package agavi |
25
|
|
|
* @subpackage view |
26
|
|
|
* |
27
|
|
|
* @author David Zülke <[email protected]> |
28
|
|
|
* @copyright Authors |
29
|
|
|
* @copyright The Agavi Project |
30
|
|
|
* |
31
|
|
|
* @since 0.11.0 |
32
|
|
|
* |
33
|
|
|
* @version $Id$ |
34
|
|
|
*/ |
35
|
|
|
class FileTemplateLayer extends StreamTemplateLayer |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* Constructor. |
39
|
|
|
* |
40
|
|
|
* @param array $parameters Initial parameters. |
41
|
|
|
* |
42
|
|
|
* @author David Zülke <[email protected]> |
43
|
|
|
* @since 0.11.0 |
44
|
|
|
*/ |
45
|
|
|
public function __construct(array $parameters = array()) |
46
|
|
|
{ |
47
|
|
|
$targets = array(); |
48
|
|
|
if (Config::get('core.use_translation')) { |
49
|
|
|
$targets[] = '${directory}/${locale}/${template}${extension}'; |
50
|
|
|
$targets[] = '${directory}/${template}.${locale}${extension}'; |
51
|
|
|
} |
52
|
|
|
$targets[] = '${directory}/${template}${extension}'; |
53
|
|
|
|
54
|
|
|
parent::__construct(array_merge(array( |
55
|
|
|
'directory' => Config::get('core.module_dir') . '/${module}/templates', |
56
|
|
|
'scheme' => 'file', |
57
|
|
|
'check' => true, |
58
|
|
|
'targets' => $targets, |
59
|
|
|
), $parameters)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initialize the layer. |
64
|
|
|
* |
65
|
|
|
* Will try and figure out an alternative default for "directory". |
66
|
|
|
* |
67
|
|
|
* @param Context The current Context instance. |
68
|
|
|
* @param array An array of initialization parameters. |
69
|
|
|
* |
70
|
|
|
* @author David Zülke <[email protected]> |
71
|
|
|
* @since 1.0.0 |
72
|
|
|
*/ |
73
|
|
|
public function initialize(Context $context, array $parameters = array()) |
74
|
|
|
{ |
75
|
|
|
$this->setParameter('directory', Toolkit::evaluateModuleDirective(isset($parameters['module']) ? $parameters['module'] : '', 'agavi.template.directory')); |
76
|
|
|
|
77
|
|
|
parent::initialize($context, $parameters); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the full, resolved stream location name to the template resource. |
82
|
|
|
* |
83
|
|
|
* @return string A PHP stream resource identifier. |
84
|
|
|
* |
85
|
|
|
* @throws AgaviException If the template could not be found. |
86
|
|
|
* |
87
|
|
|
* @author David Zülke <[email protected]> |
88
|
|
|
* @since 0.11.0 |
89
|
|
|
*/ |
90
|
|
|
public function getResourceStreamIdentifier() |
91
|
|
|
{ |
92
|
|
|
$retval = null; |
|
|
|
|
93
|
|
|
$template = $this->getParameter('template'); |
94
|
|
|
|
95
|
|
|
if ($template === null) { |
96
|
|
|
// no template set, we return null so nothing gets rendered |
97
|
|
|
return null; |
98
|
|
|
} elseif (Toolkit::isPathAbsolute($template)) { |
99
|
|
|
// the template is an absolute path, ignore the dir |
100
|
|
|
$directory = dirname($template); |
101
|
|
|
$template = basename($template); |
102
|
|
|
} else { |
103
|
|
|
$directory = $this->getParameter('directory'); |
104
|
|
|
} |
105
|
|
|
// treat the directory as sprintf format string and inject module name |
106
|
|
|
$directory = Toolkit::expandVariables($directory, array_merge(array_filter($this->getParameters(), 'is_scalar'), array_filter($this->getParameters(), 'is_null'))); |
107
|
|
|
|
108
|
|
|
$this->setParameter('directory', $directory); |
109
|
|
|
$this->setParameter('template', $template); |
110
|
|
|
if (!$this->hasParameter('extension')) { |
111
|
|
|
$this->setParameter('extension', $this->renderer->getDefaultExtension()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// everything set up for the parent |
115
|
|
|
return parent::getResourceStreamIdentifier(); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.