1 | <?php |
||
24 | final class TypeAdapterProvider |
||
25 | { |
||
26 | /** |
||
27 | * A cache of mapped factories |
||
28 | * |
||
29 | * @var CacheProvider |
||
30 | */ |
||
31 | private $typeAdapterCache; |
||
32 | |||
33 | /** |
||
34 | * All registered [@see TypeAdapter]s |
||
35 | * |
||
36 | * @var TypeAdapterFactory[] |
||
37 | */ |
||
38 | private $typeAdapterFactories = []; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | * |
||
43 | * @param array $typeAdapterFactories |
||
44 | * @param CacheProvider $cache |
||
45 | */ |
||
46 | 12 | public function __construct(array $typeAdapterFactories, CacheProvider $cache) |
|
51 | |||
52 | /** |
||
53 | * Add type adapter directly into cache |
||
54 | * |
||
55 | * @param string $type |
||
56 | * @param TypeAdapter $typeAdapter |
||
57 | */ |
||
58 | 1 | public function addTypeAdapter(string $type, TypeAdapter $typeAdapter): void |
|
62 | |||
63 | /** |
||
64 | * Creates a key based on the type, and optionally the class that should be skipped. |
||
65 | * Returns the [@see TypeAdapter] if it has already been created, otherwise loops |
||
66 | * over all of the factories and finds a type adapter that supports the type. |
||
67 | * |
||
68 | * @param PhpType $type |
||
69 | * @param TypeAdapterFactory $skip |
||
|
|||
70 | * @return TypeAdapter |
||
71 | * @throws \InvalidArgumentException if the type cannot be handled by a type adapter |
||
72 | */ |
||
73 | 6 | public function getAdapter(PhpType $type, TypeAdapterFactory $skip = null): TypeAdapter |
|
105 | |||
106 | /** |
||
107 | * Get a type adapter from a [@see JsonAdapter] annotation |
||
108 | * |
||
109 | * The class may be a TypeAdapter, TypeAdapterFactory, JsonSerializer, or JsonDeserializer |
||
110 | * |
||
111 | * @param PhpType $phpType |
||
112 | * @param JsonAdapter $jsonAdapterAnnotation |
||
113 | * @return TypeAdapter |
||
114 | * @throws \InvalidArgumentException if an invalid adapter is found |
||
115 | */ |
||
116 | 6 | public function getAdapterFromAnnotation(PhpType $phpType, JsonAdapter $jsonAdapterAnnotation): TypeAdapter |
|
146 | } |
||
147 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.