X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FInvoke.php;h=3a50bfe161c4ec64a7a5bf7dbfda9e709c3d9278;hb=16bd56a4590b6ded39eaa6abaa15e7904e410445;hp=7f52c37c79117f9db022108202dcdc6f635e8139;hpb=6049c0d89e4b18c81cea8108acc71ba6bdc3ba85;p=civicrm-core.git diff --git a/CRM/Core/Invoke.php b/CRM/Core/Invoke.php index 7f52c37c79..3a50bfe161 100644 --- a/CRM/Core/Invoke.php +++ b/CRM/Core/Invoke.php @@ -23,7 +23,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /** * @@ -48,7 +48,6 @@ class CRM_Core_Invoke { * @return string * HTML. For non-HTML content, invoke() may call print() and exit(). * - * @static */ public static function invoke($args) { try { @@ -71,7 +70,11 @@ class CRM_Core_Invoke { */ public static function _invoke($args) { if ($args[0] !== 'civicrm') { - return; + return NULL; + } + // CRM-15901: Turn off PHP errors display for all ajax calls + if (CRM_Utils_Array::value(1, $args) == 'ajax' || CRM_Utils_Array::value('snippet', $_REQUEST)) { + ini_set('display_errors', 0); } if (!defined('CIVICRM_SYMFONY_PATH')) { @@ -86,7 +89,7 @@ class CRM_Core_Invoke { // Symfony-based invocation path require_once CIVICRM_SYMFONY_PATH . '/app/bootstrap.php.cache'; require_once CIVICRM_SYMFONY_PATH . '/app/AppKernel.php'; - $kernel = new AppKernel('dev', true); + $kernel = new AppKernel('dev', TRUE); $kernel->loadClassCache(); $response = $kernel->handle(Symfony\Component\HttpFoundation\Request::createFromGlobals()); if (preg_match(':^text/html:', $response->headers->get('Content-Type'))) { @@ -99,6 +102,7 @@ class CRM_Core_Invoke { } } } + /** * Hackish support /civicrm/menu/rebuild * @@ -107,7 +111,7 @@ class CRM_Core_Invoke { * @void */ static public function hackMenuRebuild($args) { - if (array('civicrm','menu','rebuild') == $args || array('civicrm', 'clearcache') == $args) { + if (array('civicrm', 'menu', 'rebuild') == $args || array('civicrm', 'clearcache') == $args) { // ensure that the user has a good privilege level if (CRM_Core_Permission::check('administer CiviCRM')) { self::rebuildMenuAndCaches(); @@ -121,7 +125,7 @@ class CRM_Core_Invoke { } /** - * Perform general setup + * Perform general setup. * * @param array $args * List of path parts. @@ -213,9 +217,9 @@ class CRM_Core_Invoke { if ($item) { // CRM-7656 - make sure we send a clean sanitized path to create printer friendly url $printerFriendly = CRM_Utils_System::makeURL( - 'snippet', FALSE, FALSE, - CRM_Utils_Array::value('path', $item) - ) . '2'; + 'snippet', FALSE, FALSE, + CRM_Utils_Array::value('path', $item) + ) . '2'; $template->assign('printerFriendly', $printerFriendly); if (!array_key_exists('page_callback', $item)) { @@ -226,7 +230,7 @@ class CRM_Core_Invoke { // check that we are permissioned to access this page if (!CRM_Core_Permission::checkMenuItem($item)) { CRM_Utils_System::permissionDenied(); - return; + return NULL; } // check if ssl is set @@ -267,9 +271,11 @@ class CRM_Core_Invoke { } $result = NULL; - if (is_array($item['page_callback'])) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, $item['page_callback'][0]) . '.php'); - $result = call_user_func($item['page_callback']); + // WISHLIST: Refactor this. Instead of pattern-matching on page_callback, lookup + // page_callback via Civi\Core\Resolver and check the implemented interfaces. This + // would require rethinking the default constructor. + if (is_array($item['page_callback']) || strpos($item['page_callback'], ':')) { + $result = call_user_func(Civi\Core\Resolver::singleton()->get($item['page_callback'])); } elseif (strstr($item['page_callback'], '_Form')) { $wrapper = new CRM_Utils_Wrapper(); @@ -281,25 +287,24 @@ class CRM_Core_Invoke { } else { $newArgs = explode('/', $_GET[$config->userFrameworkURLVar]); - 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')) { - $object = new $item['page_callback'] ($title, $mode); + 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']; $addSequence = $addSequence ? 'true' : 'false'; unset($pageArgs['addSequence']); } - $object = new $item['page_callback'] ($title, true, $mode, null, $addSequence); + $object = new $item['page_callback']($title, TRUE, $mode, NULL, $addSequence); } else { CRM_Core_Error::fatal(); @@ -317,14 +322,13 @@ class CRM_Core_Invoke { } /** - * This function contains the default action + * This function contains the default action. * * @param $action * * @param $contact_type * @param $contact_sub_type * - * @static */ public static function form($action, $contact_type, $contact_sub_type) { CRM_Utils_System::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view')); @@ -340,7 +344,7 @@ class CRM_Core_Invoke { } /** - * Show the message about CiviCRM versions + * Show the message about CiviCRM versions. * * @param CRM_Core_Smarty $template */ @@ -398,4 +402,5 @@ class CRM_Core_Invoke { CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE); CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); } + }