$path,
$domain,
$secure,
$httpOnly,
$sameSite
) {
// Special case: in CLI -- don't actually write headers!
if ('cli' === PHP_SAPI) {
return true;
}
return setcookie(
$key,
$value ?? '',
[
'expires' => $expire,
'path' => $path,
'domain' => $domain,
'samesite' => $sameSite,
'secure' => $secure,
'httponly' => $httpOnly,
]
);
}
/**
* Support method for set() -- set the actual cookie in PHP.
*
* @param string $key Name of cookie to set
* @param mixed $value Value to set
* @param int $expire Cookie expiration time
* @param null|bool $httpOnly Whether the cookie should be "HTTP only"
* @param string $sameSite SameSite attribute to use (Lax, Strict or None)
*
* @return bool
*/
public function setGlobalCookie(
$key,
$value,
$expire,
$httpOnly = null,
$path,
$domain,
$secure,
$httpOnly,
$sameSite
) {
// Special case: in CLI -- don't actually write headers!
if ('cli' === PHP_SAPI) {
return true;
}
return setcookie(
$key,
$value ?? '',
[
'expires' => $expire,
'path' => $path,
'domain' => $domain,
'samesite' => $sameSite,
'secure' => $secure,
'httponly' => $httpOnly,
]
);
}
/**
* Support method for set() -- set the actual cookie in PHP.
*
* @param string $key Name of cookie to set
* @param mixed $value Value to set
* @param int $expire Cookie expiration time
* @param null|bool $httpOnly Whether the cookie should be "HTTP only"
* @param string $sameSite SameSite attribute to use (Lax, Strict or None)
*
* @return bool
*/
public function setGlobalCookie(
$key,
$value,
$expire,
$httpOnly = null,
*
* @return bool
*/
public function setGlobalCookie(
$key,
$value,
$expire,
$httpOnly = null,
$sameSite = null
) {
if (null === $httpOnly) {
$httpOnly = $this->httpOnly;
}
if (null === $sameSite) {
$sameSite = $this->sameSite;
}
// Simple case: flat value.
if (!is_array($value)) {
return $this->proxySetCookie(
$key,
$value,
$expire,
$this->path,
$this->domain,
$this->secure,
$httpOnly,
$sameSite
);
}
// Complex case: array of values.
$success = true;
foreach ($value as $i => $curr) {
$lastSuccess = $this->proxySetCookie(
$key . '[' . $i . ']',
$curr,
$expire,
$this->path,
$this->domain,
$this->secure,
/**
* Set a cookie.
*
* @param string $key Name of cookie to set
* @param mixed $value Value to set
* @param int $expire Cookie expiration time
* @param null|bool $httpOnly Whether the cookie should be "HTTP only"
* @param string $sameSite SameSite attribute to use (Lax, Strict or None)
*
* @return bool
*/
public function set(
$key,
$value,
$expire = 0,
$httpOnly = null,
$sameSite = null
) {
$success = $this
->setGlobalCookie($key, $value, $expire, $httpOnly, $sameSite);
if ($success) {
$this->cookies[$key] = $value;
}
return $success;
}
/**
* Clear a cookie.
*
* @param string $key Name of cookie to unset
*
* @return bool
*/
public function clear($key)
{
$value = $this->get($key);
if (is_array($value)) {
$success = true;
foreach (array_keys($value) as $i) {
if (!$this->clear($key . '[' . $i . ']')) {
? $this->config->mobile_theme : false;
// Find out if the user has a saved preference in the POST, URL or cookies:
$selectedUI = null;
if (isset($request)) {
$selectedUI = $request->getPost()->get(
'ui',
$request->getQuery()->get(
'ui',
$request->getCookie()->ui ?? null
)
);
}
if (empty($selectedUI)) {
$selectedUI = ($mobileTheme && $this->mobile->detect())
? 'mobile' : 'standard';
}
// Save the current setting to a cookie so it persists:
$this->cookieManager->set('ui', $selectedUI);
// Do we have a valid mobile selection?
if ($mobileTheme && $selectedUI == 'mobile') {
return $mobileTheme;
}
// Do we have a non-standard selection?
if (
$selectedUI != 'standard'
&& isset($this->config->alternate_themes)
) {
// Check the alternate theme settings for a match:
$parts = explode(',', $this->config->alternate_themes);
foreach ($parts as $part) {
$subparts = explode(':', $part);
if (
(trim($subparts[0]) == trim($selectedUI))
&& isset($subparts[1]) && !empty($subparts[1])
) {
return $subparts[1];
}
/**
* Initialize the theme. This needs to be triggered as part of the dispatch
* event.
*
* @throws \Exception
* @return void
*/
public function init()
{
// Make sure to initialize the theme just once
if (self::$themeInitialized) {
return;
}
self::$themeInitialized = true;
// Determine the current theme:
$currentTheme = $this->pickTheme(
isset($this->event) ? $this->event->getRequest() : null
);
// Determine theme options:
$this->sendThemeOptionsToView();
// Make sure the current theme is set correctly in the tools object:
$error = null;
try {
$this->tools->setTheme($currentTheme);
} catch (\Exception $error) {
// If an illegal value is passed in, the setter may throw an exception.
// We should ignore it for now and throw it after we have set up the
// theme (the setter will use a safe value instead of the illegal one).
}
// Using the settings we initialized above, actually configure the themes; we
// need to do this even if there is an error, since we need a theme in order
// to display an error message!
$this->setUpThemes(array_reverse($this->tools->getThemeInfo()));
($user = $authManager->isLoggedIn())
&& $user->last_language != $language
) {
$user->updateLastLanguage($language);
}
}
/**
* Set up theme handling.
*
* @return void
*/
protected function initTheme(): void
{
// Attach remaining theme configuration to the dispatch event at high
// priority (TODO: use priority constant once defined by framework):
$config = $this->config->Site;
$callback = function ($event) use ($config) {
$theme = new \VuFindTheme\Initializer($config, $event);
$theme->init();
};
$this->events->attach('dispatch.error', $callback, 9000);
$this->events->attach('dispatch', $callback, 9000);
}
/**
* Set up custom HTTP status based on exception information.
*
* @return void
*/
protected function initExceptionBasedHttpStatuses(): void
{
// HTTP statuses not needed in console mode:
if (PHP_SAPI == 'cli') {
return;
}
$callback = function ($e) {
$exception = $e->getParam('exception');
if ($exception instanceof \VuFind\Exception\HttpStatusInterface) {
}
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
<?php
// If the profiler is enabled, set it up now:
$vufindProfiler = getenv('VUFIND_PROFILER_XHPROF');
if (!empty($vufindProfiler)) {
include __DIR__ . '/../module/VuFind/functions/profiler.php';
enableVuFindProfiling($vufindProfiler);
}
// Run the application!
$app = include __DIR__ . '/../config/application.php';
if (PHP_SAPI === 'cli') {
return $app->getServiceManager()
->get(\VuFindConsole\ConsoleRunner::class)->run();
} else {
$app->run();
}