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

Created initializer class for shared functionality between service manager and plugin managers.

parent b7b269c8
Branches
Tags
No related merge requests found
...@@ -51,17 +51,9 @@ abstract class AbstractPluginManager extends Base ...@@ -51,17 +51,9 @@ abstract class AbstractPluginManager extends Base
\Zend\ServiceManager\ConfigInterface $configuration = null \Zend\ServiceManager\ConfigInterface $configuration = null
) { ) {
parent::__construct($configuration); parent::__construct($configuration);
$initializer = function ($instance, $manager) { $this->addInitializer(
if ($instance instanceof \VuFind\Db\Table\DbTableAwareInterface) { array('VuFind\ServiceManager\Initializer', 'initPlugin'), false
$instance->setDbTableManager( );
$manager->getServiceLocator()->get('VuFind\DbTablePluginManager')
);
}
if (method_exists($instance, 'setPluginManager')) {
$instance->setPluginManager($manager);
}
};
$this->addInitializer($initializer, false);
} }
/** /**
......
<?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
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