INFRA-132 - Trailing commas for multiline arrays
[civicrm-core.git] / CRM / Core / Region.php
index c3b25ec0e54702ea2cd8b3a768d9acde14bdf8f7..417b1ecaa1e5d3fde86df153c2242fa553c1b7b9 100644 (file)
@@ -10,11 +10,12 @@ class CRM_Core_Region {
    * Obtain the content for a given region
    *
    * @param string $name
-   * @param bool $autocreate whether to automatically create an empty region
+   * @param bool $autocreate
+   *   Whether to automatically create an empty region.
    * @return CRM_Core_Region
    */
-  static function &instance($name, $autocreate = TRUE) {
-    if ( $autocreate && ! isset( self::$_instances[$name] ) ) {
+  public static function &instance($name, $autocreate = TRUE) {
+    if ($autocreate && ! isset(self::$_instances[$name])) {
       self::$_instances[$name] = new CRM_Core_Region($name);
     }
     return self::$_instances[$name];
@@ -41,10 +42,13 @@ class CRM_Core_Region {
    */
   var $_isSorted;
 
+  /**
+   * @param string $name
+   */
   public function __construct($name) {
     // Templates injected into regions should normally be file names, but sometimes inline notation is handy.
     require_once 'CRM/Core/Smarty/resources/String.php';
-    civicrm_smarty_register_string_resource( );
+    civicrm_smarty_register_string_resource();
 
     $this->_name = $name;
     $this->_snippets = array();
@@ -80,7 +84,8 @@ class CRM_Core_Region {
    * Note: This function does not perform any extra encoding of markup, script code, or etc. If
    * you're passing in user-data, you must clean it yourself.
    *
-   * @param $snippet array; keys:
+   * @param $snippet
+   *   Array; keys:.
    *   - type: string (auto-detected for markup, template, callback, script, scriptUrl, jquery, style, styleUrl)
    *   - name: string, optional
    *   - weight: int, optional; default=1
@@ -94,6 +99,8 @@ class CRM_Core_Region {
    *   - jquery: string, Javascript code which runs inside a jQuery(function($){...}); block
    *   - style: string, CSS code
    *   - styleUrl: string, URL of a CSS file
+   *
+   * @return array
    */
   public function add($snippet) {
     static $types = array('markup', 'template', 'callback', 'scriptUrl', 'script', 'jquery', 'style', 'styleUrl');
@@ -115,16 +122,25 @@ class CRM_Core_Region {
     if (!isset($snippet['name'])) {
       $snippet['name'] = count($this->_snippets);
     }
-    $this->_snippets[ $snippet['name'] ] = $snippet;
+    $this->_snippets[$snippet['name']] = $snippet;
     $this->_isSorted = FALSE;
     return $snippet;
   }
 
+  /**
+   * @param string $name
+   * @param $snippet
+   */
   public function update($name, $snippet) {
     $this->_snippets[$name] = array_merge($this->_snippets[$name], $snippet);
     $this->_isSorted = FALSE;
   }
 
+  /**
+   * @param string $name
+   *
+   * @return mixed
+   */
   public function &get($name) {
     return @$this->_snippets[$name];
   }
@@ -132,8 +148,10 @@ class CRM_Core_Region {
   /**
    * Render all the snippets in a region
    *
-   * @param string $default HTML, the initial content of the region
-   * @param bool $allowCmsOverride allow CMS to override rendering of region
+   * @param string $default
+   *   HTML, the initial content of the region.
+   * @param bool $allowCmsOverride
+   *   Allow CMS to override rendering of region.
    * @return string, HTML
    */
   public function render($default, $allowCmsOverride = TRUE) {
@@ -155,25 +173,29 @@ class CRM_Core_Region {
       if ($snippet['disabled']) {
         continue;
       }
-      switch($snippet['type']) {
+      switch ($snippet['type']) {
         case 'markup':
           $html .= $snippet['markup'];
           break;
+
         case 'template':
           $tmp = $smarty->get_template_vars('snippet');
           $smarty->assign('snippet', $snippet);
           $html .= $smarty->fetch($snippet['template']);
           $smarty->assign('snippet', $tmp);
           break;
+
         case 'callback':
           $args = isset($snippet['arguments']) ? $snippet['arguments'] : array(&$snippet, &$html);
           $html .= call_user_func_array($snippet['callback'], $args);
           break;
+
         case 'scriptUrl':
           if (!$allowCmsOverride || !$cms->addScriptUrl($snippet['scriptUrl'], $this->_name)) {
             $html .= sprintf("<script type=\"text/javascript\" src=\"%s\">\n</script>\n", $snippet['scriptUrl']);
           }
           break;
+
         case 'jquery':
           $snippet['script'] = sprintf("CRM.\$(function(\$) {\n%s\n});", $snippet['jquery']);
           // no break - continue processing as script
@@ -182,44 +204,62 @@ class CRM_Core_Region {
             $html .= sprintf("<script type=\"text/javascript\">\n%s\n</script>\n", $snippet['script']);
           }
           break;
+
         case 'styleUrl':
           if (!$allowCmsOverride || !$cms->addStyleUrl($snippet['styleUrl'], $this->_name)) {
             $html .= sprintf("<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\"/>\n", $snippet['styleUrl']);
           }
           break;
+
         case 'style':
           if (!$allowCmsOverride || !$cms->addStyle($snippet['style'], $this->_name)) {
             $html .= sprintf("<style type=\"text/css\">\n%s\n</style>\n", $snippet['style']);
           }
           break;
+
         default:
           require_once 'CRM/Core/Error.php';
-          CRM_Core_Error::fatal( ts( 'Snippet type %1 is unrecognized',
-                     array( 1 => $snippet['type'] ) ) );
+          CRM_Core_Error::fatal(ts('Snippet type %1 is unrecognized',
+                     array(1 => $snippet['type'])));
       }
     }
     return $html;
   }
 
-  static function _cmpSnippet($a, $b) {
-    if ($a['weight'] < $b['weight']) return -1;
-    if ($a['weight'] > $b['weight']) return 1;
+  /**
+   * @param $a
+   * @param $b
+   *
+   * @return int
+   */
+  public static function _cmpSnippet($a, $b) {
+    if ($a['weight'] < $b['weight']) {
+      return -1;
+    }
+    if ($a['weight'] > $b['weight']) {
+      return 1;
+    }
     // fallback to name sort; don't really want to do this, but it makes results more stable
-    if ($a['name'] < $b['name']) return -1;
-    if ($a['name'] > $b['name']) return 1;
+    if ($a['name'] < $b['name']) {
+      return -1;
+    }
+    if ($a['name'] > $b['name']) {
+      return 1;
+    }
     return 0;
   }
 
   /**
    * Add block of static HTML to a region
    *
-   * @param string $markup HTML
+   * @param string $markup
+   *   HTML.
    *
   public function addMarkup($markup) {
-    return $this->add(array(
-      'type' => 'markup',
-      'markup' => $markup,
-    ));
+  return $this->add(array(
+  'type' => 'markup',
+  'markup' => $markup,
+  ));
   }
 
   /**
@@ -227,27 +267,29 @@ class CRM_Core_Region {
    *
    * Note: File is not evaluated until the page is rendered
    *
-   * @param string $template path to the Smarty template file
+   * @param string $template
+   *   Path to the Smarty template file.
    *
   public function addTemplate($template) {
-    return $this->add(array(
-      'type' => 'template',
-      'template' => $template,
-    ));
+  return $this->add(array(
+  'type' => 'template',
+  'template' => $template,
+  ));
   }
 
   /**
    * Use a callback function to extend a region
    *
    * @param mixed $callback
-   * @param array $arguments optional, array of parameters for callback; if omitted, the default arguments are ($snippetSpec, $html)
+   * @param array $arguments
+   *   Optional, array of parameters for callback; if omitted, the default arguments are ($snippetSpec, $html).
    *
   public function addCallback($callback, $arguments = FALSE) {
-    return $this->add(array(
-      'type' => 'callback',
-      'callback' => $callback,
-      'arguments' => $arguments,
-    ));
+  return $this->add(array(
+  'type' => 'callback',
+  'callback' => $callback,
+  'arguments' => $arguments,
+  ));
   }
   */
 }