Skip to content
Snippets Groups Projects
Commit 08393147 authored by Demian Katz's avatar Demian Katz
Browse files

Began refactoring Theme class to separate initialization routines from generic tools.

parent cbbb6e90
No related merge requests found
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
*/ */
namespace VuFind; namespace VuFind;
use VuFind\Config\Reader as ConfigReader, use VuFind\Config\Reader as ConfigReader,
VuFind\Theme, VuFind\Theme\Initializer as ThemeInitializer,
Zend\Mvc\MvcEvent; Zend\Mvc\MvcEvent;
/** /**
* VuFind Bootstrapper * VuFind Bootstrapper
...@@ -74,12 +74,14 @@ class Bootstrap ...@@ -74,12 +74,14 @@ class Bootstrap
$events = $this->event->getApplication()->events(); $events = $this->event->getApplication()->events();
// Attach template injection configuration to the route event: // 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: // Attach remaining theme configuration to the dispatch event:
$config =& $this->config; $config =& $this->config;
$events->attach('dispatch', function($event) use ($config) { $events->attach('dispatch', function($event) use ($config) {
$theme = new Theme($config, $event); $theme = new ThemeInitializer($config, $event);
$theme->init(); $theme->init();
}); });
} }
......
<?php <?php
/** /**
* VuFind Theme Handler * VuFind Theme Initializer
* *
* PHP version 5 * PHP version 5
* *
...@@ -25,17 +25,16 @@ ...@@ -25,17 +25,16 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site * @link http://vufind.org Main Site
*/ */
namespace VuFind; namespace VuFind\Theme;
use VuFind\Mobile, use VuFind\Mobile,
VuFind\Mvc\View\InjectTemplateListener, VuFind\Mvc\View\InjectTemplateListener,
Zend\Config\Config, Zend\Config\Config,
Zend\Config\Reader\Ini as IniReader, Zend\Config\Reader\Ini as IniReader,
Zend\Mvc\MvcEvent, Zend\Mvc\MvcEvent,
Zend\Session\Container as SessionContainer,
Zend\Stdlib\RequestInterface as Request; Zend\Stdlib\RequestInterface as Request;
/** /**
* VuFind Theme Handler * VuFind Theme Initializer
* *
* @category VuFind2 * @category VuFind2
* @package Support_Classes * @package Support_Classes
...@@ -43,7 +42,7 @@ use VuFind\Mobile, ...@@ -43,7 +42,7 @@ use VuFind\Mobile,
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org Main Site * @link http://vufind.org Main Site
*/ */
class Theme class Initializer
{ {
protected $autoLoader; protected $autoLoader;
protected $config; protected $config;
...@@ -56,14 +55,19 @@ class Theme ...@@ -56,14 +55,19 @@ class Theme
* *
* @param Config $config Configuration object * @param Config $config Configuration object
* @param MvcEvent $event Zend MVC Event object * @param MvcEvent $event Zend MVC Event object
* @param string $tools Name of Tools class
*/ */
public function __construct(Config $config, MvcEvent $event, 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->config = $config;
$this->event = $event; $this->event = $event;
$this->baseDir = empty($baseDir) $this->baseDir = call_user_func(array($tools, 'getBaseDir'));
? APPLICATION_PATH . '/themes/vufind' : $baseDir;
// Create a class loader for helper management: // Create a class loader for helper management:
$this->autoLoader = $this->getAutoloader(); $this->autoLoader = $this->getAutoloader();
...@@ -72,7 +76,7 @@ class Theme ...@@ -72,7 +76,7 @@ class Theme
$this->serviceManager = $this->event->getApplication()->getServiceManager(); $this->serviceManager = $this->event->getApplication()->getServiceManager();
// Set up a session namespace for storing theme settings: // Set up a session namespace for storing theme settings:
$this->session = new SessionContainer('Theme'); $this->session = call_user_func(array($tools, 'getPersistenceContainer'));
} }
/** /**
......
<?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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment