| @@ 72-94 (lines=23) @@ | ||
| 69 | * @return ResponseBodyConverter |
|
| 70 | * @throws LogicException |
|
| 71 | */ |
|
| 72 | public function getResponseBodyConverter(TypeToken $type): ResponseBodyConverter |
|
| 73 | { |
|
| 74 | $key = (string)$type; |
|
| 75 | if (isset($this->responseBodyConverters[$key])) { |
|
| 76 | return $this->responseBodyConverters[$key]; |
|
| 77 | } |
|
| 78 | ||
| 79 | foreach ($this->converterFactories as $converterFactory) { |
|
| 80 | $converter = $converterFactory->responseBodyConverter($type); |
|
| 81 | if ($converter === null) { |
|
| 82 | continue; |
|
| 83 | } |
|
| 84 | ||
| 85 | $this->responseBodyConverters[$key] = $converter; |
|
| 86 | ||
| 87 | return $converter; |
|
| 88 | } |
|
| 89 | ||
| 90 | throw new LogicException(sprintf( |
|
| 91 | 'Retrofit: Could not get response body converter for type %s', |
|
| 92 | $type |
|
| 93 | )); |
|
| 94 | } |
|
| 95 | ||
| 96 | /** |
|
| 97 | * Get a request body converter for type |
|
| @@ 103-125 (lines=23) @@ | ||
| 100 | * @return RequestBodyConverter |
|
| 101 | * @throws \LogicException |
|
| 102 | */ |
|
| 103 | public function getRequestBodyConverter(TypeToken $type): RequestBodyConverter |
|
| 104 | { |
|
| 105 | $key = (string)$type; |
|
| 106 | if (isset($this->requestBodyConverters[$key])) { |
|
| 107 | return $this->requestBodyConverters[$key]; |
|
| 108 | } |
|
| 109 | ||
| 110 | foreach ($this->converterFactories as $converterFactory) { |
|
| 111 | $converter = $converterFactory->requestBodyConverter($type); |
|
| 112 | if ($converter === null) { |
|
| 113 | continue; |
|
| 114 | } |
|
| 115 | ||
| 116 | $this->requestBodyConverters[$key] = $converter; |
|
| 117 | ||
| 118 | return $converter; |
|
| 119 | } |
|
| 120 | ||
| 121 | throw new LogicException(sprintf( |
|
| 122 | 'Retrofit: Could not get request body converter for type %s', |
|
| 123 | $type |
|
| 124 | )); |
|
| 125 | } |
|
| 126 | ||
| 127 | /** |
|
| 128 | * Get a string converter for type |
|
| @@ 134-156 (lines=23) @@ | ||
| 131 | * @return StringConverter |
|
| 132 | * @throws \LogicException |
|
| 133 | */ |
|
| 134 | public function getStringConverter(TypeToken $type): StringConverter |
|
| 135 | { |
|
| 136 | $key = (string)$type; |
|
| 137 | if (isset($this->stringConverters[$key])) { |
|
| 138 | return $this->stringConverters[$key]; |
|
| 139 | } |
|
| 140 | ||
| 141 | foreach ($this->converterFactories as $converterFactory) { |
|
| 142 | $converter = $converterFactory->stringConverter($type); |
|
| 143 | if ($converter === null) { |
|
| 144 | continue; |
|
| 145 | } |
|
| 146 | ||
| 147 | $this->stringConverters[$key] = $converter; |
|
| 148 | ||
| 149 | return $converter; |
|
| 150 | } |
|
| 151 | ||
| 152 | throw new LogicException(sprintf( |
|
| 153 | 'Retrofit: Could not get string converter for type %s', |
|
| 154 | $type |
|
| 155 | )); |
|
| 156 | } |
|
| 157 | } |
|
| 158 | ||