* @return mixed
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
private function doCreate($resolvedName, array $options = null)
{
try {
if (! isset($this->delegators[$resolvedName])) {
// Let's create the service by fetching the factory
$factory = $this->getFactory($resolvedName);
$object = $factory($this->creationContext, $resolvedName, $options);
} else {
$object = $this->createDelegatorFromName($resolvedName, $options);
}
} catch (ContainerException $exception) {
throw $exception;
} catch (Exception $exception) {
throw new ServiceNotCreatedException(sprintf(
'Service with name "%s" could not be created. Reason: %s',
$resolvedName,
$exception->getMessage()
), (int) $exception->getCode(), $exception);
}
foreach ($this->initializers as $initializer) {
$initializer($this->creationContext, $object);
}
return $object;
}
/**
* Create the lazy services delegator factory.
*
* Creates the lazy services delegator factory based on the lazy_services
* configuration present.
*
* @return Proxy\LazyServiceFactory
// introduced in PHP 7.2. Do not alter running INI setting.
return $this;
default:
$key = 'session.' . $storageName;
break;
}
$iniGet = ini_get($key);
$storageValue = (string) $storageValue;
if (false !== $iniGet && (string) $iniGet === $storageValue) {
return $this;
}
$sessionRequiresRestart = false;
if (session_status() == PHP_SESSION_ACTIVE) {
session_write_close();
$sessionRequiresRestart = true;
}
$result = ini_set($key, $storageValue);
if ($sessionRequiresRestart) {
session_start();
}
if (false === $result) {
throw new Exception\InvalidArgumentException(
"'{$key}' is not a valid sessions-related ini setting."
);
}
return $this;
}
/**
* Retrieve a storage option from a backend configuration store
*
* Used to retrieve default values from a backend configuration store.
*
* @param string $storageOption
* @return mixed
// introduced in PHP 7.2. Do not alter running INI setting.
return $this;
default:
$key = 'session.' . $storageName;
break;
}
$iniGet = ini_get($key);
$storageValue = (string) $storageValue;
if (false !== $iniGet && (string) $iniGet === $storageValue) {
return $this;
}
$sessionRequiresRestart = false;
if (session_status() == PHP_SESSION_ACTIVE) {
session_write_close();
$sessionRequiresRestart = true;
}
$result = ini_set($key, $storageValue);
if ($sessionRequiresRestart) {
session_start();
}
if (false === $result) {
throw new Exception\InvalidArgumentException(
"'{$key}' is not a valid sessions-related ini setting."
);
}
return $this;
}
/**
* Retrieve a storage option from a backend configuration store
*
* Used to retrieve default values from a backend configuration store.
*
* @param string $storageOption
* @return mixed
{
if (null === $this->cookieSecure) {
$this->cookieSecure = $this->getStorageOption('cookie_secure');
}
return $this->cookieSecure;
}
/**
* Set session.cookie_httponly
*
* case sensitive method lookups in setOptions means this method has an
* unusual casing
*
* @param bool $cookieHttpOnly
* @return StandardConfig
*/
public function setCookieHttpOnly($cookieHttpOnly)
{
$this->cookieHttpOnly = (bool) $cookieHttpOnly;
$this->setStorageOption('cookie_httponly', $this->cookieHttpOnly);
return $this;
}
/**
* Get session.cookie_httponly
*
* @return bool
*/
public function getCookieHttpOnly()
{
if (null === $this->cookieHttpOnly) {
$this->cookieHttpOnly = $this->getStorageOption('cookie_httponly');
}
return $this->cookieHttpOnly;
}
/**
* Set session.use_cookies
*
* @param bool $useCookies
* otherwise, a standard option will be set with the value provided via
* {@link setOption()}.
*
* @param array|Traversable $options
* @return StandardConfig
* @throws Exception\InvalidArgumentException
*/
public function setOptions($options)
{
if (! is_array($options) && ! $options instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'Parameter provided to %s must be an array or Traversable',
__METHOD__
));
}
foreach ($options as $key => $value) {
$setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
if (method_exists($this, $setter)) {
$this->{$setter}($value);
} else {
$this->setOption($key, $value);
}
}
return $this;
}
/**
* Get all options set
*
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* Set an individual option
*
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
// Build configuration:
$sessionConfig = new \Laminas\Session\Config\SessionConfig();
$sessionConfig->setOptions($this->getOptions($container));
// Build session manager and attach handler:
$sessionManager = new $requestedName($sessionConfig);
$sessionManager->setSaveHandler($this->getHandler($container));
// Start up the session:
$sessionManager->start();
// Verify that any existing session has the correct path to avoid using
// a cookie from a service higher up in the path hierarchy.
$storage = new \Laminas\Session\Container('SessionState', $sessionManager);
if (null !== $storage->cookiePath) {
if ($storage->cookiePath != $sessionConfig->getCookiePath()) {
// Disable writes temporarily to keep the existing session intact
$sessionManager->getSaveHandler()->disableWrites();
// Regenerate session ID and reset the session data
$sessionManager->regenerateId(false);
session_unset();
$sessionManager->getSaveHandler()->enableWrites();
$storage->cookiePath = $sessionConfig->getCookiePath();
/**
* Create a new instance with an already resolved name
*
* This is a highly performance sensitive method, do not modify if you have not benchmarked it carefully
*
* @param string $resolvedName
* @param null|array $options
* @return mixed
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
private function doCreate($resolvedName, array $options = null)
{
try {
if (! isset($this->delegators[$resolvedName])) {
// Let's create the service by fetching the factory
$factory = $this->getFactory($resolvedName);
$object = $factory($this->creationContext, $resolvedName, $options);
} else {
$object = $this->createDelegatorFromName($resolvedName, $options);
}
} catch (ContainerException $exception) {
throw $exception;
} catch (Exception $exception) {
throw new ServiceNotCreatedException(sprintf(
'Service with name "%s" could not be created. Reason: %s',
$resolvedName,
$exception->getMessage()
), (int) $exception->getCode(), $exception);
}
foreach ($this->initializers as $initializer) {
$initializer($this->creationContext, $object);
}
return $object;
}
// is the fastest method).
if (isset($this->services[$requestedName])) {
return $this->services[$requestedName];
}
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
// Next, if the alias should be shared, and we have cached the resolved
// service, use it.
if ($requestedName !== $name
&& (! isset($this->shared[$requestedName]) || $this->shared[$requestedName])
&& isset($this->services[$name])
) {
$this->services[$requestedName] = $this->services[$name];
return $this->services[$name];
}
// At this point, we need to create the instance; we use the resolved
// name for that.
$object = $this->doCreate($name);
// Cache it for later, if it is supposed to be shared.
if (($this->sharedByDefault && ! isset($this->shared[$name]))
|| (isset($this->shared[$name]) && $this->shared[$name])
) {
$this->services[$name] = $object;
}
// Also do so for aliases; this allows sharing based on service name used.
if ($requestedName !== $name
&& (($this->sharedByDefault && ! isset($this->shared[$requestedName]))
|| (isset($this->shared[$requestedName]) && $this->shared[$requestedName]))
) {
$this->services[$requestedName] = $object;
}
return $object;
}
/**
try {
// Check if the catalog wants to hide the login link, and override
// the configuration if necessary.
$catalog = $container->get(\VuFind\ILS\Connection::class);
if ($catalog->loginIsHidden()) {
$config = new \Laminas\Config\Config($config->toArray(), true);
$config->Authentication->hideLogin = true;
$config->setReadOnly();
}
} catch (\Exception $e) {
// Ignore exceptions; if the catalog is broken, throwing an exception
// here may interfere with UI rendering. If we ignore it now, it will
// still get handled appropriately later in processing.
error_log($e->getMessage());
}
// Load remaining dependencies:
$userTable = $container->get(\VuFind\Db\Table\PluginManager::class)
->get('user');
$sessionManager = $container->get(\Laminas\Session\SessionManager::class);
$pm = $container->get(\VuFind\Auth\PluginManager::class);
$cookies = $container->get(\VuFind\Cookie\CookieManager::class);
$csrf = $container->get(\VuFind\Validator\Csrf::class);
// Build the object and make sure account credentials haven't expired:
$manager = new $requestedName(
$config, $userTable, $sessionManager, $pm, $cookies, $csrf
);
$manager->checkForExpiredCredentials();
return $manager;
}
}
/**
* Create a new instance with an already resolved name
*
* This is a highly performance sensitive method, do not modify if you have not benchmarked it carefully
*
* @param string $resolvedName
* @param null|array $options
* @return mixed
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
private function doCreate($resolvedName, array $options = null)
{
try {
if (! isset($this->delegators[$resolvedName])) {
// Let's create the service by fetching the factory
$factory = $this->getFactory($resolvedName);
$object = $factory($this->creationContext, $resolvedName, $options);
} else {
$object = $this->createDelegatorFromName($resolvedName, $options);
}
} catch (ContainerException $exception) {
throw $exception;
} catch (Exception $exception) {
throw new ServiceNotCreatedException(sprintf(
'Service with name "%s" could not be created. Reason: %s',
$resolvedName,
$exception->getMessage()
), (int) $exception->getCode(), $exception);
}
foreach ($this->initializers as $initializer) {
$initializer($this->creationContext, $object);
}
return $object;
}
// is the fastest method).
if (isset($this->services[$requestedName])) {
return $this->services[$requestedName];
}
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
// Next, if the alias should be shared, and we have cached the resolved
// service, use it.
if ($requestedName !== $name
&& (! isset($this->shared[$requestedName]) || $this->shared[$requestedName])
&& isset($this->services[$name])
) {
$this->services[$requestedName] = $this->services[$name];
return $this->services[$name];
}
// At this point, we need to create the instance; we use the resolved
// name for that.
$object = $this->doCreate($name);
// Cache it for later, if it is supposed to be shared.
if (($this->sharedByDefault && ! isset($this->shared[$name]))
|| (isset($this->shared[$name]) && $this->shared[$name])
) {
$this->services[$name] = $object;
}
// Also do so for aliases; this allows sharing based on service name used.
if ($requestedName !== $name
&& (($this->sharedByDefault && ! isset($this->shared[$requestedName]))
|| (isset($this->shared[$requestedName]) && $this->shared[$requestedName]))
) {
$this->services[$requestedName] = $object;
}
return $object;
}
/**
// Make sure language code is valid, reset to default if bad:
if (!in_array($language, array_keys($config->Languages->toArray()))) {
$language = $config->Site->language;
}
try {
$translator = $sm->get(\Laminas\Mvc\I18n\Translator::class);
$translator->setLocale($language);
$this->addLanguageToTranslator($translator, $language);
} catch (\Laminas\Mvc\I18n\Exception\BadMethodCallException $e) {
if (!extension_loaded('intl')) {
throw new \Exception(
'Translation broken due to missing PHP intl extension.'
. ' Please disable translation or install the extension.'
);
}
}
// Store last selected language in user account, if applicable:
if (($user = $sm->get(\VuFind\Auth\Manager::class)->isLoggedIn())
&& $user->last_language != $language
) {
$user->updateLastLanguage($language);
}
// Send key values to view:
$viewModel = $sm->get('ViewManager')->getViewModel();
$viewModel->setVariable('userLang', $language);
$viewModel->setVariable('allLangs', $config->Languages);
$rtlLangs = isset($config->LanguageSettings->rtl_langs)
? array_map(
'trim', explode(',', $config->LanguageSettings->rtl_langs)
) : [];
$viewModel->setVariable('rtl', in_array($language, $rtlLangs));
};
$this->events->attach('dispatch.error', $callback, 10000);
$this->events->attach('dispatch', $callback, 10000);
}
/**
}
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();
}