Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
Common.php
Go to the documentation of this file.
1
<?php
16
20
require_once
'PEAR.php'
;
21
35
class
PEAR_Command_Common
extends
PEAR
36
{
43
var
$config
;
48
var
$_registry
;
49
54
var
$ui
;
55
56
var
$_deps_rel_trans
= array(
57
'lt'
=>
'<'
,
58
'le'
=>
'<='
,
59
'eq'
=>
'='
,
60
'ne'
=>
'!='
,
61
'gt'
=>
'>'
,
62
'ge'
=>
'>='
,
63
'has'
=>
'=='
64
);
65
66
var
$_deps_type_trans
= array(
67
'pkg'
=>
'package'
,
68
'ext'
=>
'extension'
,
69
'php'
=>
'PHP'
,
70
'prog'
=>
'external program'
,
71
'ldlib'
=>
'external library for linking'
,
72
'rtlib'
=>
'external runtime library'
,
73
'os'
=>
'operating system'
,
74
'websrv'
=>
'web server'
,
75
'sapi'
=>
'SAPI backend'
76
);
77
83
function
__construct
(&
$ui
, &
$config
)
84
{
85
parent::__construct();
86
$this->config = &
$config
;
87
$this->ui = &
$ui
;
88
}
89
95
function
getCommands
()
96
{
97
$ret = array();
98
foreach
(array_keys($this->commands) as
$command
) {
99
$ret[
$command
] = $this->commands[
$command
][
'summary'
];
100
}
101
102
return
$ret;
103
}
104
110
function
getShortcuts
()
111
{
112
$ret = array();
113
foreach
(array_keys($this->commands) as
$command
) {
114
if
(isset($this->commands[
$command
][
'shortcut'
])) {
115
$ret[$this->commands[
$command
][
'shortcut'
]] =
$command
;
116
}
117
}
118
119
return
$ret;
120
}
121
122
function
getOptions
(
$command
)
123
{
124
$shortcuts = $this->
getShortcuts
();
125
if
(isset($shortcuts[
$command
])) {
126
$command
= $shortcuts[
$command
];
127
}
128
129
if
(isset($this->commands[
$command
]) &&
130
isset($this->commands[
$command
][
'options'
])) {
131
return
$this->commands[
$command
][
'options'
];
132
}
133
134
return
null
;
135
}
136
137
function
getGetoptArgs
(
$command
, &$short_args, &$long_args)
138
{
139
$short_args =
''
;
140
$long_args = array();
141
if
(empty($this->commands[
$command
]) || empty($this->commands[
$command
][
'options'
])) {
142
return
;
143
}
144
145
reset($this->commands[
$command
][
'options'
]);
146
foreach
($this->commands[
$command
][
'options'
] as $option => $info) {
147
$larg = $sarg =
''
;
148
if
(isset($info[
'arg'
])) {
149
if
($info[
'arg'
][0] ==
'('
) {
150
$larg =
'=='
;
151
$sarg =
'::'
;
152
$arg = substr($info[
'arg'
], 1, -1);
153
}
else
{
154
$larg =
'='
;
155
$sarg =
':'
;
156
$arg = $info[
'arg'
];
157
}
158
}
159
160
if
(isset($info[
'shortopt'
])) {
161
$short_args .= $info[
'shortopt'
] . $sarg;
162
}
163
164
$long_args[] = $option . $larg;
165
}
166
}
167
176
function
getHelp
(
$command
)
177
{
178
$config
= &PEAR_Config::singleton();
179
if
(!isset($this->commands[
$command
])) {
180
return
"No such command \"$command\""
;
181
}
182
183
$help =
null
;
184
if
(isset($this->commands[
$command
][
'doc'
])) {
185
$help = $this->commands[
$command
][
'doc'
];
186
}
187
188
if
(empty($help)) {
189
// XXX (cox) Fallback to summary if there is no doc (show both?)
190
if
(!isset($this->commands[
$command
][
'summary'
])) {
191
return
"No help for command \"$command\""
;
192
}
193
$help = $this->commands[
$command
][
'summary'
];
194
}
195
196
if
(preg_match_all(
'/{config\s+([^\}]+)}/'
, $help, $matches)) {
197
foreach
($matches[0] as $k => $v) {
198
$help = preg_replace(
"/$v/"
,
$config
->get($matches[1][$k]), $help);
199
}
200
}
201
202
return
array($help, $this->
getHelpArgs
($command));
203
}
204
211
function
getHelpArgs
(
$command
)
212
{
213
if
(isset($this->commands[
$command
][
'options'
]) &&
214
count($this->commands[
$command
][
'options'
]))
215
{
216
$help =
"Options:\n"
;
217
foreach
($this->commands[
$command
][
'options'
] as $k => $v) {
218
if
(isset($v[
'arg'
])) {
219
if
($v[
'arg'
][0] ==
'('
) {
220
$arg = substr($v[
'arg'
], 1, -1);
221
$sapp =
" [$arg]"
;
222
$lapp =
"[=$arg]"
;
223
}
else
{
224
$sapp =
" $v[arg]"
;
225
$lapp =
"=$v[arg]"
;
226
}
227
}
else
{
228
$sapp = $lapp =
""
;
229
}
230
231
if
(isset($v[
'shortopt'
])) {
232
$s = $v[
'shortopt'
];
233
$help .=
" -$s$sapp, --$k$lapp\n"
;
234
}
else
{
235
$help .=
" --$k$lapp\n"
;
236
}
237
238
$p =
" "
;
239
$doc = rtrim(str_replace(
"\n"
,
"\n$p"
, $v[
'doc'
]));
240
$help .=
" $doc\n"
;
241
}
242
243
return
$help;
244
}
245
246
return
null
;
247
}
248
249
function
run
(
$command
,
$options
, $params)
250
{
251
if
(empty($this->commands[
$command
][
'function'
])) {
252
// look for shortcuts
253
foreach
(array_keys($this->commands) as $cmd) {
254
if
(isset($this->commands[$cmd][
'shortcut'
]) && $this->commands[$cmd][
'shortcut'
] ==
$command
) {
255
if
(empty($this->commands[$cmd][
'function'
])) {
256
return
$this->raiseError(
"unknown command `$command'"
);
257
}
else
{
258
$func = $this->commands[$cmd][
'function'
];
259
}
260
$command
= $cmd;
261
262
//$command = $this->commands[$cmd]['function'];
263
break
;
264
}
265
}
266
}
else
{
267
$func = $this->commands[
$command
][
'function'
];
268
}
269
270
return
$this->$func(
$command
,
$options
, $params);
271
}
272
}
PEAR_Command_Common
Definition
Common.php:36
PEAR_Command_Common\getGetoptArgs
getGetoptArgs($command, &$short_args, &$long_args)
Definition
Common.php:137
PEAR_Command_Common\getShortcuts
getShortcuts()
Definition
Common.php:110
PEAR_Command_Common\__construct
__construct(&$ui, &$config)
Definition
Common.php:83
PEAR_Command_Common\$config
$config
Definition
Common.php:43
PEAR_Command_Common\run
run($command, $options, $params)
Definition
Common.php:249
PEAR_Command_Common\$ui
$ui
Definition
Common.php:54
PEAR_Command_Common\getCommands
getCommands()
Definition
Common.php:95
PEAR_Command_Common\getOptions
getOptions($command)
Definition
Common.php:122
PEAR_Command_Common\$_deps_type_trans
$_deps_type_trans
Definition
Common.php:66
PEAR_Command_Common\getHelpArgs
getHelpArgs($command)
Definition
Common.php:211
PEAR_Command_Common\$_deps_rel_trans
$_deps_rel_trans
Definition
Common.php:56
PEAR_Command_Common\$_registry
$_registry
Definition
Common.php:48
PEAR_Command_Common\getHelp
getHelp($command)
Definition
Common.php:176
PEAR
$options
$options
Definition
pearcmd.php:145
$command
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition
pearcmd.php:322
sandbox
core
libs
php
pear
pear
PEAR
Command
Common.php
Generated by
1.17.0