diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index f8d206435d989967baeef7ac869b12cc526b470d..73685d986aca65d1e5eeadb4067be76ea0f04feb 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -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', diff --git a/module/VuFind/src/VuFind/Cart.php b/module/VuFind/src/VuFind/Cart.php index 5f87c73b74a9978b417d7301bb15c1e99cf25eb8..a6bae49ac2e30225c473f6f16d811a1b1abe476c 100644 --- a/module/VuFind/src/VuFind/Cart.php +++ b/module/VuFind/src/VuFind/Cart.php @@ -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); } }