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
|
15 |
|
public function __construct($handler, \Closure $callback = null) |
20
|
|
|
{ |
21
|
15 |
|
$this->handler = $handler; |
22
|
10 |
|
$this->endpoints = new Collection(Endpoint::class); |
23
|
10 |
|
$this->headers = new Collection(Header::class); |
24
|
|
|
|
25
|
10 |
|
if ($callback) { |
26
|
10 |
|
$callback($this); |
27
|
10 |
|
} |
28
|
15 |
|
} |
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
|
10 |
|
public function endpoint($method, $uri, $name) |
40
|
|
|
{ |
41
|
10 |
|
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
|
10 |
|
public function header($header, $name) |
54
|
|
|
{ |
55
|
10 |
|
return $this->headers->add(new Header($header), $name); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Return api base url. |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
10 |
|
public function getHandler() |
64
|
|
|
{ |
65
|
10 |
|
return is_array($this->handler) ? $this->handler : ['base_uri' => $this->handler]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Return api headers. |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
10 |
|
public function getHeaders() |
74
|
|
|
{ |
75
|
10 |
|
return $this->headers; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Return api endpoints. |
80
|
|
|
* |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
10 |
|
public function getEndpoints() |
84
|
|
|
{ |
85
|
10 |
|
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
|
10 |
|
public function execute($name, array $params = [], array $headers = []) |
98
|
|
|
{ |
99
|
10 |
|
$executor = new Executor($this); |
100
|
|
|
|
101
|
10 |
|
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.