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

Started loading configurations through a custom plugin manager instead of...

Started loading configurations through a custom plugin manager instead of static \VuFind\Config\Reader.
parent 52837aa6
Branches
Tags
No related merge requests found
...@@ -251,6 +251,10 @@ $config = array( ...@@ -251,6 +251,10 @@ $config = array(
// This section contains all VuFind-specific settings (i.e. configurations // This section contains all VuFind-specific settings (i.e. configurations
// unrelated to specific Zend Framework 2 components). // unrelated to specific Zend Framework 2 components).
'vufind' => array( 'vufind' => array(
// The config reader is a special service manager for loading .ini files:
'config_reader' => array(
'abstract_factories' => array('VuFind\Config\PluginFactory'),
),
// This section contains service manager configurations for all VuFind // This section contains service manager configurations for all VuFind
// pluggable components: // pluggable components:
'plugin_managers' => array( 'plugin_managers' => array(
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
* @link http://vufind.org Main Site * @link http://vufind.org Main Site
*/ */
namespace VuFind; namespace VuFind;
use VuFind\Config\Reader as ConfigReader, use Zend\Console\Console, Zend\Mvc\MvcEvent, Zend\Mvc\Router\Http\RouteMatch;
Zend\Console\Console, Zend\Mvc\MvcEvent, Zend\Mvc\Router\Http\RouteMatch;
/** /**
* VuFind Bootstrapper * VuFind Bootstrapper
...@@ -40,7 +39,7 @@ use VuFind\Config\Reader as ConfigReader, ...@@ -40,7 +39,7 @@ use VuFind\Config\Reader as ConfigReader,
*/ */
class Bootstrapper class Bootstrapper
{ {
protected $config; protected $config = null;
protected $event; protected $event;
protected $events; protected $events;
...@@ -51,7 +50,6 @@ class Bootstrapper ...@@ -51,7 +50,6 @@ class Bootstrapper
*/ */
public function __construct(MvcEvent $event) public function __construct(MvcEvent $event)
{ {
$this->config = ConfigReader::getConfig();
$this->event = $event; $this->event = $event;
$this->events = $event->getApplication()->getEventManager(); $this->events = $event->getApplication()->getEventManager();
} }
...@@ -72,6 +70,26 @@ class Bootstrapper ...@@ -72,6 +70,26 @@ class Bootstrapper
} }
} }
/**
* Set up configuration manager.
*
* @return void
*/
protected function initConfig()
{
// Create the configuration manager:
$app = $this->event->getApplication();
$serviceManager = $app->getServiceManager();
$config = $app->getConfig();
$cfg = new \Zend\ServiceManager\Config($config['vufind']['config_reader']);
$serviceManager->setService(
'VuFind\Config', new \VuFind\Config\PluginManager($cfg)
);
// Use the manager to load the configuration used in subsequent init methods:
$this->config = $serviceManager->get('VuFind\Config')->get('config');
}
/** /**
* Set up plugin managers. * Set up plugin managers.
* *
......
<?php
/**
* VuFind Config Plugin Factory
*
* 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 ServiceManager
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
namespace VuFind\Config;
use Zend\ServiceManager\AbstractFactoryInterface,
Zend\ServiceManager\ServiceLocatorInterface;
/**
* VuFind Config Plugin Factory
*
* @category VuFind2
* @package ServiceManager
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
class PluginFactory implements AbstractFactoryInterface
{
/**
* Can we create a service for the specified name?
*
* @param ServiceLocatorInterface $serviceLocator Service locator
* @param string $name Name of service
* @param string $requestedName Unfiltered name of service
*
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator,
$name, $requestedName
) {
// Assume that configurations exist:
return true;
}
/**
* Create a service for the specified name.
*
* @param ServiceLocatorInterface $serviceLocator Service locator
* @param string $name Name of service
* @param string $requestedName Unfiltered name of service
*
* @return object
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator,
$name, $requestedName
) {
return \VuFind\Config\Reader::getConfig($requestedName);
}
}
<?php
/**
* VuFind Config Manager
*
* 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 ServiceManager
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
namespace VuFind\Config;
use Zend\ServiceManager\AbstractPluginManager as Base;
/**
* VuFind Config Manager
*
* @category VuFind2
* @package ServiceManager
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
class PluginManager extends Base
{
/**
* Validate the plugin
*
* Checks that the filter loaded is either a valid callback or an instance
* of FilterInterface.
*
* @param mixed $plugin Plugin to validate
*
* @throws ServiceManagerRuntimeException if invalid
* @return void
*/
public function validatePlugin($plugin)
{
// Assume everything is okay.
}
}
\ 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