Answers.Body: <p>It's probably easier to answer based on a specific need rather than your more generic "hey, found a stash of toys, can I play with them? ;)"</p>
  
  <p>They are a few that you shouldn't use directly but use the more specific functions, so instead of:</p>
  
  <pre><code>addHTMLHead($head)
  addScript($code, $region)
  addScriptUrl($url, $region)
  addStyle($code, $region)
  addStyleUrl($url, $region)
  </code></pre>
  
  <p>it's more common/recommended to use <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Resource+Reference" rel="nofollow noreferrer">CRM_Core_Resources</a> </p>
  
  <pre><code>CRM_Core_Resources::singleton()
  -&gt;addScriptFile(...)
  -&gt;addStyleFile(...)
  ...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-29T12:13:53.537Z
Answers.Text: hey thanks @Xavier! good point, but that is one cool box of toys!! I guess I'm hunting for a generic pattern of accessing this interface from the context of an extension author (I wish I'd known about some of them years ago!)
Answers.UserDisplayName: ErichBSchulz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-29T11:48:36.383Z
Answers.LastActivityDate: 2016-12-29T11:48:36.383Z
Answers.UserDisplayName: Xavier
Answers.Body: <p>There is this example:
  <code>
  CRM/Utils/System.php-1503-  /**
  CRM/Utils/System.php-1504-   * Check if user is logged in.
  CRM/Utils/System.php-1505-   *
  CRM/Utils/System.php-1506-   * @return bool
  CRM/Utils/System.php-1507-   */
  CRM/Utils/System.php:1508:  public static function isUserLoggedIn() {
  CRM/Utils/System.php-1509-    $config = CRM_Core_Config::singleton();
  CRM/Utils/System.php:1510:    return $config-&gt;userSystem-&gt;isUserLoggedIn();
  CRM/Utils/System.php-1511-  }
  </code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-29T05:29:07.913Z
Answers.Text: answered my own question as a "best guess" on the basis someone who knows more may wish to post a better answer!
Answers.UserDisplayName: ErichBSchulz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-29T05:27:15.243Z
Answers.LastActivityDate: 2016-12-29T05:27:15.243Z
Answers.UserDisplayName: ErichBSchulz
Answers.Body: <p>This base class is not intended to be used by itself, but extended based on the CMS. CiviCRM will automatically give you an instance of the correct object which extends this base class. You can access it via the <code>CRM_Utils_System</code> static methods. For example:</p>
  
  <pre><code>CRM_Utils_System::appendBreadCrumb($something);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>CRM_Utils_System::isUserLoggedIn();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-01T03:36:12.057Z
