From 7c6fc238739c1431d42f067dda31137c84a24497 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 4 Jan 2013 11:27:51 -0500
Subject: [PATCH] Simplified use of theme resource container by making it a
 service.

---
 module/VuFind/config/module.config.php        |  1 +
 .../VuFind/src/VuFind/Theme/Initializer.php   | 21 +++++++------------
 .../Theme/Root/Helper/HeadThemeResources.php  | 10 ++++-----
 module/VuFind/src/VuFind/Theme/Tools.php      | 19 -----------------
 4 files changed, 13 insertions(+), 38 deletions(-)

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index d975fafd08d..221011fa212 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -494,6 +494,7 @@ $config = array(
             'VuFind\SearchSpecsReader' => 'VuFind\Config\SearchSpecsReader',
             'VuFind\SessionManager' => 'Zend\Session\SessionManager',
             'VuFind\WorldCatUtils' => 'VuFind\Connection\WorldCatUtils',
+            'VuFindTheme\ResourceContainer' => 'VuFind\Theme\ResourceContainer',
         ),
         'initializers' => array(
             array('VuFind\ServiceManager\Initializer', 'initInstance'),
diff --git a/module/VuFind/src/VuFind/Theme/Initializer.php b/module/VuFind/src/VuFind/Theme/Initializer.php
index 8613a4ec7a1..52bdc0218e4 100644
--- a/module/VuFind/src/VuFind/Theme/Initializer.php
+++ b/module/VuFind/src/VuFind/Theme/Initializer.php
@@ -57,13 +57,6 @@ class Initializer
      */
     protected $event;
 
-    /**
-     * Theme resource container
-     *
-     * @var ResourceContainer
-     */
-    protected $resourceContainer;
-
     /**
      * Top-level service manager
      *
@@ -96,9 +89,6 @@ class Initializer
         // Get base directory from tools object:
         $this->tools = $this->serviceManager->get('VuFindTheme\Tools');
         $this->baseDir = $this->tools->getBaseDir();
-
-        // Grab the resource manager for tracking CSS, JS, etc.:
-        $this->resourceContainer = $this->tools->getResourceContainer();
     }
 
     /**
@@ -315,6 +305,9 @@ class Initializer
     {
         $templatePathStack = array();
 
+        // Grab the resource manager for tracking CSS, JS, etc.:
+        $resources = $this->serviceManager->get('VuFindTheme\ResourceContainer');
+
         // Apply the loaded theme settings in reverse for proper inheritance:
         foreach ($themes as $key=>$currentThemeInfo) {
             if ($helperNS = $currentThemeInfo->get('helper_namespace')) {
@@ -328,20 +321,20 @@ class Initializer
 
             // Add CSS and JS dependencies:
             if ($css = $currentThemeInfo->get('css')) {
-                $this->resourceContainer->addCss($css);
+                $resources->addCss($css);
             }
             if ($js = $currentThemeInfo->get('js')) {
-                $this->resourceContainer->addJs($js);
+                $resources->addJs($js);
             }
 
             // Select encoding:
             if ($encoding = $currentThemeInfo->get('encoding')) {
-                $this->resourceContainer->setEncoding($encoding);
+                $resources->setEncoding($encoding);
             }
 
             // Select favicon:
             if ($favicon = $currentThemeInfo->get('favicon')) {
-                $this->resourceContainer->setFavicon($favicon);
+                $resources->setFavicon($favicon);
             }
         }
 
diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php
index 9e623f6a31d..fa8fb9229a2 100644
--- a/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php
+++ b/module/VuFind/src/VuFind/Theme/Root/Helper/HeadThemeResources.php
@@ -40,13 +40,13 @@ use Zend\View\Helper\AbstractHelper;
 class HeadThemeResources extends AbstractServiceLocator
 {
     /**
-     * Get the theme tools.
+     * Get the theme resource container.
      *
-     * @return \VuFind\Theme\Tools
+     * @return \VuFind\Theme\ResourceContainer
      */
-    public function getThemeTools()
+    public function getThemeResourceContainer()
     {
-        return $this->getServiceLocator()->get('VuFindTheme\Tools');
+        return $this->getServiceLocator()->get('VuFindTheme\ResourceContainer');
     }
 
     /**
@@ -56,7 +56,7 @@ class HeadThemeResources extends AbstractServiceLocator
      */
     public function __invoke()
     {
-        $resourceContainer = $this->getThemeTools()->getResourceContainer();
+        $resourceContainer = $this->getThemeResourceContainer();
 
         // Set up encoding:
         $headMeta = $this->getView()->plugin('headmeta');
diff --git a/module/VuFind/src/VuFind/Theme/Tools.php b/module/VuFind/src/VuFind/Theme/Tools.php
index 5a3e002ec5f..48aa978670b 100644
--- a/module/VuFind/src/VuFind/Theme/Tools.php
+++ b/module/VuFind/src/VuFind/Theme/Tools.php
@@ -60,13 +60,6 @@ class Tools
      */
     protected $safeTheme;
 
-    /**
-     * Resource container
-     *
-     * @var ResourceContainer
-     */
-    protected $resourceContainer;
-
     /**
      * Theme configuration
      *
@@ -83,7 +76,6 @@ class Tools
     {
         $this->baseDir = $baseDir;
         $this->currentTheme = $this->safeTheme = $safeTheme;
-        $this->resourceContainer = new ResourceContainer();
     }
 
     /**
@@ -96,17 +88,6 @@ class Tools
         return $this->baseDir;
     }
 
-    /**
-     * Get the container used for handling public resources for themes
-     * (CSS, JS, etc.)
-     *
-     * @return ResourceContainer
-     */
-    public function getResourceContainer()
-    {
-        return $this->resourceContainer;
-    }
-
     /**
      * Get the configuration file for the specified theme.
      *
-- 
GitLab