From: Coleman Watts Date: Mon, 23 Nov 2015 15:35:00 +0000 (-0500) Subject: Initial refactor of CRM_Utils_System to use magic method. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=091db9085e779dc6b50f1644c721846437b6c844;p=civicrm-core.git Initial refactor of CRM_Utils_System to use magic method. Instead of creating one static function for every CMS function we can access them via magic method. --- diff --git a/CRM/Admin/Form/CMSUser.php b/CRM/Admin/Form/CMSUser.php index 7ecfb8ae0f..c88a2a58da 100644 --- a/CRM/Admin/Form/CMSUser.php +++ b/CRM/Admin/Form/CMSUser.php @@ -59,7 +59,7 @@ class CRM_Admin_Form_CMSUser extends CRM_Core_Form { * Process the form submission. */ public function postProcess() { - $result = Civi::userSystem()->synchronizeUsers(); + $result = CRM_Utils_System::synchronizeUsers(); $status = ts('Checked one user record.', array( diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index d14f025945..74a1f8e092 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -33,6 +33,24 @@ /** * System wide utilities. + * + * Provides a collection of Civi utilities + access to the CMS-dependant utilities + * + * FIXME: This is a massive and random collection that could be split into smaller services + * + * @method static mixed permissionDenied() Show access denied screen. + * @method static mixed logout() Log out the current user. + * @method static mixed updateCategories() Clear CMS caches related to the user registration/profile forms. + * @method static appendBreadCrumb(string $breadCrumbs) Append an additional breadcrumb tag to the existing breadcrumbs. + * @method static resetBreadCrumb() Reset an additional breadcrumb tag to the existing breadcrumb. + * @method static addHTMLHead(string $bc) Append a string to the head of the HTML file. + * @method static string postURL(int $action) Determine the post URL for a form. + * @method static string|null getUFLocale() Get the locale of the CMS. + * @method static bool setUFLocale(string $civicrm_language) Set the locale of the CMS. + * @method static bool isUserLoggedIn() Check if user is logged in. + * @method static int getLoggedInUfID() Get current logged in user id. + * @method static setHttpHeader(string $name, string $value) Set http header. + * @method static array synchronizeUsers() Create CRM contacts for all existing CMS users. */ class CRM_Utils_System { @@ -44,6 +62,18 @@ class CRM_Utils_System { */ static $title = ''; + /** + * Access methods in the appropriate CMS class + * + * @param $name + * @param $arguments + * @return mixed + */ + public static function __callStatic($name, $arguments) { + $userSystem = CRM_Core_Config::singleton()->userSystem; + return call_user_func_array(array($userSystem, $name), $arguments); + } + /** * Compose a new URL string from the current URL string. * @@ -270,36 +300,6 @@ class CRM_Utils_System { return "$text"; } - /** - * Permission denied. - * - * @return mixed - */ - public static function permissionDenied() { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->permissionDenied(); - } - - /** - * Log out. - * - * @return mixed - */ - public static function logout() { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->logout(); - } - - /** - * This is a very drupal specific function for now. - */ - public static function updateCategories() { - $config = CRM_Core_Config::singleton(); - if ($config->userSystem->is_drupal) { - $config->userSystem->updateCategories(); - } - } - /** * What menu path are we currently on. Called for the primary tpl. * @@ -341,7 +341,9 @@ class CRM_Utils_System { * Sets the title of the page. * * @param string $title + * Document title - plain text only * @param string $pageTitle + * Page title (if different) - may include html */ public static function setTitle($title, $pageTitle = NULL) { self::$title = $title; @@ -464,48 +466,6 @@ class CRM_Utils_System { self::civiExit(); } - /** - * Append an additional breadcrumb tag to the existing breadcrumbs. - * - * @param string $breadCrumbs - */ - public static function appendBreadCrumb($breadCrumbs) { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->appendBreadCrumb($breadCrumbs); - } - - /** - * Reset an additional breadcrumb tag to the existing breadcrumb. - */ - public static function resetBreadCrumb() { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->resetBreadCrumb(); - } - - /** - * Append a string to the head of the HTML file. - * - * @param string $bc - */ - public static function addHTMLHead($bc) { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->addHTMLHead($bc); - } - - /** - * Determine the post URL for a form. - * - * @param int $action - * The default action if one is pre-specified. - * - * @return string - * The URL to post the form. - */ - public static function postURL($action) { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->postURL($action); - } - /** * Get the base URL of the system. * @@ -1386,34 +1346,6 @@ class CRM_Utils_System { } } - /** - * Get the locale of the hosting CMS. - * - * @return string - * The used locale or null for none. - */ - public static function getUFLocale() { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->getUFLocale(); - } - - /** - * Set the locale of the hosting CMS. - * - * For example, a mailing will want to change the CMS language so that - * URLs are in the correct language (such as the Drupal language prefix). - * - * @param string $civicrm_language - * An array of parameters (see CRM_Utils_System::docURL2 method for names) - * - * @return bool - * Returns whether the locale was successfully changed. - */ - public static function setUFLocale($civicrm_language) { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->setUFLocale($civicrm_language); - } - /** * Execute external or internal URLs and return server response. * @@ -1511,27 +1443,6 @@ class CRM_Utils_System { return $config->userSystem->loadBootStrap($params, $loadUser, $throwError, $realPath); } - /** - * Check if user is logged in. - * - * @return bool - */ - public static function isUserLoggedIn() { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->isUserLoggedIn(); - } - - /** - * Get current logged in user id. - * - * @return int - * ufId, currently logged in user uf id. - */ - public static function getLoggedInUfID() { - $config = CRM_Core_Config::singleton(); - return $config->userSystem->getLoggedInUfID(); - } - /** * Get Base CMS url. * @@ -1915,14 +1826,4 @@ class CRM_Utils_System { return NULL; } - /** - * Set http header. - * - * @param string $name - * @param string $value - */ - public static function setHttpHeader($name, $value) { - CRM_Core_Config::singleton()->userSystem->setHttpHeader($name, $value); - } - } diff --git a/Civi.php b/Civi.php index 21ee580731..fe16326de7 100644 --- a/Civi.php +++ b/Civi.php @@ -115,11 +115,4 @@ class Civi { return \Civi\Core\Container::getBootService('settings_manager')->getBagByDomain($domainID); } - /** - * @return \CRM_Utils_System_Base - */ - public static function userSystem() { - return CRM_Core_Config::singleton()->userSystem; - } - }