Skip to content

Instantly share code, notes, and snippets.

@leevigraham
Last active April 8, 2018 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leevigraham/35b9d1e458fe4fec3a6323d56fea204d to your computer and use it in GitHub Desktop.
Save leevigraham/35b9d1e458fe4fec3a6323d56fea204d to your computer and use it in GitHub Desktop.
Support for verb requests in craftcms v2
<?php
// Example in your plugin file
public function registerSiteRoutes(): array {
return [
'api/.*+' => ['action' => 'nCIG/preFlight', 'verb' => 'OPTIONS'],
];
}
From b9825afaafd273ad030c95dbdecc9c467c73727a Mon Sep 17 00:00:00 2001
From: Leevi Graham <leevi@newism.com.au>
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