From 99218b4b7f17af4aa11a1469ff469aef6ff4abd1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Jan 2015 22:24:42 -0800 Subject: [PATCH] CRM_Core_Invoke - Backport support for PHP 5.3 namespaces This is a partial backport of 0fc3cacbd2714be493afda6a33eda93846deaca2. It includes support for PHP 5.3 namespaces but not for Symfony request/response objects. --- CRM/Core/Invoke.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CRM/Core/Invoke.php b/CRM/Core/Invoke.php index b1da8497d3..6fdec2cee8 100644 --- a/CRM/Core/Invoke.php +++ b/CRM/Core/Invoke.php @@ -268,7 +268,10 @@ class CRM_Core_Invoke { $result = NULL; if (is_array($item['page_callback'])) { - require_once str_replace('_', DIRECTORY_SEPARATOR, $item['page_callback'][0]) . '.php'; + if ($item['page_callback']{0} !== '\\') { + // Legacy class-loading for PHP 5.2 namespaces; not sure it's needed, but counter-productive for PHP 5.3 namespaces + require_once str_replace('_', DIRECTORY_SEPARATOR, $item['page_callback'][0]) . '.php'; + } $result = call_user_func($item['page_callback']); } elseif (strstr($item['page_callback'], '_Form')) { @@ -281,18 +284,21 @@ class CRM_Core_Invoke { } else { $newArgs = explode('/', $_GET[$config->userFrameworkURLVar]); - require_once str_replace('_', DIRECTORY_SEPARATOR, $item['page_callback']) . '.php'; + if ($item['page_callback']{0} !== '\\') { + // Legacy class-loading for PHP 5.2 namespaces; not sure it's needed, but counter-productive for PHP 5.3 namespaces + require_once str_replace('_', DIRECTORY_SEPARATOR, $item['page_callback']) . '.php'; + } $mode = 'null'; if (isset($pageArgs['mode'])) { $mode = $pageArgs['mode']; unset($pageArgs['mode']); } $title = CRM_Utils_Array::value('title', $item); - if (strstr($item['page_callback'], '_Page')) { + if (strstr($item['page_callback'], '_Page') || strstr($item['page_callback'], '\\Page\\')) { $object = new $item['page_callback']($title, $mode); $object->urlPath = explode('/', $_GET[$config->userFrameworkURLVar]); } - elseif (strstr($item['page_callback'], '_Controller')) { + elseif (strstr($item['page_callback'], '_Controller') || strstr($item['page_callback'], '\\Controller\\')) { $addSequence = 'false'; if (isset($pageArgs['addSequence'])) { $addSequence = $pageArgs['addSequence']; -- 2.25.1