|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) Nate Brunette. |
|
4
|
|
|
* Distributed under the MIT License (http://opensource.org/licenses/MIT) |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace Tebru\Retrofit\Internal\AnnotationHandler; |
|
10
|
|
|
|
|
11
|
|
|
use InvalidArgumentException; |
|
12
|
|
|
use Tebru\AnnotationReader\AbstractAnnotation; |
|
13
|
|
|
use Tebru\Retrofit\AnnotationHandler; |
|
14
|
|
|
use Tebru\Retrofit\Converter; |
|
15
|
|
|
use Tebru\Retrofit\Internal\ParameterHandler\PathParamHandler; |
|
16
|
|
|
use Tebru\Retrofit\ServiceMethodBuilder; |
|
17
|
|
|
use Tebru\Retrofit\StringConverter; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class PathAnnotHandler |
|
21
|
|
|
* |
|
22
|
|
|
* @author Nate Brunette <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class PathAnnotHandler implements AnnotationHandler |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Add a path param handler |
|
28
|
|
|
* |
|
29
|
|
|
* @param AbstractAnnotation $annotation The annotation to handle |
|
30
|
|
|
* @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod] |
|
31
|
|
|
* @param Converter|StringConverter $converter Converter used to convert types before sending to service method |
|
32
|
|
|
* @param int|null $index The position of the parameter or null if annotation does not reference parameter |
|
33
|
|
|
* @return void |
|
34
|
|
|
* @throws \InvalidArgumentException |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public function handle( |
|
37
|
|
|
AbstractAnnotation $annotation, |
|
38
|
|
|
ServiceMethodBuilder $serviceMethodBuilder, |
|
39
|
|
|
?Converter $converter, |
|
40
|
|
|
?int $index |
|
41
|
|
|
): void { |
|
42
|
3 |
|
if (!$converter instanceof StringConverter) { |
|
43
|
1 |
|
throw new InvalidArgumentException(sprintf( |
|
44
|
1 |
|
'Retrofit: Converter must be a StringConverter, %s found', |
|
45
|
1 |
|
\gettype($converter) |
|
46
|
|
|
)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
$serviceMethodBuilder->addParameterHandler($index, new PathParamHandler($converter, $annotation->getValue())); |
|
50
|
2 |
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|