@@ -166,10 +166,7 @@ private function process_mask($mask)
166166 */
167167 public function payload ($ format = '' )
168168 {
169- if (!empty ($ format ))
170- if (isset ($ this ->supported_formats [$ format ]))
171- return $ this ->{$ this ->supported_formats [$ format ]}($ this ->getPayload ());
172- return $ this ->{$ this ->getFormat ()}($ this ->getPayload ());
169+ return $ this ->{$ this ->getFormat ($ format )}($ this ->getPayload ());
173170 }
174171
175172 /**
@@ -187,22 +184,46 @@ public function all()
187184 *
188185 * @return string Return the short format code (xml, json, ...).
189186 */
190- public function getFormat ()
187+ public function getFormat ($ format = '' )
191188 {
189+ if (! empty ($ format )) {
190+ return $ this ->processContentType ($ format );
191+ }
192+
192193 if (isset ($ _SERVER ['CONTENT_TYPE ' ]))
193194 {
194- if ( isset ( $ this ->supported_formats [ $ _SERVER ['CONTENT_TYPE ' ]]))
195- return $ this -> supported_formats [ $ _SERVER [ ' CONTENT_TYPE ' ]] ;
195+ $ type = $ this ->processContentType ( $ _SERVER ['CONTENT_TYPE ' ]);
196+ if ( $ type !== false ) return $ type ;
196197 }
198+
197199 if (isset ($ _SERVER ['HTTP_CONTENT_TYPE ' ]))
198200 {
199- if ( isset ( $ this ->supported_formats [ $ _SERVER ['HTTP_CONTENT_TYPE ' ]]))
200- return $ this -> supported_formats [ $ _SERVER [ ' HTTP_CONTENT_TYPE ' ]] ;
201+ $ type = $ this ->processContentType ( $ _SERVER ['HTTP_CONTENT_TYPE ' ]);
202+ if ( $ type !== false ) return $ type ;
201203 }
202204
203205 return 'json ' ;
204206 }
205207
208+ /**
209+ * Process the content-type values
210+ *
211+ * @param string $contentType Content-Type raw string
212+ *
213+ * @return bool|string
214+ */
215+ private function processContentType ($ contentType )
216+ {
217+ foreach (explode ('; ' , $ contentType ) as $ type ) {
218+ $ type = strtolower (trim ($ type ));
219+ if (isset ($ this ->supported_formats [$ type ])) {
220+ return $ this ->supported_formats [$ type ];
221+ }
222+ }
223+
224+ return false ;
225+ }
226+
206227 /**
207228 * Return the payload data from the HTTP post request.
208229 *
0 commit comments