Answers.Text: Cool @ErichBSchulz don't forget to mark this answer correct.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-01T01:17:36.277Z
Answers.LastActivityDate: 2017-01-01T03:38:04.963Z
Answers.LastEditDate: 2017-01-01T03:38:04.963Z
Answers.UserDisplayName: Coleman
Body: <p><a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/System/Base.php" rel="nofollow noreferrer"><code>CRM_Utils_System_Base</code></a> defines a great set of key functions that look like they should work in any system.</p>
  
  <p>What is the correct way to access this functionality within an extension?</p>
  
  <p>FYI these are the classes public methods:</p>
  
  <p><code>addHTMLHead($head)
  addScript($code, $region)
  addScriptUrl($url, $region)
  addStyle($code, $region)
  addStyleUrl($url, $region)
  appendBreadCrumb($breadCrumbs)
  appendCoreResources(&amp;$list)
  authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
  checkPermissionAddUser()
  clearResourceCache()
  cmsRootPath()
  createUser(&amp;$params, $mail)
  flush()
  getBestUFID($user = NULL)
  getBestUFUniqueIdentifier($user = NULL)
  getDefaultBlockLocation()
  getDefaultSiteSettings($dir)
  getLoggedInUfID()
  getLoggedInUniqueIdentifier()
  getLoginDestination(&amp;$form)
  getModules()
  getTimeZoneOffset()
  getTimeZoneString()
  getUFLocale()
  getUfId($username)
  getUniqueIdentifierFromUserObject($user)
  getUser($contactID)
  getUserIDFromUserObject($user)
  getUserRecordUrl($contactID)
  getVersion()
  isUserLoggedIn()
  languageNegotiationURL(
  loadUser($user)
  logger($message)
  </code><strike>logout()</strike><code>
  mapConfigToSSL()
  outputError($content)
  permissionDenied()
  postURL($action)
  resetBreadCrumb()
  setMessage($message)
  setMySQLTimeZone()
  setTitle($title, $pageTitle = NULL)
  setUserSession($data)
  theme(&amp;$content, $print = FALSE, $maintenance = FALSE)
  updateCMSName($ufID, $email)
  updateCategories()
  url($path = NULL, $query = NULL, $absolute = FALSE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE) 
  userLoginFinalize($params = array())
  </code></p>
  
  <p>(note a few of these are marked as only be called in certain contexts)</p>
  
Tags: <extension><php><coding-standards>
Title: best practice for using core base functions (CRM_Utils_System_Base) from an extension?
ThreadText: # best practice for using core base functions (CRM_Utils_System_Base) from an extension?
  
  (Asked by: username_0 on 2016-12-29)
  
  [`CRM_Utils_System_Base`](https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/System/Base.php) defines a great set of key functions that look like they should work in any system.
  
  What is the correct way to access this functionality within an extension?
  
  FYI these are the classes public methods:
  
  `addHTMLHead($head)
  addScript($code, $region)
  addScriptUrl($url, $region)
  addStyle($code, $region)
  addStyleUrl($url, $region)
  appendBreadCrumb($breadCrumbs)
  appendCoreResources(&$list)
  authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL)
  checkPermissionAddUser()
  clearResourceCache()
  cmsRootPath()
  createUser(&$params, $mail)
  flush()
  getBestUFID($user = NULL)
  getBestUFUniqueIdentifier($user = NULL)
  getDefaultBlockLocation()
  getDefaultSiteSettings($dir)
  getLoggedInUfID()
  getLoggedInUniqueIdentifier()
  getLoginDestination(&$form)
  getModules()
  getTimeZoneOffset()
  getTimeZoneString()
  getUFLocale()
  getUfId($username)
  getUniqueIdentifierFromUserObject($user)
  getUser($contactID)
  getUserIDFromUserObject($user)
  getUserRecordUrl($contactID)
  getVersion()
  isUserLoggedIn()
  languageNegotiationURL(
  loadUser($user)
  logger($message)`logout()`mapConfigToSSL()
  outputError($content)
  permissionDenied()
  postURL($action)
  resetBreadCrumb()
  setMessage($message)
  setMySQLTimeZone()
  setTitle($title, $pageTitle = NULL)
  setUserSession($data)
  theme(&$content, $print = FALSE, $maintenance = FALSE)
  updateCMSName($ufID, $email)
  updateCategories()
  url($path = NULL, $query = NULL, $absolute = FALSE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE)
  userLoginFinalize($params = array())`
  
  (note a few of these are marked as only be called in certain contexts)
  
  **Tags:** extension, php, coding-standards
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2017-01-01. Score: 3 | Accepted answer
  
  This base class is not intended to be used by itself, but extended based on the CMS. CiviCRM will automatically give you an instance of the correct object which extends this base class. You can access it via the CRM_Utils_System static methods. For example:
  CRM_Utils_System::appendBreadCrumb($something);
  
  or
  CRM_Utils_System::isUserLoggedIn();
  
  > **Comments:**
  > **username_2**: Cool @username_0 don't forget to mark this answer correct.  
  
  ---
  
  ### Answer by username_1 on 2016-12-29. Score: 2
  
  It's probably easier to answer based on a specific need rather than your more generic "hey, found a stash of toys, can I play with them? ;)"
  They are a few that you shouldn't use directly but use the more specific functions, so instead of:
  addHTMLHead($head)
  addScript($code, $region)
  addScriptUrl($url, $region)
  addStyle($code, $region)
  addStyleUrl($url, $region)
  
  it's more common/recommended to use CRM_Core_Resources 
  CRM_Core_Resources::singleton()
  ->addScriptFile(...)
  ->addStyleFile(...)
  ...
  
  > **Comments:**
  > **username_0**: hey thanks @username_1! good point, but that is one cool box of toys!! I guess I'm hunting for a generic pattern of accessing this interface from the context of an extension author (I wish I'd known about some of them years ago!)  
  
  ---
  
  ### Answer by username_0 on 2016-12-29. Score: 0
  
  There is this example:
  `CRM/Utils/System.php-1503- /**
  CRM/Utils/System.php-1504- * Check if user is logged in.
  CRM/Utils/System.php-1505- *
  CRM/Utils/System.php-1506- * @return bool
  CRM/Utils/System.php-1507- */
  CRM/Utils/System.php:1508: public static function isUserLoggedIn() {
  CRM/Utils/System.php-1509- $config = CRM_Core_Config::singleton();
  CRM/Utils/System.php:1510: return $config->userSystem->isUserLoggedIn();
  CRM/Utils/System.php-1511- }`
  
  > **Comments:**
  > **username_0**: answered my own question as a "best guess" on the basis someone who knows more may wish to post a better answer!  
  
  ---
  
  