|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------------+ |
|
4
|
|
|
// | This file is part of the Agavi package. | |
|
5
|
|
|
// | Copyright (c) 2005-2010 the Agavi Project. | |
|
6
|
|
|
// | | |
|
7
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
|
8
|
|
|
// | file that was distributed with this source code. You can also view the | |
|
9
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
|
10
|
|
|
// | vi: set noexpandtab: | |
|
11
|
|
|
// | Local Variables: | |
|
12
|
|
|
// | indent-tabs-mode: t | |
|
13
|
|
|
// | End: | |
|
14
|
|
|
// +---------------------------------------------------------------------------+ |
|
15
|
|
|
|
|
16
|
|
|
require_once(__DIR__ . '/AgaviTask.php'); |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Resolves Agavi configuration directives and variables. |
|
20
|
|
|
* |
|
21
|
|
|
* @package agavi |
|
22
|
|
|
* @subpackage build |
|
23
|
|
|
* |
|
24
|
|
|
* @author Noah Fontes <[email protected]> |
|
25
|
|
|
* @copyright Authors |
|
26
|
|
|
* @copyright The Agavi Project |
|
27
|
|
|
* |
|
28
|
|
|
* @since 1.0.0 |
|
29
|
|
|
* |
|
30
|
|
|
* @version $Id$ |
|
31
|
|
|
*/ |
|
32
|
|
|
class ResolveconfigurationTask extends AgaviTask |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
protected $property; |
|
35
|
|
|
protected $string; |
|
36
|
|
|
protected $expandDirectives = true; |
|
37
|
|
|
protected $variables = array(); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Sets the property that this task will modify. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string The property to modify. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function setProperty($property) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->property = $property; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Sets the string that this task will read. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string The string to read. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setString($string) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->string = $string; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Sets whether directives should be expanded as well as variables. |
|
61
|
|
|
* |
|
62
|
|
|
* @param bool Whether to expand directives in the input string. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setExpandDirectives($expandDirectives) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->expandDirectives = StringHelper::booleanValue($expandDirectives); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Adds a new variable to this task. |
|
71
|
|
|
* |
|
72
|
|
|
* @return VariableType The new variable. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function createVariable() |
|
75
|
|
|
{ |
|
76
|
|
|
$variable = new VariableType(); |
|
77
|
|
|
$this->variables[] = $variable; |
|
78
|
|
|
return $variable; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Executes the task. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function main() |
|
85
|
|
|
{ |
|
86
|
|
|
if($this->property === null) { |
|
87
|
|
|
throw new \Agavi\Build\Exception\BuildException('The property attribute must be specified'); |
|
88
|
|
|
} |
|
89
|
|
|
if($this->string === null) { |
|
90
|
|
|
throw new \Agavi\Build\Exception\BuildException('The string attribute must be specified'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$this->tryLoadAgavi(); |
|
94
|
|
|
$this->tryBootstrapAgavi(); |
|
95
|
|
|
|
|
96
|
|
|
$assigns = array(); |
|
97
|
|
|
foreach($this->variables as $variable) { |
|
98
|
|
|
$assigns[$variable->getName()] = $variable->getValue(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$result = \Agavi\Util\Toolkit::expandVariables( |
|
102
|
|
|
$this->expandDirectives ? \Agavi\Util\Toolkit::expandDirectives($this->string) : $this->string, |
|
103
|
|
|
$assigns |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$this->project->setUserProperty($this->property, $result); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
?> |
|
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.