diff --git a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php index 0b71c1c416963695ee220c4d5065780b0306a95e..8ab59c121b3d4c997a8f9e799896a856a4131282 100644 --- a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php +++ b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php @@ -51,17 +51,9 @@ abstract class AbstractPluginManager extends Base \Zend\ServiceManager\ConfigInterface $configuration = null ) { parent::__construct($configuration); - $initializer = function ($instance, $manager) { - if ($instance instanceof \VuFind\Db\Table\DbTableAwareInterface) { - $instance->setDbTableManager( - $manager->getServiceLocator()->get('VuFind\DbTablePluginManager') - ); - } - if (method_exists($instance, 'setPluginManager')) { - $instance->setPluginManager($manager); - } - }; - $this->addInitializer($initializer, false); + $this->addInitializer( + array('VuFind\ServiceManager\Initializer', 'initPlugin'), false + ); } /** diff --git a/module/VuFind/src/VuFind/ServiceManager/Initializer.php b/module/VuFind/src/VuFind/ServiceManager/Initializer.php new file mode 100644 index 0000000000000000000000000000000000000000..6aad840e140f48411ac4e94bc1eb5de779831fa4 --- /dev/null +++ b/module/VuFind/src/VuFind/ServiceManager/Initializer.php @@ -0,0 +1,74 @@ +<?php +/** + * VuFind Service Initializer + * + * 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/building_a_recommendations_module Wiki + */ +namespace VuFind\ServiceManager; +use Zend\ServiceManager\ServiceManager; + +/** + * VuFind Service Initializer + * + * @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/building_a_search_object Wiki + */ +class Initializer +{ + /** + * Given an instance and a Service Manager, initialize the instance. + * + * @param object $instance Instance to initialize + * @param ServiceManager $sm Service manager + * + * @return object + */ + public static function initInstance($instance, ServiceManager $sm) + { + if ($instance instanceof \VuFind\Db\Table\DbTableAwareInterface) { + $instance->setDbTableManager($sm->get('VuFind\DbTablePluginManager')); + } + return $instance; + } + + /** + * Given an instance and a Plugin Manager, initialize the instance. + * + * @param object $instance Instance to initialize + * @param AbstractPluginManager $manager Plugin manager + * + * @return object + */ + public static function initPlugin($instance, AbstractPluginManager $manager) + { + static::initInstance($instance, $manager->getServiceLocator()); + if (method_exists($instance, 'setPluginManager')) { + $instance->setPluginManager($manager); + } + return $instance; + } +} \ No newline at end of file