Work on setting up configRegistry
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 22 Apr 2019 20:38:47 +0000 (16:38 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 22 Apr 2019 20:38:47 +0000 (16:38 -0400)
New class for config registry

classes/configRegistry.php [new file with mode: 0644]
index.php
models/admin/management/index.php

diff --git a/classes/configRegistry.php b/classes/configRegistry.php
new file mode 100644 (file)
index 0000000..8055e28
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+namespace GlmAssociate\Config;
+/**
+ * configRegistry.php
+ *
+ * PHP version 5.2
+ *
+ * @category  Classes
+ * @package   Config Registry
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2019 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: $Id$
+ * @link      <>
+ */
+
+/**
+ * configRegistry.php class to hold objects for access anywhere. Think of the Registry
+ * as a key/value store. With the key being an identifier for an instance of an
+ * object, and the value being the instance itself.
+ *
+ * @category  CommonApps
+ * @package   Registry
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2019 Gaslight Media
+ * @license   Gaslight Media
+ * @version   Release: 1.0
+ * @link      <>
+ */
+class GlmConfig
+{
+    private $_store;
+
+    public function __construct( $data )
+    {
+        $this->_store = $data;
+    }
+
+    public function getConfig()
+    {
+        return $this->_store;
+    }
+}
+
+class Registry
+{
+    static private $_store = array();
+
+    /**
+     * Add a object to the Registry::_store
+     *
+     * @param object $object Object
+     * @param object $name   Name of object key
+     *
+     * @return object
+     */
+    static public function add( $object, $name = null )
+    {
+        // Use the class name if no name given, simulates singleton
+        $name = ( !\is_null( $name ) ) ? $name: \get_class( $object );
+
+        \trigger_error( $name, E_USER_NOTICE );
+
+        $return = null;
+        if ( isset( self::$_store[$name] ) ) {
+            // Store the old object for returning
+            $return = self::$_store[$name];
+        }
+
+        self::$_store[$name] = $object;
+        return $return;
+    }
+
+    /**
+     * get the object from the Registry::_store
+     *
+     * @param type $name Name of the object key
+     *
+     * @return type
+     * @throws Exception
+     */
+    static public function get( $name )
+    {
+        if ( !self::contains( $name ) ) {
+            throw new \Exception( 'Object does not exist in registry' );
+        }
+
+        return self::$_store[$name];
+    }
+
+    /**
+     * Check to see if the Registry::_store contains the object
+     *
+     * @param type $name name of object key
+     *
+     * @return boolean
+     */
+    static public function contains( $name )
+    {
+        if ( !isset( self::$_store[$name] ) ) {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * Remove the object from the Registry::_store
+     *
+     * @param type $name name of object key
+     *
+     * @return void
+     */
+    static public function remove( $name )
+    {
+        if ( self::contains( $name ) ) {
+            unset( self::$_store[$name] );
+        }
+    }
+}
index 3edb0a7..85efac5 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -9,6 +9,8 @@
  * License: GPL2
  */
 
+require_once 'classes/configRegistry.php';
+use \GlmAssociate\Config as GlmConfig;
 /**
  * GLM Associate - Members Plugin
  * Index
@@ -936,3 +938,14 @@ if (GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE) {
     trigger_error("GLM Associate Index End: ".glmAssociateMemoryUsage()." - Start glm-member-db setup",E_USER_NOTICE);
 }
 
+// Add config to the Registry
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['addOns'] ), 'addOns' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['validActions'] ), 'validActions' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['shortcodes'] ), 'shortcodes' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['imageSizes'] ), 'imageSizes' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['states'] ), 'states' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['countries'] ), 'countries' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['settings'] ), 'settings' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['terms'] ), 'terms' );
+GlmConfig\Registry::add( new GlmConfig\GlmConfig( $config['loggedInUser'] ), 'loggedInUser' );
+
index 340fe80..093349e 100755 (executable)
@@ -1,4 +1,5 @@
 <?php
+use \GlmAssociate\Config as GlmConfig;
 
 /**
  * Gaslight Media Members Database
@@ -235,6 +236,9 @@ class GlmMembersAdmin_management_index extends GlmDataSettingsGeneral
             $settings_updated = false;
         }
 
+        $config = GlmConfig\Registry::get( 'settings' )->getConfig();
+        trigger_error( print_r( $config, true ), E_USER_NOTICE );
+
         wp_register_script( 'glm-api', GLM_MEMBERS_PLUGIN_BASE_URL . '/js/glmApiSettings.js' );
 
         wp_localize_script(