-
Notifications
You must be signed in to change notification settings - Fork 0
/
tito.php
89 lines (67 loc) · 1.34 KB
/
tito.php
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
86
87
88
89
<?php
// Example tiny tool
// modify this to conform with your class-loading strategy:
use dface\tito\Tito;
include_once 'vendor/autoload.php';
class Param implements JsonSerializable
{
private string $val;
public function __construct(string $val)
{
$this->val = $val;
}
public static function deserialize($val) : self
{
return new static($val);
}
public function jsonSerialize()
{
return $this->val;
}
}
class Param2 implements JsonSerializable
{
private string $val;
public function __construct(string $val)
{
$this->val = $val;
}
public function jsonSerialize()
{
return $this->val;
}
}
// example service class
class Test
{
public function process($val)
{
return $val;
}
public function processObj(Param $val) : \Param
{
return $val;
}
public function processObj2(Param2 $val) : \Param2
{
return $val;
}
public function info()
{
return $_SERVER['argv'];
}
}
// kinda container
$container = [
'service1' => new Test(),
'service2' => new Test(),
];
// Initialize tito - pass in description and service-locator callback:
$tito = new Tito(
'X-system command line tool.',
static function ($service_name) use ($container) {
return $container[$service_name];
}
);
// ask tito to make the rest
$tito->call();