1 | <?php |
||
13 | class Application |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var Client |
||
18 | */ |
||
19 | private $client; |
||
20 | |||
21 | /** |
||
22 | * @param string $secret |
||
23 | */ |
||
24 | public function __construct($secret) |
||
32 | |||
33 | /** |
||
34 | * @param Closure $callback function (DateTime $date, array $parameters) |
||
35 | */ |
||
36 | public function onGetSlots(Closure $callback) |
||
37 | { |
||
38 | $this->client->registerMethod(new GetSlots($callback)); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param Closure $callback function (DateTime $startDateTime, DateTime $endDateTime, int $quantity, array $parameters) |
||
43 | */ |
||
44 | public function onCreateReservation(Closure $callback) |
||
48 | |||
49 | /** |
||
50 | * @param Closure $callback function (DateTime $startDateTime, DateTime $endDateTime, int $quantity, array $parameters) |
||
51 | */ |
||
52 | public function onCancelReservation(Closure $callback) |
||
56 | |||
57 | public function run() |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | private function getHttpBody() |
||
72 | |||
73 | /** |
||
74 | * @return string[] |
||
75 | */ |
||
76 | private function getHttpHeaders() |
||
94 | |||
95 | } |
||
96 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: