foreach (glob($this->path . "/sess_*") as $filename) {
if (filemtime($filename) + $maxlifetime < time()) {
unlink($filename);
}
}
return true;
}
/**
* A function that is called internally when session data is to be saved.
*
* @param string $sessId The current session ID
* @param string $data The session data to write
*
* @return bool
*/
protected function saveSession($sessId, $data)
{
$sessFile = $this->path . '/sess_' . $sessId;
if ($handle = fopen($sessFile, "w")) {
$return = fwrite($handle, $data);
fclose($handle);
if ($return !== false) {
return true;
}
}
// If we got this far, something went wrong with the file output...
// It is tempting to throw an exception here, but this code is called
// outside of the context of exception handling, so all we can do is
// echo a message.
echo 'Cannot write session to ' . $sessFile . "\n";
return false;
}
}
foreach (glob($this->path . "/sess_*") as $filename) {
if (filemtime($filename) + $maxlifetime < time()) {
unlink($filename);
}
}
return true;
}
/**
* A function that is called internally when session data is to be saved.
*
* @param string $sessId The current session ID
* @param string $data The session data to write
*
* @return bool
*/
protected function saveSession($sessId, $data)
{
$sessFile = $this->path . '/sess_' . $sessId;
if ($handle = fopen($sessFile, "w")) {
$return = fwrite($handle, $data);
fclose($handle);
if ($return !== false) {
return true;
}
}
// If we got this far, something went wrong with the file output...
// It is tempting to throw an exception here, but this code is called
// outside of the context of exception handling, so all we can do is
// echo a message.
echo 'Cannot write session to ' . $sessFile . "\n";
return false;
}
}
// Anecdotal testing Today and Yesterday seems to indicate destroy()
// is called by the garbage collector and everything is good.
// Something to keep in mind though.
return true;
}
/**
* Write function that is called when session data is to be saved.
*
* @param string $sessId The current session ID
* @param string $data The session data to write
*
* @return bool
*/
public function write($sessId, $data)
{
if ($this->writesDisabled) {
return true;
}
return $this->saveSession($sessId, $data);
}
/**
* A function that is called internally when session data is to be saved.
*
* @param string $sessId The current session ID
* @param string $data The session data to write
*
* @return bool
*/
abstract protected function saveSession($sessId, $data);
}
*
* @return void
*/
public function writeClose()
{
// The assumption is that we're using PHP's ext/session.
// session_write_close() will actually overwrite $_SESSION with an
// empty array on completion -- which leads to a mismatch between what
// is in the storage object and $_SESSION. To get around this, we
// temporarily reset $_SESSION to an array, and then re-link it to
// the storage object.
//
// Additionally, while you _can_ write to $_SESSION following a
// session_write_close() operation, no changes made to it will be
// flushed to the session handler. As such, we now mark the storage
// object isImmutable.
$storage = $this->getStorage();
if (! $storage->isImmutable()) {
$_SESSION = $storage->toArray(true);
session_write_close();
$storage->fromArray($_SESSION);
$storage->markImmutable();
}
}
/**
* Attempt to set the session name
*
* If the session has already been started, or if the name provided fails
* validation, an exception will be raised.
*
* @param string $name
* @return SessionManager
* @throws Exception\InvalidArgumentException
*/
public function setName($name)
{
if ($this->sessionExists()) {
throw new Exception\InvalidArgumentException(
'Cannot set session name after a session has already started'
/**
* Session manager (if instantiated)
*
* @var SessionManager
*/
protected $manager = null;
/**
* Disable session writes after this point in time.
*
* @return void
*/
public function disableWrite()
{
// Set the flag
$this->disableWrite = true;
// If the session manager is already instantiated, close it!
if (null !== $this->manager) {
$this->manager->writeClose();
}
}
/**
* Have session writes been disabled?
*
* @return bool
*/
public function isWriteDisabled()
{
return $this->disableWrite;
}
/**
* Set a session manager instance.
*
* @param SessionManager $sessionManager Session manager
*
* @return Settings
*/
'confirm' => $yesTarget,
'cancel' => $noTarget,
'messages' => (array)$messages,
'extras' => $extras
]
]
);
}
/**
* Prevent session writes -- this is designed to be called prior to time-
* consuming AJAX operations to help reduce the odds of a timing-related bug
* that causes the wrong version of session data to be written to disk (see
* VUFIND-716 for more details).
*
* @return void
*/
protected function disableSessionWrites()
{
$this->serviceLocator->get(\VuFind\Session\Settings::class)->disableWrite();
}
/**
* Get the search memory
*
* @return \VuFind\Search\Memory
*/
public function getSearchMemory()
{
return $this->serviceLocator->get(\VuFind\Search\Memory::class);
}
/**
* Are comments enabled?
*
* @return bool
*/
protected function commentsEnabled()
{
$check = $this->serviceLocator
$savedSearch->getParams()->removeFilter($filter);
}
$formatted[] = $current;
}
return $formatted;
}
/**
* Returns a list of all items associated with one facet for the lightbox
*
* Parameters:
* facet The facet to retrieve
* searchParams Facet search params from $results->getUrlQuery()->getParams()
*
* @return mixed
*/
public function facetListAction()
{
$this->disableSessionWrites(); // avoid session write timing bug
// Get results
$results = $this->getResultsManager()->get($this->searchClassId);
$params = $results->getParams();
$params->initFromRequest($this->getRequest()->getQuery());
// Get parameters
$facet = $this->params()->fromQuery('facet');
$page = (int)$this->params()->fromQuery('facetpage', 1);
$options = $results->getOptions();
$facetSortOptions = $options->getFacetSortOptions($facet);
$sort = $this->params()->fromQuery('facetsort', null);
if ($sort === null || !in_array($sort, array_keys($facetSortOptions))) {
$sort = empty($facetSortOptions)
? 'count'
: current(array_keys($facetSortOptions));
}
$config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class)
->get($options->getFacetsIni());
$limit = $config->Results_Settings->lightboxLimit ?? 50;
$limit = $this->params()->fromQuery('facetlimit', $limit);
$facets = $results->getPartialFieldFacets(
*/
public function onDispatch(MvcEvent $e)
{
$routeMatch = $e->getRouteMatch();
if (! $routeMatch) {
/**
* @todo Determine requirements for when route match is missing.
* Potentially allow pulling directly from request metadata?
*/
throw new Exception\DomainException('Missing route matches; unsure how to retrieve action');
}
$action = $routeMatch->getParam('action', 'not-found');
$method = static::getMethodFromAction($action);
if (! method_exists($this, $method)) {
$method = 'notFoundAction';
}
$actionResponse = $this->$method();
$e->setResult($actionResponse);
return $actionResponse;
}
}
}
if ($this->sharedManager) {
foreach ($this->sharedManager->getListeners($this->identifiers, $name) as $priority => $listeners) {
$listOfListenersByPriority[$priority][] = $listeners;
}
}
// Sort by priority in reverse order
krsort($listOfListenersByPriority);
// Initial value of stop propagation flag should be false
$event->stopPropagation(false);
// Execute listeners
$responses = new ResponseCollection();
foreach ($listOfListenersByPriority as $listOfListeners) {
foreach ($listOfListeners as $listeners) {
foreach ($listeners as $listener) {
$response = $listener($event);
$responses->push($response);
// If the event was asked to stop propagating, do so
if ($event->propagationIsStopped()) {
$responses->setStopped(true);
return $responses;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && $callback($response)) {
$responses->setStopped(true);
return $responses;
}
}
}
}
return $responses;
}
$event->setParams($argv);
}
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function triggerEvent(EventInterface $event)
{
return $this->triggerListeners($event);
}
/**
* @inheritDoc
*/
public function triggerEventUntil(callable $callback, EventInterface $event)
{
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function attach($eventName, callable $listener, $priority = 1)
{
if (! is_string($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string for the event; received %s',
__METHOD__,
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
$this->events[$eventName][(int) $priority][0][] = $listener;
return $listener;
}
/**
* @events dispatch.pre, dispatch.post
* @param Request $request
* @param null|Response $response
* @return Response|mixed
*/
public function dispatch(Request $request, Response $response = null)
{
$this->request = $request;
if (! $response) {
$response = new HttpResponse();
}
$this->response = $response;
$e = $this->getEvent();
$e->setName(MvcEvent::EVENT_DISPATCH);
$e->setRequest($request);
$e->setResponse($response);
$e->setTarget($this);
$result = $this->getEventManager()->triggerEventUntil(function ($test) {
return ($test instanceof Response);
}, $e);
if ($result->stopped()) {
return $result->last();
}
return $e->getResult();
}
/**
* Get request object
*
* @return Request
*/
public function getRequest()
{
if (! $this->request) {
$this->request = new HttpRequest();
}
);
return $this->complete($return, $e);
} catch (\Throwable $exception) {
$return = $this->marshalBadControllerEvent($controllerName, $e, $application, $exception);
return $this->complete($return, $e);
} catch (\Exception $exception) { // @TODO clean up once PHP 7 requirement is enforced
$return = $this->marshalBadControllerEvent($controllerName, $e, $application, $exception);
return $this->complete($return, $e);
}
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($e);
}
$request = $e->getRequest();
$response = $application->getResponse();
$caughtException = null;
try {
$return = $controller->dispatch($request, $response);
} catch (\Throwable $ex) {
$caughtException = $ex;
} catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced
$caughtException = $ex;
}
if ($caughtException !== null) {
$e->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$e->setError($application::ERROR_EXCEPTION);
$e->setController($controllerName);
$e->setControllerClass(get_class($controller));
$e->setParam('exception', $caughtException);
$return = $application->getEventManager()->triggerEvent($e)->last();
if (! $return) {
$return = $e->getResult();
}
}
return $this->complete($return, $e);
}
if ($this->sharedManager) {
foreach ($this->sharedManager->getListeners($this->identifiers, $name) as $priority => $listeners) {
$listOfListenersByPriority[$priority][] = $listeners;
}
}
// Sort by priority in reverse order
krsort($listOfListenersByPriority);
// Initial value of stop propagation flag should be false
$event->stopPropagation(false);
// Execute listeners
$responses = new ResponseCollection();
foreach ($listOfListenersByPriority as $listOfListeners) {
foreach ($listOfListeners as $listeners) {
foreach ($listeners as $listener) {
$response = $listener($event);
$responses->push($response);
// If the event was asked to stop propagating, do so
if ($event->propagationIsStopped()) {
$responses->setStopped(true);
return $responses;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && $callback($response)) {
$responses->setStopped(true);
return $responses;
}
}
}
}
return $responses;
}
$event->setParams($argv);
}
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function triggerEvent(EventInterface $event)
{
return $this->triggerListeners($event);
}
/**
* @inheritDoc
*/
public function triggerEventUntil(callable $callback, EventInterface $event)
{
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function attach($eventName, callable $listener, $priority = 1)
{
if (! is_string($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string for the event; received %s',
__METHOD__,
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
$this->events[$eventName][(int) $priority][0][] = $listener;
return $listener;
}
/**
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setName(MvcEvent::EVENT_FINISH);
$event->setTarget($this);
$event->setResponse($response);
$event->stopPropagation(false); // Clear before triggering
$events->triggerEvent($event);
$this->response = $response;
return $this;
}
}
if ($event->getError()) {
return $this->completeRequest($event);
}
// Trigger dispatch event
$event->setName(MvcEvent::EVENT_DISPATCH);
$event->stopPropagation(false); // Clear before triggering
$result = $events->triggerEventUntil($shortCircuit, $event);
// Complete response
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setName(MvcEvent::EVENT_FINISH);
$event->setTarget($this);
$event->setResponse($response);
$event->stopPropagation(false); // Clear before triggering
$events->triggerEvent($event);
$this->response = $response;
return $this;
}
$response = $this->response;
$event->setResponse($response);
return $this->completeRequest($event);
}
/**
* Complete the request
$pathParts[] = APPLICATION_PATH . '/vendor';
$pathParts[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $pathParts));
// Composer autoloading
if (file_exists('vendor/autoload.php')) {
$loader = include 'vendor/autoload.php';
}
if (!class_exists('Laminas\Loader\AutoloaderFactory')) {
throw new RuntimeException('Unable to load Laminas autoloader.');
}
// Run the application!
$app = Laminas\Mvc\Application::init(require 'config/application.config.php');
if (PHP_SAPI === 'cli') {
return $app->getServiceManager()
->get(\VuFindConsole\ConsoleRunner::class)->run();
} else {
$app->run();
}