From d977cabb821b43096934b189a8583ab4b9d294b8 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 12 Jun 2019 15:34:18 -0400 Subject: [PATCH] Add optional support for an executeUnknown() method to Process modules. This method is called when an unknown method is requested. It is not enabled by default, unless you add an executeUnknown() method to the Process module. --- wire/core/Process.php | 13 +++++++++++++ wire/core/ProcessController.php | 16 ++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/wire/core/Process.php b/wire/core/Process.php index f35d3a2f..074da9d7 100644 --- a/wire/core/Process.php +++ b/wire/core/Process.php @@ -151,6 +151,19 @@ abstract class Process extends WireData implements Module { */ public function ___executed($method) { } + /* + * Add this method to your Process module if you want a catch-all fallback + * + * It should check $input->urlSegment1 for the method that was requested. + * This is commented out here since it is not used by Process modules unless manually added. + * + * @since 3.0.133 + * @return string|array + * + public function ___executeUnknown() { + } + */ + /** * Get a value stored in this Process * diff --git a/wire/core/ProcessController.php b/wire/core/ProcessController.php index 8bd33ea1..8a182cd4 100644 --- a/wire/core/ProcessController.php +++ b/wire/core/ProcessController.php @@ -291,12 +291,16 @@ class ProcessController extends Wire { } } - if($forceFail) return ''; - if($method === 'executed') return ''; - - if(method_exists($process, $method)) return $method; - if(method_exists($process, "___$method")) return $method; - if($process->hasHook($method . '()')) return $method; + if(!$forceFail) { + if($method === 'executed') return ''; + if(method_exists($process, $method)) return $method; + if(method_exists($process, "___$method")) return $method; + if($process->hasHook($method . '()')) return $method; + } + + // fallback to the unknown, if there is an unknown (you never know) + $method = 'executeUnknown'; + if(method_exists($process, $method) || method_exists($process, "___$method")) return $method; return ''; }