diff --git a/core/modules/rest/src/Entity/RestEndpoint.php b/core/modules/rest/src/Entity/RestEndpoint.php index 7769a55..1d56c06 100644 --- a/core/modules/rest/src/Entity/RestEndpoint.php +++ b/core/modules/rest/src/Entity/RestEndpoint.php @@ -88,6 +88,7 @@ public function getResourcePlugin() { * {@inheritdoc} */ public function getSupportedAuthenticationProviders($method) { + $method = $this->normaliseRestMethod($method); if (isset($this->configuration[$method]) && isset($this->configuration[$method]['supported_auth'])) { return $this->configuration[$method]['supported_auth']; } @@ -98,11 +99,13 @@ public function getSupportedAuthenticationProviders($method) { * {@inheritdoc} */ public function hasSupportForAuthenticationProvider($method, $auth) { + $method = $this->normaliseRestMethod($method); return $this->hasSupportedAuthenticationProviders($method) && in_array($auth, $this->configuration[$method]['supported_auth']); } public function hasSupportedAuthenticationProviders($method) { + $method = $this->normaliseRestMethod($method); return isset($this->configuration[$method]) && isset($this->configuration[$method]['supported_auth']) && !empty($this->configuration[$method]['supported_auth']); @@ -112,6 +115,7 @@ public function hasSupportedAuthenticationProviders($method) { * {@inheritdoc} */ public function addSupportedAuthenticationProvider($method, $auth) { + $method = $this->normaliseRestMethod($method); if (!isset($this->configuration[$method])) { $this->configuration[$method] = [ 'supported_auth' => [] ]; } @@ -128,6 +132,7 @@ public function addSupportedAuthenticationProvider($method, $auth) { * {@inheritdoc} */ public function removeSupportedAuthenticationProvider($method, $auth) { + $method = $this->normaliseRestMethod($method); $new_auth = array_filter($this->configuration[$method]['supported_auth'], function ($val) use ($auth) { return ($val != $auth); }); @@ -139,6 +144,7 @@ public function removeSupportedAuthenticationProvider($method, $auth) { * {@inheritdoc} */ public function getSupportedFormats($method) { + $method = $this->normaliseRestMethod($method); if (isset($this->configuration[$method]) && isset($this->configuration[$method]['supported_formats'])) { return $this->configuration[$method]['supported_formats']; } @@ -149,6 +155,7 @@ public function getSupportedFormats($method) { * {@inheritdoc} */ public function supportsFormat($method, $format) { + $method = $this->normaliseRestMethod($method); return $this->hasSupportedFormats($method) && in_array($format, $this->configuration[$method]['supported_formats']); } @@ -157,6 +164,7 @@ public function supportsFormat($method, $format) { * {@inheritdoc} */ public function hasSupportedFormats($method) { + $method = $this->normaliseRestMethod($method); return isset($this->configuration[$method]) && isset($this->configuration[$method]['supported_formats']) && !empty($this->configuration[$method]['supported_formats']); @@ -166,6 +174,7 @@ public function hasSupportedFormats($method) { * {@inheritdoc} */ public function addSupportedFormat($method, $format) { + $method = $this->normaliseRestMethod($method); if (!isset($this->configuration[$method])) { $this->configuration[$method] = [ 'supported_formats' => [] ]; } @@ -182,6 +191,7 @@ public function addSupportedFormat($method, $format) { * {@inheritdoc} */ public function removeSupportedFormat($method, $format) { + $method = $this->normaliseRestMethod($method); $new_auth = array_filter($this->configuration[$method]['supported_formats'], function ($val) use ($format) { return ($val != $format); }); @@ -202,4 +212,13 @@ public function getPluginCollections() { 'resource' => new DefaultLazyPluginCollection($this->pluginManager, $plugin_configuration) ]; } + + protected function normaliseRestMethod($method) { + $valid_methods = [ 'GET', 'POST', 'PATCH', 'DELETE' ]; + $normalised_method = strtoupper($method); + if (!in_array($normalised_method, $valid_methods)) { + throw new \InvalidArgumentException('The method is not supported.'); + } + return $normalised_method; + } }