diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 0240e527d38056bddd3fc2203bd3781b0bddb7ba..2214c7fe670b66842ca09ffd7fd56f5825f22358 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -9,7 +9,9 @@ $config = [ 'VuFind\BranchesReader' => 'finc\Service\Factory::getBranchesReader', 'VuFind\ILSConnection' => 'finc\Service\Factory::getILSConnection', 'VuFind\ILSHoldLogic' => 'finc\Service\Factory::getILSHoldLogic', - 'finc\Rewrite' => 'finc\Rewrite\Factory' + 'finc\Rewrite' => 'finc\Rewrite\Factory', + 'VuFind\SessionManager' => 'finc\Session\ManagerFactory', + 'VuFind\CookieManager' => 'finc\Service\Factory::getCookieManager' ] ], 'controllers' => [ diff --git a/module/finc/src/finc/Cookie/CookieManager.php b/module/finc/src/finc/Cookie/CookieManager.php new file mode 100644 index 0000000000000000000000000000000000000000..7584ed0d6ebda3bc5e82251c662a8e025a463c47 --- /dev/null +++ b/module/finc/src/finc/Cookie/CookieManager.php @@ -0,0 +1,77 @@ +<?php +/** + * Cookie Manager + * + * PHP version 5 + * + * Copyright (C) Villanova University 2015. + * + * 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 VuFind + * @package Cookie + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\Cookie; + +/** + * Cookie Manager + * + * @category VuFind + * @package Cookie + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class CookieManager extends \VuFind\Cookie\CookieManager +{ + /** + * The name of the session cookie + * + * @var string + */ + protected $sessionName; + + /** + * Constructor + * + * @param array $cookies Cookie array to manipulate (e.g. $_COOKIE) + * @param string $path Cookie base path (default = /) + * @param string $domain Cookie domain + * @param bool $secure Are cookies secure only? (default = false) + * @param string $sessionName Session cookie name (if null defaults to PHP + * settings) + */ + public function __construct($cookies, $path = '/', $domain = null, + $secure = false, $sessionName = null + ) { + $this->cookies = $cookies; + $this->path = $path; + $this->domain = $domain; + $this->secure = $secure; + $this->sessionName = $sessionName; + } + + /** + * Get the name of the cookie + * + * @return mixed + */ + public function getSessionName() + { + return $this->sessionName; + } +} diff --git a/module/finc/src/finc/Service/Factory.php b/module/finc/src/finc/Service/Factory.php index 2841fcde82cc5f4d205bb975442e1d338fd2d643..4efbc4ba42544fbe75f2fda7a4676cae6c7f349c 100644 --- a/module/finc/src/finc/Service/Factory.php +++ b/module/finc/src/finc/Service/Factory.php @@ -69,7 +69,7 @@ class Factory $sm->get('VuFind\CacheManager') ); } - + /** * Construct the ILS connection. * @@ -101,4 +101,37 @@ class Factory $sm->get('VuFind\HMAC'), $sm->get('VuFind\Config')->get('config') ); } + + /** + * Construct the cookie manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Cookie\CookieManager + */ + public static function getCookieManager(ServiceManager $sm) + { + $config = $sm->get('VuFind\Config')->get('config'); + $path = '/'; + if (isset($config->Cookies->limit_by_path) + && $config->Cookies->limit_by_path + ) { + $path = $sm->get('Request')->getBasePath(); + if (empty($path)) { + $path = '/'; + } + } + $secure = isset($config->Cookies->only_secure) + ? $config->Cookies->only_secure + : false; + $domain = isset($config->Cookies->domain) + ? $config->Cookies->domain + : null; + $session_name = isset($config->Cookies->session_name) + ? $config->Cookies->session_name + : null; + return new \finc\Cookie\CookieManager( + $_COOKIE, $path, $domain, $secure, $session_name + ); + } } diff --git a/module/finc/src/finc/Session/ManagerFactory.php b/module/finc/src/finc/Session/ManagerFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..6dc0836a1e9dc23ac7b80518a708b68ab120222a --- /dev/null +++ b/module/finc/src/finc/Session/ManagerFactory.php @@ -0,0 +1,71 @@ +<?php +/** + * Factory for instantiating Session Manager + * + * PHP version 5 + * + * Copyright (C) Villanova University 2016. + * + * 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 VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\Session; +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Factory for instantiating Session Manager + * + * @category VuFind + * @package Session_Handlers + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + * + * @codeCoverageIgnore + */ +class ManagerFactory extends \VuFind\Session\ManagerFactory +{ + /** + * Build the options array. + * + * @param ServiceLocatorInterface $sm Service manager + * + * @return array + */ + protected function getOptions(ServiceLocatorInterface $sm) + { + $cookieManager = $sm->get('VuFind\CookieManager'); + $options = [ + 'cookie_path' => $cookieManager->getPath(), + 'cookie_secure' => $cookieManager->isSecure() + ]; + + $domain = $cookieManager->getDomain(); + if (!empty($domain)) { + $options['cookie_domain'] = $domain; + } + + $name = $cookieManager->getSessionName(); + if (!empty($name)) { + $options['name'] = $name; + } + + return $options; + } +}