Last active
April 8, 2018 01:49
-
-
Save leevigraham/35b9d1e458fe4fec3a6323d56fea204d to your computer and use it in GitHub Desktop.
Support for verb requests in craftcms v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example in your plugin file | |
public function registerSiteRoutes(): array { | |
return [ | |
'api/.*+' => ['action' => 'nCIG/preFlight', 'verb' => 'OPTIONS'], | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b9825afaafd273ad030c95dbdecc9c467c73727a Mon Sep 17 00:00:00 2001 | |
From: Leevi Graham <[email protected]> | |
Date: Tue, 12 Dec 2017 15:25:57 +1100 | |
Subject: [PATCH] Support request verbs | |
--- | |
craft/app/etc/web/UrlManager.php | 11 ++++++++++- | |
1 file changed, 10 insertions(+), 1 deletion(-) | |
diff --git a/craft/app/etc/web/UrlManager.php b/craft/app/etc/web/UrlManager.php | |
index 8550b29..4e4d55a 100644 | |
--- a/craft/app/etc/web/UrlManager.php | |
+++ b/craft/app/etc/web/UrlManager.php | |
@@ -383,8 +383,17 @@ class UrlManager extends \CUrlManager | |
// Parse tokens | |
$regexPattern = $this->_parseRegexTokens($regexPattern); | |
+ // HACK: Support route verbs ^LG | |
+ $verbMatch = true; | |
+ if(is_array($route) && array_key_exists('verb', $route)){ | |
+ $verbMatch = false; | |
+ if(craft()->getRequest()->getRequestType() === strtoupper($route['verb'])) { | |
+ $verbMatch = true; | |
+ } | |
+ } | |
+ | |
// Does it match? | |
- if (preg_match('/^'.$regexPattern.'$/u', $path, $match)) | |
+ if (preg_match('/^'.$regexPattern.'$/u', $path, $match) && $verbMatch) | |
{ | |
// Normalize the route | |
$route = $this->_normalizeRoute($route); | |
-- | |
2.14.1+GitX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment