Updated class and class method names to be compliant with spec
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 22 Mar 2019 19:41:37 +0000 (15:41 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 22 Mar 2019 19:42:56 +0000 (15:42 -0400)
Also fixes problem with use of list() method with PHP 5

classes/scriptRegistry.php
index.php
setup/registerAdminScriptStyle.php
setup/registerFrontScriptStyle.php

index 9def26b..cfa9711 100644 (file)
@@ -21,9 +21,9 @@
  * The intent is to have plugins/add-ons supply information on scripts and styles that might be
  * loaded in a 'scripts.php' file in the 'setup' directory so that consistency can be maintained and
  * duplicates can be avoided. Models then simply ask to have a script or style enqueued by
- * specifying the "handle" of that script using the enqueue() method.
+ * specifying the "handle" of that script using the enqueueScripts() method.
  *
- * The 'scripts.php' files should be exclusively a set of calls to the add() method
+ * The 'scripts.php' files should be exclusively a set of calls to the addScript() method
  *
  * @category  CommonApps
  * @package   Registry
@@ -33,7 +33,7 @@
  * @version   Release: 1.0
  * @link      <>
  */
-abstract class glmScriptType
+abstract class GlmScriptType
 {
     const Unknown = 0;
     const Script = 1;
@@ -41,7 +41,7 @@ abstract class glmScriptType
 
 }
 
-class glmScript
+class GlmScript
 {
 
     /**
@@ -49,7 +49,7 @@ class glmScript
      *
      * @var string  $handle        Required handle (name) for this script
      * @var string  $src           Required source URL of script
-     * @var int     $type          Required type enumerated (see glmScriptType above)
+     * @var int     $type          Required type enumerated (see GlmScriptType above)
      * @var array   $deps          Optional array of handles for scripts this script depends on
      * @var boolean $in_footer     Optional flag for enqueue before </body> tag
      * @var string  $media         Optional media types for styles (i.e. 'all', 'print', 'screen'...)
@@ -62,7 +62,7 @@ class glmScript
      */
     public $handle = '';
     public $src = '';
-    public $type = glmScriptType::Unknown;
+    public $type = GlmScriptType::Unknown;
     public $deps = false;
     public $in_footer = false;
     public $media = 'all';
@@ -74,7 +74,7 @@ class glmScript
     public $fullHandle = '';
 
     /**
-     * This constructor takes an array of parameters and creates a glmScript object from that.
+     * This constructor takes an array of parameters and creates a GlmScript object from that.
      * Not all parameters need to be supplied, only those specified as such above. Defaults will be
      * used for parameters that are not suplied.
      *
@@ -92,7 +92,7 @@ class glmScript
                     $this->$key = $val;
                 } else {
                     trigger_error(
-                        "glmScriptRegistry invalid glmScipt object parameter: Key = $key, Value = $val",
+                        "GlmScriptRegistry invalid glmScipt object parameter: Key = $key, Value = $val",
                         E_USER_NOTICE );
                 }
             }
@@ -122,7 +122,7 @@ function glmScriptRegistryTagFilter( $tag, $fullHandle, $src )
     }
 
 
-    $script = glmScriptRegistry::find( glmScriptType::Script, $fullHandle);
+    $script = GlmScriptRegistry::findScript( GlmScriptType::Script, $fullHandle );
 
     if ( $script ) {
 
@@ -149,10 +149,10 @@ function glmScriptRegistryTagFilter( $tag, $fullHandle, $src )
 // Add the above function as 'script_loader_tag' filter
 add_filter( 'script_loader_tag', 'glmScriptRegistryTagFilter', 10, 3 );
 
-class glmScriptRegistry
+class GlmScriptRegistry
 {
 
-    // Lists of glmScript objects
+    // Lists of GlmScript objects
     private static $_scripts = array();
     private static $_styles = array();
 
@@ -164,32 +164,32 @@ class glmScriptRegistry
      *
      * @return object New script values array or false if failure
      */
-    static public function add( $scriptVals )
+    static public function addScript( $scriptVals )
     {
 
         // Make sure an array has been submitted
         if ( !is_array( $scriptVals ) || !count( $scriptVals ) ) {
             trigger_error(
-                'glmScriptRegistry add(): No data supplied or not array!',
+                'GlmScriptRegistry addScript(): No data supplied or not array!',
                 E_USER_NOTICE );
             return false;
         }
 
         // Create an object with the submitted script values
-        $script = new glmScript( $scriptVals );
+        $script = new GlmScript( $scriptVals );
 
         // Check if handle not supplied
         if ( trim( $script->handle ) == '' ) {
             trigger_error(
-                'glmScriptRegistry add(): Required "handle" not supplied!',
+                'GlmScriptRegistry addScript(): Required "handle" not supplied!',
                 E_USER_NOTICE );
             return false;
         }
 
         // Check if file type is supplied
-        if ( trim( $script->type ) == glmScriptType::Unknown ) {
+        if ( trim( $script->type ) == GlmScriptType::Unknown ) {
             trigger_error(
-                'glmScriptRegistry add(): Required "type" not supplied or invalid!',
+                'GlmScriptRegistry addScript(): Required "type" not supplied or invalid!',
                 E_USER_NOTICE );
             return false;
         }
@@ -197,7 +197,7 @@ class glmScriptRegistry
         // Check if src is supplied
         if ( trim( $script->src ) == '' ) {
             trigger_error(
-                'glmScriptRegistry add(): Required "src" not supplied!',
+                'GlmScriptRegistry addScript(): Required "src" not supplied!',
                 E_USER_NOTICE );
             return false;
         }
@@ -205,7 +205,7 @@ class glmScriptRegistry
         // Check if plugin is supplied
         if ( trim( $script->plugin ) == '' ) {
             trigger_error(
-                'glmScriptRegistry add(): Required "plugin" not supplied!',
+                'GlmScriptRegistry addScript(): Required "plugin" not supplied!',
                 E_USER_NOTICE );
             return false;
         }
@@ -213,7 +213,7 @@ class glmScriptRegistry
         // Check if version is supplied
         if ( trim( $script->src ) == '' ) {
             trigger_error(
-                'glmScriptRegistry add(): Required "version" not supplied!',
+                'GlmScriptRegistry addScript(): Required "version" not supplied!',
                 E_USER_NOTICE );
             return false;
         }
@@ -221,7 +221,7 @@ class glmScriptRegistry
         // Add script to registry list
         switch ( $script->type ) {
 
-            case glmScriptType::Script:
+            case GlmScriptType::Script:
 
                 // If there's any already listed, check for duplicates
                 if ( count( self::$_scripts ) ) {
@@ -229,7 +229,7 @@ class glmScriptRegistry
                     // Check for duplicate handle
                     if ( isset( self::$_scripts[$script->handle] ) ) {
                         trigger_error(
-                            'glmScriptRegistry add(): Duplicate script "handle" submitted! (' .
+                            'GlmScriptRegistry addScript(): Duplicate script "handle" submitted! (' .
                             $script->handle . ')', E_USER_NOTICE );
                         return false;
                     }
@@ -238,7 +238,7 @@ class glmScriptRegistry
                     foreach ( self::$_scripts as $handle=>$s ) {
                         if ( $script->src == $s->src ) {
                             trigger_error(
-                                'glmScriptRegistry add(): Duplicate script "src" submitted! (' .
+                                'GlmScriptRegistry addScript(): Duplicate script "src" submitted! (' .
                                 $s->src . ')', E_USER_NOTICE );
                             return false;
                         }
@@ -249,13 +249,13 @@ class glmScriptRegistry
 
                 if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
                     trigger_error(
-                        "glmScriptRegistry add(): script handle added = " .
+                        "GlmScriptRegistry addScript(): script handle added = " .
                         $script->handle, E_USER_NOTICE );
                 }
 
                 break;
 
-            case glmScriptType::Style:
+            case GlmScriptType::Style:
 
                 // If there's any already listed, check for duplicates
                 if ( count( self::$_styles ) ) {
@@ -263,7 +263,7 @@ class glmScriptRegistry
                     // Check for duplicate handle
                     if ( isset( self::$_styles[$script->handle] ) ) {
                         trigger_error(
-                            'glmScriptRegistry add(): Duplicate style "handle" submitted! (' .
+                            'GlmScriptRegistry addScript(): Duplicate style "handle" submitted! (' .
                             $script->handle . ')', E_USER_NOTICE );
                         return false;
                     }
@@ -272,7 +272,7 @@ class glmScriptRegistry
                     foreach ( self::$_scripts as $handle=>$s ) {
                         if ( $script->src == $s->src ) {
                             trigger_error(
-                                'glmScriptRegistry add(): Duplicate style "src" submitted! (' .
+                                'GlmScriptRegistry addScript(): Duplicate style "src" submitted! (' .
                                 $s->src . ')', E_USER_NOTICE );
                             return false;
                         }
@@ -283,16 +283,16 @@ class glmScriptRegistry
 
                 if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
                     trigger_error(
-                        "glmScriptRegistry add(): style handle added = " .
+                        "GlmScriptRegistry addScript(): style handle added = " .
                         $script->handle, E_USER_NOTICE );
                 }
 
                 break;
 
-            case glmScriptType::Unknown:
+            case GlmScriptType::Unknown:
                 defaut:
                 trigger_error(
-                    "glmScriptRegistry Script Type Unknown: Plugin = $s->plugin, Script = $s->handle",
+                    "GlmScriptRegistry Script Type Unknown: Plugin = $s->plugin, Script = $s->handle",
                     E_USER_NOTICE );
                 break;
         }
@@ -302,21 +302,21 @@ class glmScriptRegistry
     /**
      * Find script using fullHandle value
      *
-     * @param int    $type       Type - enumerated (see glmScriptType above)
+     * @param int    $type       Type - enumerated (see GlmScriptType above)
      * @param string $fullHandle Full handle for script
      *
-     * @return glmScriptType Script object or false if not found
+     * @return GlmScriptType Script object or false if not found
      */
-    static public function find( $type, $fullHandle )
+    static public function findScript( $type, $fullHandle )
     {
 
         switch ( $type ) {
 
-            case glmScriptType::Script:
+            case GlmScriptType::Script:
 
                 // Try to find script using fullHandle field
-                if ( count( glmScriptRegistry::$_scripts ) ) {
-                    foreach ( glmScriptRegistry::$_scripts as $script ) {
+                if ( count( GlmScriptRegistry::$_scripts ) ) {
+                    foreach ( GlmScriptRegistry::$_scripts as $script ) {
                         if ( $script->fullHandle == $fullHandle ) {
                             return $script;
                         }
@@ -325,11 +325,11 @@ class glmScriptRegistry
 
                 break;
 
-            case glmScriptType::Style:
+            case GlmScriptType::Style:
 
                 // Try to find style using fullHandle field
-                if ( count( glmScriptRegistry::$_styles ) ) {
-                    foreach ( glmScriptRegistry::$_styles as $style ) {
+                if ( count( GlmScriptRegistry::$_styles ) ) {
+                    foreach ( GlmScriptRegistry::$_styles as $style ) {
                         if ( $style->fullHandle == $fullHandle ) {
                             return $style;
                         }
@@ -352,7 +352,7 @@ class glmScriptRegistry
      *
      * @return void
      */
-    static public function reset()
+    static public function resetScripts()
     {
 
         if ( count( self::$_scripts ) ) {
@@ -371,17 +371,17 @@ class glmScriptRegistry
     /**
      * Selectd a script to be enqueued
      *
-     * @param int    $type   Type - enumerated (see glmScriptType above)
+     * @param int    $type   Type - enumerated (see GlmScriptType above)
      * @param string $handle Handle of script to be enqueued
      *
      * @return boolean Success is true
      */
-    static public function select( $type, $handle )
+    static public function selectScript( $type, $handle )
     {
 
         switch ( $type ) {
 
-            case glmScriptType::Script:
+            case GlmScriptType::Script:
                 if ( isset( self::$_scripts[$handle] ) ) {
                     self::$_scripts[$handle]->enqueue = true;
                 } else {
@@ -389,7 +389,7 @@ class glmScriptRegistry
                 }
                 break;
 
-            case glmScriptType::Style:
+            case GlmScriptType::Style:
                 if ( isset( self::$_styles[$handle] ) ) {
                     self::$_styles[$handle]->enqueue = true;
                 } else {
@@ -397,7 +397,7 @@ class glmScriptRegistry
                 }
                 break;
 
-            case glmScriptType::Unknown:
+            case GlmScriptType::Unknown:
             default:
                 return false;
                 break;
@@ -410,7 +410,7 @@ class glmScriptRegistry
      *
      * @param boolean $enqueuedOnly Return only enqueued scripts and styles
      */
-    static public function list( $enqueuedOnly = false)
+    static public function listScripts( $enqueuedOnly = false)
     {
 
         // If not enqueued only, return entire list
@@ -451,7 +451,7 @@ class glmScriptRegistry
     /**
      * Enqueue listed scripts
      */
-    static public function enqueue()
+    static public function enqueueScripts()
     {
 
         // Scripts
@@ -475,7 +475,7 @@ class glmScriptRegistry
 
                     if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
                         trigger_error(
-                            "glmScriptRegistry enqueue(): handle = " . $handle .
+                            "GlmScriptRegistry enqueueScripts(): handle = " . $handle .
                             ', src = ' . $s->src . ', version = ' . $s->version,
                             E_USER_NOTICE );
                     }
@@ -500,7 +500,7 @@ class glmScriptRegistry
 
                     if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
                         trigger_error(
-                            "glmScriptRegistry enqueue(): handle = " . $handle,
+                            "GlmScriptRegistry enqueueScripts(): handle = " . $handle,
                             E_USER_NOTICE );
                     }
                 }
index 120dfa7..120cf8b 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -466,10 +466,10 @@ if ($glmMembersDatabaseDbVersion) {
 }
 
 /*
- *  Enqueue all scripts and styles registered with glmScriptRegistry
+ *  Enqueue all scripts and styles registered with GlmScriptRegistry
  */
 function glmEnqueueScripts() {
-    glmScriptRegistry::enqueue();
+    GlmScriptRegistry::enqueueScripts();
 }
 add_action('wp_footer', 'glmEnqueueScripts');
 
index 26ee514..cf5243c 100644 (file)
@@ -14,7 +14,7 @@
  */
 
 /**
- * This file registers scripts and styles with the glmScriptRegistry.
+ * This file registers scripts and styles with the GlmScriptRegistry.
  *
  * Scripts and Styles are added to the registry to ensure consistancy and avoid duplication.
  * This process only lists them in the registry. A further step of calling the enqueue()
@@ -28,7 +28,7 @@
  * it may be the same for a matching script and style (the plugin slug and type prefix the
  * 'handle' provided below to make them actually unique).
  *
- * int     type      Required type enumerated (see glmScriptType above)
+ * int     type      Required type enumerated (see GlmScriptType above)
  * string  handle    Required handle (name) for this script (no spaces or punctuation)
  *                      Handles must be unique for a particular type
  *                      A matching script and style may have the same handle
@@ -50,9 +50,9 @@
  *
  * Example - Please add multi-line comment above each with script src for reference
  *
- *  glmScriptRegistry::add(
+ *  GlmScriptRegistry::addScript(
  *      [
- *          'type' => glmScriptType::Script,
+ *          'type' => GlmScriptType::Script,
  *          'handle' => 'RegApp',
  *          'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js',
  *          'deps' => array(
index 8d9e3b0..bd36ffd 100644 (file)
@@ -14,7 +14,7 @@
  */
 
 /**
- * This file registers scripts and styles with the glmScriptRegistry.
+ * This file registers scripts and styles with the GlmScriptRegistry.
  *
  * Scripts and Styles are added to the registry to ensure consistancy and avoid duplication.
  * This process only lists them in the registry. A further step of calling the enqueue()
@@ -28,7 +28,7 @@
  * it may be the same for a matching script and style (the plugin slug and type prefix the
  * 'handle' provided below to make them actually unique).
  *
- * int     type      Required type enumerated (see glmScriptType above)
+ * int     type      Required type enumerated (see GlmScriptType above)
  * string  handle    Required handle (name) for this script (no spaces or punctuation)
  *                      Handles must be unique for a particular type
  *                      A matching script and style may have the same handle
@@ -50,9 +50,9 @@
  *
  * Example - Please add multi-line comment above each with script src for reference
  *
- *  glmScriptRegistry::add(
+ *  GlmScriptRegistry::addScript(
  *      [
- *          'type' => glmScriptType::Script,
+ *          'type' => GlmScriptType::Script,
  *          'handle' => 'RegApp',
  *          'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js',
  *          'deps' => array(
@@ -76,9 +76,9 @@
 /*
  * https://unpkg.com/leaflet@1.3.3/dist/leaflet.css
  */
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
     [
-        'type' => glmScriptType::Style,
+        'type' => GlmScriptType::Style,
         'handle' => 'Leaflet',
         'src' => 'https://unpkg.com/leaflet@1.3.3/dist/leaflet.css',
         'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
@@ -88,9 +88,9 @@ glmScriptRegistry::add(
 /*
  * https://unpkg.com/leaflet@1.3.3/dist/leaflet.js
  */
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
     [
-        'type' => glmScriptType::Script,
+        'type' => GlmScriptType::Script,
         'handle' => 'Leaflet',
         'src' => 'https://unpkg.com/leaflet@1.3.3/dist/leaflet.js',
         'in_footer' => true,
@@ -106,9 +106,9 @@ glmScriptRegistry::add(
  * {registrations}/js/Leaflet.loading/src/Control.Loading.css
  * NOTE - This file is actually in glm-member-db plugin. Need to move this at some point ****
  */
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
     [
-        'type' => glmScriptType::Style,
+        'type' => GlmScriptType::Style,
         'handle' => 'LeafletControlLoading',
         'src' => GLM_MEMBERS_PLUGIN_URL . 'js/Leaflet.loading/src/Control.Loading.css',
         'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
@@ -119,9 +119,9 @@ glmScriptRegistry::add(
  * GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL/js/Leaflet.loading/src/Control.Loading.js
  * NOTE - This file is actually in glm-member-db plugin. Need to move this at some point ****
  */
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
     [
-        'type' => glmScriptType::Script,
+        'type' => GlmScriptType::Script,
         'handle' => 'LeafletControlLoading',
         'src' => GLM_MEMBERS_PLUGIN_URL . 'js/Leaflet.loading/src/Control.Loading.js',
         'in_footer' => true,
@@ -132,9 +132,9 @@ glmScriptRegistry::add(
 /*
  * Google Maps API
  */
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
     [
-        'type' => glmScriptType::Script,
+        'type' => GlmScriptType::Script,
         'handle' => 'GoogleMapsAPI',
         'src' => 'https://maps.googleapis.com/maps/api/js?sensor=true&key=' .
         $this->config['settings']['google_maps_api_key'],