|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Raidros\Storer; |
|
4
|
|
|
|
|
5
|
|
|
use Raidros\Collection\Collection; |
|
6
|
|
|
|
|
7
|
|
|
class Api |
|
8
|
|
|
{ |
|
9
|
|
|
protected $handler; |
|
10
|
|
|
protected $endpoints; |
|
11
|
|
|
protected $headers; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Configure a new api. |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $handler |
|
17
|
|
|
* @param Closure|null $callback |
|
18
|
|
|
*/ |
|
19
|
12 |
|
public function __construct($handler, \Closure $callback = null) |
|
20
|
|
|
{ |
|
21
|
12 |
|
$this->handler = $handler; |
|
22
|
8 |
|
$this->endpoints = new Collection(Endpoint::class); |
|
23
|
8 |
|
$this->headers = new Collection(Header::class); |
|
24
|
|
|
|
|
25
|
8 |
|
if ($callback) { |
|
26
|
8 |
|
$callback($this); |
|
27
|
8 |
|
} |
|
28
|
12 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* add a endpoint to the api. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $method |
|
34
|
|
|
* @param string $uri |
|
35
|
|
|
* @param string $name |
|
36
|
|
|
* |
|
37
|
|
|
* @return Raidros\Storer\Endpoint |
|
38
|
|
|
*/ |
|
39
|
8 |
|
public function endpoint($method, $uri, $name) |
|
40
|
|
|
{ |
|
41
|
8 |
|
return $this->endpoints->add(new Endpoint($method, $uri), $name); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* add a header to the api. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $key |
|
|
|
|
|
|
48
|
|
|
* @param string $value |
|
|
|
|
|
|
49
|
|
|
* @param string $name |
|
50
|
|
|
* |
|
51
|
|
|
* @return Raidros\Storer\Header |
|
52
|
|
|
*/ |
|
53
|
8 |
|
public function header($header, $name) |
|
54
|
|
|
{ |
|
55
|
8 |
|
return $this->headers->add(new Header($header), $name); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Return api base url. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
8 |
|
public function getHandler() |
|
64
|
|
|
{ |
|
65
|
8 |
|
return is_array($this->handler) ? $this->handler : ['base_uri' => $this->handler]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Return api headers. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
8 |
|
public function getHeaders() |
|
74
|
|
|
{ |
|
75
|
8 |
|
return $this->headers; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Return api endpoints. |
|
80
|
|
|
* |
|
81
|
|
|
* @return array |
|
82
|
|
|
*/ |
|
83
|
8 |
|
public function getEndpoints() |
|
84
|
|
|
{ |
|
85
|
8 |
|
return $this->endpoints; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Execute a call in api endpoint. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $name |
|
92
|
|
|
* @param array $params |
|
93
|
|
|
* @param array $headers |
|
94
|
|
|
* |
|
95
|
|
|
* @return GuzzleHttp\Promise\PromiseInterface |
|
96
|
|
|
*/ |
|
97
|
8 |
|
public function execute($name, array $params = [], array $headers = []) |
|
98
|
|
|
{ |
|
99
|
8 |
|
$executor = new Executor($this); |
|
100
|
|
|
|
|
101
|
8 |
|
return $executor->run($name, $params, $headers); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.