@@ -58,7 +58,8 @@ class Resolver implements CacheAwareInterface
5858 public function __construct ()
5959 {
6060 $ this ->methodOperations = [
61- 'GET ' => 'get ' , 'POST ' => 'create ' , 'PUT ' => 'update ' , 'DELETE ' => 'delete ' , 'PATCH ' => 'modify '
61+ 'GET ' => 'get ' , 'POST ' => 'create ' , 'PUT ' => 'update ' , 'DELETE ' => 'delete ' , 'PATCH ' => 'modify ' ,
62+ 'OPTIONS ' => 'options ' , 'HEAD ' => 'head '
6263 ];
6364 }
6465
@@ -92,8 +93,7 @@ public function setMethodOperations(array $methodOperations): void
9293 */
9394 public function setMethodOperation (string $ method , string $ operation ): void
9495 {
95- $ knownMethods = $ this ->methodOperations + ['HEAD ' => true , 'OPTIONS ' => true ];
96- if ( ! isset ($ knownMethods [$ method = strtoupper ($ method )]) ) {
96+ if ( ! isset ($ this ->methodOperations [$ method = strtoupper ($ method )]) ) {
9797 throw new InvalidArgumentException ("The method ' {$ method }' is not a valid http method. " );
9898 }
9999
@@ -207,13 +207,14 @@ public function match(string $method, string $path): Match
207207 'Alternative resource operations must be requested by POST. '
208208 );
209209 }
210- if ( ! preg_match ('/^[a-zA-Z ]+$/ ' , $ methodOperations ['POST ' ]) ) {
210+ if ( ! preg_match ('/^[a-zA-Z_- ]+$/ ' , $ methodOperations ['POST ' ]) ) {
211211 throw new HttpBadRequestException ('Invalid operation method. ' );
212212 }
213213 }
214214
215- $ allowedMethods = $ resource ->getAllowedMethods ();
216- if ( ! in_array ($ method , $ allowedMethods + ['OPTIONS ' , 'HEAD ' ], true ) ) {
215+ $ allowedMethods = array_merge ($ resource ->getAllowedMethods (), ['OPTIONS ' , 'HEAD ' ]);
216+
217+ if ( ! in_array ($ method , $ allowedMethods , true ) ) {
217218 throw new HttpMethodNotAllowedException (
218219 'Invalid method. This resource supports only one of this methods: ' .implode (', ' , $ allowedMethods )
219220 );
0 commit comments