@@ -204,12 +204,22 @@ class ProblemDetailsResponseFactory
204204 */
205205 private $ defaultDetailMessage ;
206206
207+ /**
208+ * A map used to infer the "type" property based on the status code.
209+ *
210+ * Defaults to an empty map.
211+ *
212+ * @var array
213+ */
214+ private $ defaultTypes ;
215+
207216 public function __construct (
208217 callable $ responseFactory ,
209218 bool $ isDebug = self ::EXCLUDE_THROWABLE_DETAILS ,
210219 int $ jsonFlags = null ,
211220 bool $ exceptionDetailsInResponse = false ,
212- string $ defaultDetailMessage = self ::DEFAULT_DETAIL_MESSAGE
221+ string $ defaultDetailMessage = self ::DEFAULT_DETAIL_MESSAGE ,
222+ array $ defaultTypes = []
213223 ) {
214224 // Ensures type safety of the composed factory
215225 $ this ->responseFactory = function () use ($ responseFactory ) : ResponseInterface {
@@ -228,6 +238,7 @@ public function __construct(
228238 $ this ->jsonFlags = $ jsonFlags ;
229239 $ this ->exceptionDetailsInResponse = $ exceptionDetailsInResponse ;
230240 $ this ->defaultDetailMessage = $ defaultDetailMessage ;
241+ $ this ->defaultTypes = $ defaultTypes ;
231242 }
232243
233244 public function createResponse (
@@ -392,7 +403,7 @@ private function createTitleFromStatus(int $status) : string
392403
393404 private function createTypeFromStatus (int $ status ) : string
394405 {
395- return sprintf ('https://httpstatus.es/%s ' , $ status );
406+ return $ this -> defaultTypes [ $ status ] ?? sprintf ('https://httpstatus.es/%s ' , $ status );
396407 }
397408
398409 private function createThrowableDetail (Throwable $ e ) : array
0 commit comments