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

Eliminated unnecessary ServiceLocator/ConfigReader in VuFind\Cart;...

Eliminated unnecessary ServiceLocator/ConfigReader in VuFind\Cart; dependencies and configuration are now injected through constructor.
parent e43748e6
No related merge requests found
......@@ -407,6 +407,16 @@ $config = array(
),
'service_manager' => array(
'factories' => array(
'VuFind\Cart' => function ($sm) {
$config = \VuFind\Config\Reader::getConfig();
$active = isset($config->Site->showBookBag)
? (bool)$config->Site->showBookBag : false;
$size = isset($config->Site->bookBagMaxSize)
? $config->Site->bookBagMaxSize : 100;
return new \VuFind\Cart(
$sm->get('VuFind\RecordLoader'), $size, $active
);
},
'VuFind\DbAdapter' => function ($sm) {
return \VuFind\Db\AdapterFactory::getAdapter();
},
......@@ -473,7 +483,6 @@ $config = array(
),
'invokables' => array(
'VuFind\AuthManager' => 'VuFind\Auth\Manager',
'VuFind\Cart' => 'VuFind\Cart',
'VuFind\CacheManager' => 'VuFind\Cache\Manager',
'VuFind\Mailer' => 'VuFind\Mailer',
'VuFind\RecordLoader' => 'VuFind\Record\Loader',
......
......@@ -26,9 +26,6 @@
* @link http://vufind.org/wiki/system_classes Wiki
*/
namespace VuFind;
use VuFind\Config\Reader as ConfigReader,
Zend\ServiceManager\ServiceLocatorAwareInterface,
Zend\ServiceManager\ServiceLocatorInterface;
/**
* Cart Class
......@@ -41,7 +38,7 @@ use VuFind\Config\Reader as ConfigReader,
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/system_classes Wiki
*/
class Cart implements ServiceLocatorAwareInterface
class Cart
{
/**
* Cart contents.
......@@ -55,21 +52,21 @@ class Cart implements ServiceLocatorAwareInterface
*
* @var int
*/
protected $maxSize = 100;
protected $maxSize;
/**
* Is the cart currently activated?
*
* @var bool
*/
protected $active = false;
protected $active;
/**
* Service locator
* Record loader
*
* @var ServiceLocatorInterface
* @var \VuFind\Record\Loader
*/
protected $serviceLocator;
protected $recordLoader;
const CART_COOKIE = 'vufind_cart';
const CART_COOKIE_SOURCES = 'vufind_cart_src';
......@@ -77,17 +74,17 @@ class Cart implements ServiceLocatorAwareInterface
/**
* Constructor
*
* @param \VuFind\Record\Loader $loader Object for loading records
* @param int $maxSize Maximum size of cart contents
* @param bool $active Is cart enabled?
*/
public function __construct()
{
$config = ConfigReader::getConfig();
if (isset($config->Site->showBookBag)) {
$this->active = (bool)$config->Site->showBookBag;
}
if (isset($config->Site->bookBagMaxSize)) {
$this->maxSize = $config->Site->bookBagMaxSize;
}
$this->items = array();
public function __construct(\VuFind\Record\Loader $loader,
$maxSize = 100, $active = true
) {
$this->recordLoader = $loader;
$this->maxSize = $maxSize;
$this->active = $active;
// Initialize contents
$this->init();
......@@ -293,30 +290,6 @@ class Cart implements ServiceLocatorAwareInterface
*/
public function getRecordDetails()
{
return $this->getServiceLocator()
->get('VuFind\RecordLoader')->loadBatch($this->items);
}
/**
* Set the service locator.
*
* @param ServiceLocatorInterface $serviceLocator Locator to register
*
* @return Manager
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
/**
* Get the service locator.
*
* @return \Zend\ServiceManager\ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
return $this->recordLoader->loadBatch($this->items);
}
}
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