Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
Replace.php
Go to the documentation of this file.
1
<?php
18
require_once
'PEAR/Task/Common.php'
;
30
class
PEAR_Task_Replace
extends
PEAR_Task_Common
31
{
32
public
$type
=
'simple'
;
33
public
$phase
=
PEAR_TASK_PACKAGEANDINSTALL
;
34
public
$_replacements
;
35
43
public
static
function
validateXml
($pkg, $xml,
$config
, $fileXml)
44
{
45
if
(!isset($xml[
'attribs'
])) {
46
return
array(
PEAR_TASK_ERROR_NOATTRIBS
);
47
}
48
if
(!isset($xml[
'attribs'
][
'type'
])) {
49
return
array(
PEAR_TASK_ERROR_MISSING_ATTRIB
,
'type'
);
50
}
51
if
(!isset($xml[
'attribs'
][
'to'
])) {
52
return
array(
PEAR_TASK_ERROR_MISSING_ATTRIB
,
'to'
);
53
}
54
if
(!isset($xml[
'attribs'
][
'from'
])) {
55
return
array(
PEAR_TASK_ERROR_MISSING_ATTRIB
,
'from'
);
56
}
57
if
($xml[
'attribs'
][
'type'
] ==
'pear-config'
) {
58
if
(!in_array($xml[
'attribs'
][
'to'
],
$config
->getKeys())) {
59
return
array(
PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE
,
'to'
, $xml[
'attribs'
][
'to'
],
60
$config
->getKeys(), );
61
}
62
} elseif ($xml[
'attribs'
][
'type'
] ==
'php-const'
) {
63
if
(defined($xml[
'attribs'
][
'to'
])) {
64
return
true
;
65
}
else
{
66
return
array(
PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE
,
'to'
, $xml[
'attribs'
][
'to'
],
67
array(
'valid PHP constant'
), );
68
}
69
} elseif ($xml[
'attribs'
][
'type'
] ==
'package-info'
) {
70
if
(in_array(
71
$xml[
'attribs'
][
'to'
],
72
array(
'name'
,
'summary'
,
'channel'
,
'notes'
,
'extends'
,
'description'
,
73
'release_notes'
,
'license'
,
'release-license'
,
'license-uri'
,
74
'version'
,
'api-version'
,
'state'
,
'api-state'
,
'release_date'
,
75
'date'
,
'time'
, )
76
)) {
77
return
true
;
78
}
else
{
79
return
array(
PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE
,
'to'
, $xml[
'attribs'
][
'to'
],
80
array(
'name'
,
'summary'
,
'channel'
,
'notes'
,
'extends'
,
'description'
,
81
'release_notes'
,
'license'
,
'release-license'
,
'license-uri'
,
82
'version'
,
'api-version'
,
'state'
,
'api-state'
,
'release_date'
,
83
'date'
,
'time'
, ), );
84
}
85
}
else
{
86
return
array(
PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE
,
'type'
, $xml[
'attribs'
][
'type'
],
87
array(
'pear-config'
,
'package-info'
,
'php-const'
), );
88
}
89
90
return
true
;
91
}
92
99
public
function
init
($xml, $attribs, $lastVersion =
null
)
100
{
101
$this->_replacements = isset($xml[
'attribs'
]) ? array($xml) : $xml;
102
}
103
115
public
function
startSession
($pkg, $contents, $dest)
116
{
117
$subst_from = $subst_to = array();
118
foreach
($this->_replacements as $a) {
119
$a = $a[
'attribs'
];
120
$to =
''
;
121
if
($a[
'type'
] ==
'pear-config'
) {
122
if
($this->installphase ==
PEAR_TASK_PACKAGE
) {
123
return
false
;
124
}
125
if
($a[
'to'
] ==
'master_server'
) {
126
$chan = $this->registry->getChannel($pkg->getChannel());
127
if
(!PEAR::isError($chan)) {
128
$to = $chan->getServer();
129
}
else
{
130
$this->logger->log(0,
"$dest: invalid pear-config replacement: $a[to]"
);
131
132
return
false
;
133
}
134
}
else
{
135
if
($this->config->isDefinedLayer(
'ftp'
)) {
136
// try the remote config file first
137
$to = $this->config->get($a[
'to'
],
'ftp'
, $pkg->getChannel());
138
if
(is_null($to)) {
139
// then default to local
140
$to = $this->config->get($a[
'to'
],
null
, $pkg->getChannel());
141
}
142
}
else
{
143
$to = $this->config->get($a[
'to'
],
null
, $pkg->getChannel());
144
}
145
}
146
if
(is_null($to)) {
147
$this->logger->log(0,
"$dest: invalid pear-config replacement: $a[to]"
);
148
149
return
false
;
150
}
151
} elseif ($a[
'type'
] ==
'php-const'
) {
152
if
($this->installphase ==
PEAR_TASK_PACKAGE
) {
153
return
false
;
154
}
155
if
(defined($a[
'to'
])) {
156
$to = constant($a[
'to'
]);
157
}
else
{
158
$this->logger->log(0,
"$dest: invalid php-const replacement: $a[to]"
);
159
160
return
false
;
161
}
162
}
else
{
163
if
($t = $pkg->packageInfo($a[
'to'
])) {
164
$to = $t;
165
}
else
{
166
$this->logger->log(0,
"$dest: invalid package-info replacement: $a[to]"
);
167
168
return
false
;
169
}
170
}
171
if
(!is_null($to)) {
172
$subst_from[] = $a[
'from'
];
173
$subst_to[] = $to;
174
}
175
}
176
$this->logger->log(
177
3,
"doing "
.
sizeof
($subst_from).
178
" substitution(s) for $dest"
179
);
180
if
(
sizeof
($subst_from)) {
181
$contents = str_replace($subst_from, $subst_to, $contents);
182
}
183
184
return
$contents;
185
}
186
}
PEAR_TASK_ERROR_NOATTRIBS
const PEAR_TASK_ERROR_NOATTRIBS
Definition
Common.php:18
PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE
const PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE
Definition
Common.php:20
PEAR_TASK_PACKAGEANDINSTALL
const PEAR_TASK_PACKAGEANDINSTALL
Definition
Common.php:25
PEAR_TASK_PACKAGE
const PEAR_TASK_PACKAGE
Definition
Common.php:23
PEAR_TASK_ERROR_MISSING_ATTRIB
const PEAR_TASK_ERROR_MISSING_ATTRIB
Definition
Common.php:19
PEAR_Task_Common
Definition
Common.php:56
PEAR_Task_Common\$config
$config
Definition
Common.php:76
PEAR_Task_Replace
Definition
Replace.php:31
PEAR_Task_Replace\init
init($xml, $attribs, $lastVersion=null)
Definition
Replace.php:99
PEAR_Task_Replace\startSession
startSession($pkg, $contents, $dest)
Definition
Replace.php:115
PEAR_Task_Replace\$type
$type
Definition
Replace.php:32
PEAR_Task_Replace\$phase
$phase
Definition
Replace.php:33
PEAR_Task_Replace\validateXml
static validateXml($pkg, $xml, $config, $fileXml)
Definition
Replace.php:43
PEAR_Task_Replace\$_replacements
$_replacements
Definition
Replace.php:34
sandbox
core
libs
php
pear
pear
PEAR
Task
Replace.php
Generated by
1.17.0