Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
Command.php
Go to the documentation of this file.
1
<?php
16
20
require_once
'PEAR.php'
;
21
require_once
'PEAR/Frontend.php'
;
22
require_once
'PEAR/XMLParser.php'
;
23
28
$GLOBALS
[
'_PEAR_Command_commandlist'
] = array();
29
34
$GLOBALS
[
'_PEAR_Command_commanddesc'
] = array();
35
40
$GLOBALS
[
'_PEAR_Command_shortcuts'
] = array();
41
46
$GLOBALS
[
'_PEAR_Command_objects'
] = array();
47
100
class
PEAR_Command
101
{
102
// {{{ factory()
103
112
public
static
function
&
factory
(
$command
, &
$config
)
113
{
114
if
(empty(
$GLOBALS
[
'_PEAR_Command_commandlist'
])) {
115
PEAR_Command::registerCommands
();
116
}
117
if
(isset(
$GLOBALS
[
'_PEAR_Command_shortcuts'
][
$command
])) {
118
$command
=
$GLOBALS
[
'_PEAR_Command_shortcuts'
][
$command
];
119
}
120
if
(!isset(
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
])) {
121
$a = PEAR::raiseError(
"unknown command `$command'"
);
122
return
$a;
123
}
124
$class =
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
];
125
if
(!class_exists($class)) {
126
require_once
$GLOBALS
[
'_PEAR_Command_objects'
][$class];
127
}
128
if
(!class_exists($class)) {
129
$a = PEAR::raiseError(
"unknown command `$command'"
);
130
return
$a;
131
}
132
$ui
=&
PEAR_Command::getFrontendObject
();
133
$obj =
new
$class(
$ui
,
$config
);
134
return
$obj;
135
}
136
137
// }}}
138
// {{{ & getObject()
139
public
static
function
&
getObject
(
$command
)
140
{
141
$class =
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
];
142
if
(!class_exists($class)) {
143
require_once
$GLOBALS
[
'_PEAR_Command_objects'
][$class];
144
}
145
if
(!class_exists($class)) {
146
return
PEAR::raiseError(
"unknown command `$command'"
);
147
}
148
$ui
=&
PEAR_Command::getFrontendObject
();
149
$config
= &PEAR_Config::singleton();
150
$obj =
new
$class(
$ui
,
$config
);
151
return
$obj;
152
}
153
154
// }}}
155
// {{{ & getFrontendObject()
156
162
public
static
function
&
getFrontendObject
()
163
{
164
$a = &
PEAR_Frontend::singleton
();
165
return
$a;
166
}
167
168
// }}}
169
// {{{ & setFrontendClass()
170
178
public
static
function
&
setFrontendClass
($uiclass)
179
{
180
$a = &
PEAR_Frontend::setFrontendClass
($uiclass);
181
return
$a;
182
}
183
184
// }}}
185
// {{{ setFrontendType()
186
194
public
static
function
setFrontendType
($uitype)
195
{
196
$uiclass =
'PEAR_Frontend_'
. $uitype;
197
return
PEAR_Command::setFrontendClass
($uiclass);
198
}
199
200
// }}}
201
// {{{ registerCommands()
202
218
public
static
function
registerCommands
($merge =
false
, $dir =
null
)
219
{
220
$parser =
new
PEAR_XMLParser
;
221
if
($dir ===
null
) {
222
$dir = dirname(__FILE__) .
'/Command'
;
223
}
224
if
(!is_dir($dir)) {
225
return
PEAR::raiseError(
"registerCommands: opendir($dir) '$dir' does not exist or is not a directory"
);
226
}
227
$dp = @opendir($dir);
228
if
(empty($dp)) {
229
return
PEAR::raiseError(
"registerCommands: opendir($dir) failed"
);
230
}
231
if
(!$merge) {
232
$GLOBALS
[
'_PEAR_Command_commandlist'
] = array();
233
}
234
235
while
($file = readdir($dp)) {
236
if
($file[0] ==
'.'
|| substr($file, -4) !=
'.xml'
) {
237
continue
;
238
}
239
240
$f = substr($file, 0, -4);
241
$class =
"PEAR_Command_"
. $f;
242
// List of commands
243
if
(empty(
$GLOBALS
[
'_PEAR_Command_objects'
][$class])) {
244
$GLOBALS
[
'_PEAR_Command_objects'
][$class] =
"$dir/"
. $f .
'.php'
;
245
}
246
247
$parser->parse(file_get_contents(
"$dir/$file"
));
248
$implements = $parser->getData();
249
foreach
($implements as
$command
=> $desc) {
250
if
(
$command
==
'attribs'
) {
251
continue
;
252
}
253
254
if
(isset(
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
])) {
255
return
PEAR::raiseError(
'Command "'
.
$command
.
'" already registered in '
.
256
'class "'
.
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
] .
'"'
);
257
}
258
259
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
] = $class;
260
$GLOBALS
[
'_PEAR_Command_commanddesc'
][
$command
] = $desc[
'summary'
];
261
if
(isset($desc[
'shortcut'
])) {
262
$shortcut = $desc[
'shortcut'
];
263
if
(isset(
$GLOBALS
[
'_PEAR_Command_shortcuts'
][$shortcut])) {
264
return
PEAR::raiseError(
'Command shortcut "'
. $shortcut .
'" already '
.
265
'registered to command "'
.
$command
.
'" in class "'
.
266
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
] .
'"'
);
267
}
268
$GLOBALS
[
'_PEAR_Command_shortcuts'
][$shortcut] =
$command
;
269
}
270
271
if
(isset($desc[
'options'
]) && $desc[
'options'
]) {
272
foreach
($desc[
'options'
] as $oname => $option) {
273
if
(isset($option[
'shortopt'
]) && strlen($option[
'shortopt'
]) > 1) {
274
return
PEAR::raiseError(
'Option "'
. $oname .
'" short option "'
.
275
$option[
'shortopt'
] .
'" must be '
.
276
'only 1 character in Command "'
.
$command
.
'" in class "'
.
277
$class .
'"'
);
278
}
279
}
280
}
281
}
282
}
283
284
ksort(
$GLOBALS
[
'_PEAR_Command_shortcuts'
]);
285
ksort(
$GLOBALS
[
'_PEAR_Command_commandlist'
]);
286
@closedir($dp);
287
return
true
;
288
}
289
290
// }}}
291
// {{{ getCommands()
292
299
public
static
function
getCommands
()
300
{
301
if
(empty(
$GLOBALS
[
'_PEAR_Command_commandlist'
])) {
302
PEAR_Command::registerCommands
();
303
}
304
return
$GLOBALS
[
'_PEAR_Command_commandlist'
];
305
}
306
307
// }}}
308
// {{{ getShortcuts()
309
315
public
static
function
getShortcuts
()
316
{
317
if
(empty(
$GLOBALS
[
'_PEAR_Command_shortcuts'
])) {
318
PEAR_Command::registerCommands
();
319
}
320
return
$GLOBALS
[
'_PEAR_Command_shortcuts'
];
321
}
322
323
// }}}
324
// {{{ getGetoptArgs()
325
335
public
static
function
getGetoptArgs
(
$command
, &$short_args, &$long_args)
336
{
337
if
(empty(
$GLOBALS
[
'_PEAR_Command_commandlist'
])) {
338
PEAR_Command::registerCommands
();
339
}
340
if
(isset(
$GLOBALS
[
'_PEAR_Command_shortcuts'
][
$command
])) {
341
$command
=
$GLOBALS
[
'_PEAR_Command_shortcuts'
][
$command
];
342
}
343
if
(!isset(
$GLOBALS
[
'_PEAR_Command_commandlist'
][
$command
])) {
344
return
null
;
345
}
346
$obj = &
PEAR_Command::getObject
(
$command
);
347
return
$obj->getGetoptArgs(
$command
, $short_args, $long_args);
348
}
349
350
// }}}
351
// {{{ getDescription()
352
360
public
static
function
getDescription
(
$command
)
361
{
362
if
(!isset(
$GLOBALS
[
'_PEAR_Command_commanddesc'
][
$command
])) {
363
return
null
;
364
}
365
return
$GLOBALS
[
'_PEAR_Command_commanddesc'
][
$command
];
366
}
367
368
// }}}
369
// {{{ getHelp()
370
376
public
static
function
getHelp
(
$command
)
377
{
378
$cmds =
PEAR_Command::getCommands
();
379
if
(isset(
$GLOBALS
[
'_PEAR_Command_shortcuts'
][
$command
])) {
380
$command
=
$GLOBALS
[
'_PEAR_Command_shortcuts'
][
$command
];
381
}
382
if
(isset($cmds[
$command
])) {
383
$obj = &
PEAR_Command::getObject
(
$command
);
384
return
$obj->getHelp(
$command
);
385
}
386
return
false
;
387
}
388
// }}}
389
}
$GLOBALS
$GLOBALS['_PEAR_Command_commandlist']
Definition
Command.php:28
$GLOBALS
$GLOBALS['_PEAR_default_error_mode']
Definition
PEAR.php:46
PEAR_Command
Definition
Command.php:101
PEAR_Command\getObject
static & getObject($command)
Definition
Command.php:139
PEAR_Command\getGetoptArgs
static getGetoptArgs($command, &$short_args, &$long_args)
Definition
Command.php:335
PEAR_Command\registerCommands
static registerCommands($merge=false, $dir=null)
Definition
Command.php:218
PEAR_Command\getShortcuts
static getShortcuts()
Definition
Command.php:315
PEAR_Command\factory
static & factory($command, &$config)
Definition
Command.php:112
PEAR_Command\getCommands
static getCommands()
Definition
Command.php:299
PEAR_Command\getFrontendObject
static & getFrontendObject()
Definition
Command.php:162
PEAR_Command\setFrontendClass
static & setFrontendClass($uiclass)
Definition
Command.php:178
PEAR_Command\getHelp
static getHelp($command)
Definition
Command.php:376
PEAR_Command\setFrontendType
static setFrontendType($uitype)
Definition
Command.php:194
PEAR_Command\getDescription
static getDescription($command)
Definition
Command.php:360
PEAR_Frontend\setFrontendClass
static & setFrontendClass($uiclass)
Definition
Frontend.php:73
PEAR_Frontend\singleton
static & singleton($type=null)
Definition
Frontend.php:51
PEAR_XMLParser
Definition
XMLParser.php:30
$config
$config
Definition
pearcmd.php:182
$ui
$ui
Definition
pearcmd.php:181
$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.php
Generated by
1.17.0