-
Notifications
You must be signed in to change notification settings - Fork 0
/
pboy
executable file
·86 lines (58 loc) · 1.77 KB
/
pboy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/php
<?php
/* ____ Include autoloads ________________________________
Composer's autoload first, then our built-in
*/
require 'vendor/autoload.php';
/* ____ Init Config ______________________________________
Class has to be hard coded since Loader needs a Config
object to do its job.
This also means than Config object, at least when loaded
from here, has no dependencies managed.
*/
$Config = new Pboy\Config\Ini;
/* ____ Init Loader ______________________________________
As for Config, class is hard coded here.
Dependencies are self managed but Config is hard-loaded
*/
$Loader = new Pboy\Loader\Loader(
array('Config' => $Config)
);
/* ____ Init more needed classes ________________________
$Io to say something
$Task to do something
*/
$Io = $Loader->getService('Io');
$Task = $Loader->getService('Task');
/* ____ Execution ________________________________________
*/
try {
$task = $Io->getTask();
if (!$task) {
throw new \BadMethodCallException();
}
$options = $Io->getOptions($task);
$status = $Task->execute($task, $options);
if ($status === true) {
$Io->write('Done');
} else {
$Io->write($status);
}
// Error with options
} catch (\UnexpectedValueException $e) {
$Io->write($e->getMessage());
$Io->write($Io->help($task));
// Error with task name
} catch (\InvalidArgumentException $e) {
$Io->write($e->getMessage());
// No task
} catch (\BadMethodCallException $e) {
$Io->write($Task->execute('help'));
// Others
} catch (\Exception $e) {
$Io->write($e->getMessage());
if (isset($options['verbose'])) {
$Io->write('Debug information:');
$Io->write($e->getMessage());
}
}