diff --git a/Sources/IntegrationHook.php b/Sources/IntegrationHook.php index fcf90a4135..da56065746 100644 --- a/Sources/IntegrationHook.php +++ b/Sources/IntegrationHook.php @@ -116,39 +116,7 @@ public function execute(array $parameters = []): array // Loop through each callable. foreach ($this->callables as $func_string => $callable) { - // Is it valid? - if (\is_callable($callable)) { - $this->results[$func_string] = \call_user_func_array($callable, $parameters); - } - // This failed, but we want to do so silently. - elseif ($this->ignore_errors) { - // return $this->results; - continue; - } - // Whatever it was supposed to call, it failed :( - else { - // Get a full path to show on error. - if (str_contains($func_string, '|')) { - list($file, $func) = explode('|', $func_string); - - $path = strtr($file, [ - '$boarddir' => Config::$boarddir, - '$sourcedir' => Config::$sourcedir, - ]); - - if (str_contains($path, '$themedir') && class_exists('SMF\\Theme', false) && !empty(Theme::$current->settings['theme_dir'])) { - $path = strtr($path, [ - '$themedir' => Theme::$current->settings['theme_dir'], - ]); - } - - ErrorHandler::log(Lang::getTxt('hook_fail_call_to', [$func, $path], file: 'Errors'), 'general'); - } - // Assume the file resides on Config::$boarddir somewhere... - else { - ErrorHandler::log(Lang::getTxt('hook_fail_call_to', [$func_string, Config::$boarddir], file: 'Errors'), 'general'); - } - } + $this->results[$func_string] = $callable(...$parameters); } return $this->results; diff --git a/Sources/Utils.php b/Sources/Utils.php index 45b784fb50..4f95851a07 100644 --- a/Sources/Utils.php +++ b/Sources/Utils.php @@ -2419,9 +2419,6 @@ public static function getCallable(string|callable $input, ?bool $ignore_errors return \is_callable($input) ? $input : false; } - // Sanitize and trim the input. - $input = Utils::htmlspecialchars(Utils::htmlTrim($input)); - // Attempt to load a file, if applicable. $input = self::loadFile($input); @@ -2431,8 +2428,11 @@ public static function getCallable(string|callable $input, ?bool $ignore_errors } // Process static or instance method callables. - if (str_contains($input, '::')) { - list($class, $method) = explode('::', $input); + $pos = strpos($input, '::'); + + if ($pos !== false) { + $class = substr($input, 0, $pos); + $method = substr($input, $pos + 2); // Handle instance creation for methods with "#". if (str_contains($method, '#')) { @@ -2440,11 +2440,12 @@ public static function getCallable(string|callable $input, ?bool $ignore_errors Utils::$context['instances'] = []; } + $instances = &Utils::$context['instances']; // Remove the "#" and ensure an instance exists. $method = str_replace('#', '', $method); - if (empty(Utils::$context['instances'][$class]) || !(Utils::$context['instances'][$class] instanceof $class)) { - Utils::$context['instances'][$class] = new $class(); + if (empty($instances[$class]) || !($instances[$class] instanceof $class)) { + $instances[$class] = new $class(); // Optionally track instance creation for debugging. if (DebugUtils::isDebugEnabled()) { @@ -2456,14 +2457,14 @@ public static function getCallable(string|callable $input, ?bool $ignore_errors } } - $callable = [Utils::$context['instances'][$class], $method]; + $callable = $instances[$class]->$method(...); } else { // Static method reference. - $callable = [$class, $method]; + $callable = $class::$method(...); } } else { // Treat as a plain function. - $callable = $input; + $callable = $input(...); } // Validate the callable.