There's no reason to make BSFunctions use a singleton. Switching it to be a purely...
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 5 Jan 2009 03:33:13 +0000 (19:33 -0800)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 5 Jan 2009 03:33:13 +0000 (19:33 -0800)
* Functions.php: Made all the ivars static
(BSFunctions::_instance): Removed
(BSFunctions::set_cookie_path): Use new static ivar
(BSFunctions::set_cookie_domain): ditto
(BSFunctions::set_cookie_timeout): ditto
(BSFunctions::cookie): ditto

Functions.php

index 92195b5af25427cbfcacc61e39518f905ea79be0..8489a6cde4d8f79e1119b795eeb74b77247cbb07 100644 (file)
@@ -28,8 +28,8 @@
 /**
  * Functions
  *
- * This is a bunch of static functions. This class is singleton so it
- * can store data while remaining static.
+ * This is a bunch of static functions wrapped in a class for modularity and
+ * namespace collisions.
  *
  * @author             Blue Static
  * @copyright  Copyright (c)2005 - 2009, Blue Static
  */
 class BSFunctions
 {
-       /**
-        * Singleton instance
-        * @var object
-        */
-       private static $instance;
-       
        /**
         * Cookie path
         * @var string
         */
-       private $cookiePath = '/';
+       private static $cookiePath = '/';
        
        /**
         * Cookie domain setting
         * @var string
         */
-       private $cookieDomain = '';
+       private static $cookieDomain = '';
        
        /**
         * Cookie expiration time
         * @var integer
         */
-       private $cookieTimeout = 900;
+       private static $cookieTimeout = 900;
        
        /**
         * Current swapped CSS class
@@ -69,23 +63,10 @@ class BSFunctions
        public static $cssClass = '';
        
        /**
-        * Constructor
-        */
-       private function __construct() {}
-       
-       /**
-        * Returns the shared instance for singleton
-        *
-        * @return      object  Shared instance
+        * Make class static
         */
-       private function _instance()
-       {
-               if (!self::$instance)
-               {
-                       self::$instance = new BSFunctions();
-               }               
-               return self::$instance;
-       }
+       private function __construct()
+       {}
        
        /**
         * Sets the cookie path
@@ -94,7 +75,7 @@ class BSFunctions
         */
        public static function set_cookie_path($path)
        {
-               self::_instance()->cookiePath = $path;
+               self::$cookiePath = $path;
        }
        
        /**
@@ -104,7 +85,7 @@ class BSFunctions
         */
        public static function set_cookie_domain($domain)
        {
-               self::_instance()->cookieDomain = $domain;
+               self::$cookieDomain = $domain;
        }
        
        /**
@@ -114,7 +95,7 @@ class BSFunctions
         */
        public static function set_cookie_timeout($timeout)
        {
-               self::_instance()->cookieTimeout = intval($timeout);
+               self::$cookieTimeout = intval($timeout);
        }
        
        /**
@@ -129,7 +110,7 @@ class BSFunctions
                // expire the cookie
                if ($value === false)
                {
-                       setcookie($name, $value, time() - (2 * self::_instance()->cookieTimeout), self::_instance()->cookiePath, self::_instance()->cookieDomain);
+                       setcookie($name, $value, time() - (2 * self::$cookieTimeout), self::$cookiePath, self::$cookieDomain);
                }
                // set the cookie
                else
@@ -140,10 +121,10 @@ class BSFunctions
                        }
                        else
                        {
-                               $expire = time() + self::_instance()->cookieTimeout;
+                               $expire = time() + self::$cookieTimeout;
                        }
                        
-                       setcookie($name, $value, $expire, self::_instance()->cookiePath, self::_instance()->cookieDomain);
+                       setcookie($name, $value, $expire, self::$cookiePath, self::$cookieDomain);
                }
        }