|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------------+ |
|
4
|
|
|
// | This file is part of the Agavi package. | |
|
5
|
|
|
// | Copyright (c) 2005-2011 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
|
|
|
* Executes a target in the buildfile. |
|
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 ExecutetargetTask extends AgaviTask |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
protected $name = null; |
|
35
|
|
|
protected $exceptionsFatal = true; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Sets the name of the target to call. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string The name of the target. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setName($name) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->name = $name; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Sets whether exceptions are fatal for targets called by this task. |
|
49
|
|
|
* |
|
50
|
|
|
* @param bool Whether exceptions should be considered fatal. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setExceptionsFatal($exceptionsFatal) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->exceptionsFatal = StringHelper::booleanValue($exceptionsFatal); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Executes this target. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function main() |
|
61
|
|
|
{ |
|
62
|
|
|
if($this->name === null) { |
|
63
|
|
|
throw new \Agavi\Build\Exception\BuildException('The name attribute must be specified'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/* Words cannot describe how ridiculously fucking stupid this is. Phing |
|
67
|
|
|
* seems to resolve properties only once, ever, so in order to run a |
|
68
|
|
|
* target multiple times with different properties we'll have to create |
|
69
|
|
|
* a new project, parse the build file all over again, copy everything |
|
70
|
|
|
* over from the current project, execute the new target, and then copy |
|
71
|
|
|
* everything back. Fuck. */ |
|
72
|
|
|
$project = new Project(); |
|
73
|
|
|
|
|
74
|
|
|
try { |
|
75
|
|
|
foreach($this->project->getBuildListeners() as $listener) { |
|
76
|
|
|
$project->addBuildListener($listener); |
|
77
|
|
|
} |
|
78
|
|
|
$project->setInputHandler($this->project->getInputHandler()); |
|
79
|
|
|
|
|
80
|
|
|
$this->project->copyUserProperties($project); |
|
81
|
|
|
$this->project->copyInheritedProperties($project); |
|
82
|
|
View Code Duplication |
foreach($this->project->getProperties() as $name => $property) { |
|
|
|
|
|
|
83
|
|
|
if($project->getProperty($name) === null) { |
|
84
|
|
|
$project->setNewProperty($name, $property); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$project->init(); |
|
89
|
|
|
ProjectConfigurator::configureProject($project, new PhingFile($this->project->getProperty('phing.file'))); |
|
90
|
|
|
|
|
91
|
|
|
Phing::setCurrentProject($project); |
|
92
|
|
|
|
|
93
|
|
|
$project->executeTarget($this->name); |
|
94
|
|
|
} |
|
95
|
|
|
catch(BuildException $be) { |
|
96
|
|
|
if($this->exceptionsFatal) { |
|
97
|
|
|
throw $be; |
|
98
|
|
|
} else { |
|
99
|
|
|
$this->log('Ignoring build exception: ' . $be->getMessage(), Project::MSG_WARN); |
|
100
|
|
|
$this->log('Continuing build', Project::MSG_INFO); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
Phing::setCurrentProject($this->project); |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* :NOTE: copy all user properties so that child task may overwrite |
|
108
|
|
|
* properties that were already set in the parent project |
|
109
|
|
|
* |
|
110
|
|
|
* using the Project::copyUserProperties() will result in |
|
111
|
|
|
* properties not adjusted to the new value. |
|
112
|
|
|
*/ |
|
113
|
|
|
foreach($project->getUserProperties() as $name => $property) { |
|
114
|
|
|
$this->project->setUserProperty($name, $property); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$project->copyInheritedProperties($this->project); |
|
118
|
|
View Code Duplication |
foreach($project->getProperties() as $name => $property) { |
|
|
|
|
|
|
119
|
|
|
if($this->project->getProperty($name) === null) { |
|
120
|
|
|
$this->project->setNewProperty($name, $property); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/* Fuck. */ |
|
125
|
|
|
unset($project); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
?> |
|
|
|
|
|
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.