From 08393147c04b3df303d33177d2085e6da0a66d9d Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 22 Jun 2012 08:16:46 -0400
Subject: [PATCH] Began refactoring Theme class to separate initialization
 routines from generic tools.

---
 module/VuFind/src/VuFind/Bootstrap.php        |  8 ++-
 .../{Theme.php => Theme/Initializer.php}      | 22 ++++---
 module/VuFind/src/VuFind/Theme/Tools.php      | 65 +++++++++++++++++++
 3 files changed, 83 insertions(+), 12 deletions(-)
 rename module/VuFind/src/VuFind/{Theme.php => Theme/Initializer.php} (96%)
 create mode 100644 module/VuFind/src/VuFind/Theme/Tools.php

diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php
index dc8124aa92c..0c890f140e6 100644
--- a/module/VuFind/src/VuFind/Bootstrap.php
+++ b/module/VuFind/src/VuFind/Bootstrap.php
@@ -27,7 +27,7 @@
  */
 namespace VuFind;
 use VuFind\Config\Reader as ConfigReader,
-    VuFind\Theme,
+    VuFind\Theme\Initializer as ThemeInitializer,
     Zend\Mvc\MvcEvent;
 /**
  * VuFind Bootstrapper
@@ -74,12 +74,14 @@ class Bootstrap
         $events = $this->event->getApplication()->events();
 
         // Attach template injection configuration to the route event:
-        $events->attach('route', array('VuFind\Theme', 'configureTemplateInjection'));
+        $events->attach(
+            'route', array('VuFind\Theme\Initializer', 'configureTemplateInjection')
+        );
 
         // Attach remaining theme configuration to the dispatch event:
         $config =& $this->config;
         $events->attach('dispatch', function($event) use ($config) {
-            $theme = new Theme($config, $event);
+            $theme = new ThemeInitializer($config, $event);
             $theme->init();
         });
     }
diff --git a/module/VuFind/src/VuFind/Theme.php b/module/VuFind/src/VuFind/Theme/Initializer.php
similarity index 96%
rename from module/VuFind/src/VuFind/Theme.php
rename to module/VuFind/src/VuFind/Theme/Initializer.php
index 1369cc30aef..315c5d06401 100644
--- a/module/VuFind/src/VuFind/Theme.php
+++ b/module/VuFind/src/VuFind/Theme/Initializer.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * VuFind Theme Handler
+ * VuFind Theme Initializer
  *
  * PHP version 5
  *
@@ -25,17 +25,16 @@
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org   Main Site
  */
-namespace VuFind;
+namespace VuFind\Theme;
 use VuFind\Mobile,
     VuFind\Mvc\View\InjectTemplateListener,
     Zend\Config\Config,
     Zend\Config\Reader\Ini as IniReader,
     Zend\Mvc\MvcEvent,
-    Zend\Session\Container as SessionContainer,
     Zend\Stdlib\RequestInterface as Request;
 
 /**
- * VuFind Theme Handler
+ * VuFind Theme Initializer
  *
  * @category VuFind2
  * @package  Support_Classes
@@ -43,7 +42,7 @@ use VuFind\Mobile,
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org   Main Site
  */
-class Theme
+class Initializer
 {
     protected $autoLoader;
     protected $config;
@@ -56,14 +55,19 @@ class Theme
      *
      * @param Config   $config Configuration object
      * @param MvcEvent $event  Zend MVC Event object
+     * @param string   $tools  Name of Tools class
      */
     public function __construct(Config $config, MvcEvent $event,
-        string $baseDir = null
+        string $tools = null
     ) {
+        // If no tools class name was passed in, use a default:
+        if (is_null($tools)) {
+            $tools = 'VuFind\Theme\Tools';
+        }
+
         $this->config = $config;
         $this->event = $event;
-        $this->baseDir = empty($baseDir)
-            ? APPLICATION_PATH . '/themes/vufind' : $baseDir;
+        $this->baseDir = call_user_func(array($tools, 'getBaseDir'));
 
         // Create a class loader for helper management:
         $this->autoLoader = $this->getAutoloader();
@@ -72,7 +76,7 @@ class Theme
         $this->serviceManager = $this->event->getApplication()->getServiceManager();
 
         // Set up a session namespace for storing theme settings:
-        $this->session = new SessionContainer('Theme');
+        $this->session = call_user_func(array($tools, 'getPersistenceContainer'));
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Theme/Tools.php b/module/VuFind/src/VuFind/Theme/Tools.php
new file mode 100644
index 00000000000..9e06b70a065
--- /dev/null
+++ b/module/VuFind/src/VuFind/Theme/Tools.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * VuFind Theme Support Methods
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2010.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * @category VuFind2
+ * @package  Support_Classes
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org   Main Site
+ */
+namespace VuFind\Theme;
+use Zend\Session\Container as SessionContainer;
+
+/**
+ * VuFind Theme Support Methods
+ *
+ * @category VuFind2
+ * @package  Support_Classes
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     http://vufind.org   Main Site
+ */
+class Tools
+{
+    /**
+     * Get the base directory for themes.
+     *
+     * @return string
+     */
+    public static function getBaseDir()
+    {
+        return APPLICATION_PATH . '/themes/vufind';
+    }
+
+    /**
+     * Get the container used for persisting session-related settings.
+     *
+     * @return SessionContainer
+     */
+    public static function getPersistenceContainer()
+    {
+        static $container = false;
+        if (!$container) {
+            $container = new SessionContainer('Theme');
+        }
+        return $container;
+    }
+}
\ No newline at end of file
-- 
GitLab