diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 95b9ec2f4a07..a21eec5d4158 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -167,7 +167,6 @@ ], 'controllers' => [ 'factories' => [ - 'VuFind\Controller\AjaxController' => 'VuFind\Controller\AjaxControllerFactory', 'VuFind\Controller\AlmaController' => 'VuFind\Controller\AbstractBaseFactory', 'VuFind\Controller\AlphabrowseController' => 'VuFind\Controller\AbstractBaseFactory', 'VuFind\Controller\DeveloperSettingsController' => 'VuFind\Controller\AbstractBaseFactory', @@ -243,8 +242,6 @@ 'VuFind\ServiceManager\ServiceInitializer', ], 'aliases' => [ - 'AJAX' => 'VuFind\Controller\AjaxController', - 'ajax' => 'VuFind\Controller\AjaxController', 'Alma' => 'VuFind\Controller\AlmaController', 'alma' => 'VuFind\Controller\AlmaController', 'Alphabrowse' => 'VuFind\Controller\AlphabrowseController', diff --git a/module/VuFind/src/VuFind/Action/AbstractTemplateRenderingAction.php b/module/VuFind/src/VuFind/Action/AbstractTemplateRenderingAction.php index 186c1e270027..5196a646c993 100644 --- a/module/VuFind/src/VuFind/Action/AbstractTemplateRenderingAction.php +++ b/module/VuFind/src/VuFind/Action/AbstractTemplateRenderingAction.php @@ -99,7 +99,7 @@ protected function renderTemplate( array $params = [], ?string $template = null, ): ResponseInterface { - return $this->getTemplateRenderer()->renderTemplate($request, $response, $params, $template); + return $this->getTemplateRenderer()->renderTemplate($request, $response, $template, $params); } /** diff --git a/module/VuFind/src/VuFind/Action/Ajax/JsonAction.php b/module/VuFind/src/VuFind/Action/Ajax/JsonAction.php new file mode 100644 index 000000000000..47f9c1b45d69 --- /dev/null +++ b/module/VuFind/src/VuFind/Action/Ajax/JsonAction.php @@ -0,0 +1,92 @@ +. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ + +namespace VuFind\Action\Ajax; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\Action\AbstractAction; +use VuFind\Action\AjaxResponseTrait; +use VuFind\AjaxHandler\PluginManager as AjaxPluginManager; +use VuFind\I18n\Translator\TranslatorAwareInterface; +use VuFind\I18n\Translator\TranslatorAwareTrait; +use VuFind\ServiceManager\Factory\Autowire; + +/** + * JSON action. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +class JsonAction extends AbstractAction implements TranslatorAwareInterface +{ + use AjaxResponseTrait; + // For AjaxResponseTrait: + use TranslatorAwareTrait; + + /** + * Constructor. + * + * @param AjaxPluginManager $ajaxManager AJAX Handler Plugin Manager + */ + #[Autowire()] + public function __construct( + AjaxPluginManager $ajaxManager + ) { + parent::__construct(); + $this->ajaxManager = $ajaxManager; + } + + /** + * Make an AJAX call with a JSON-formatted response. + * + * @param ServerRequestInterface $request Server request + * @param ResponseInterface $response Response + * + * @return ResponseInterface + */ + public function action( + ServerRequestInterface $request, + ResponseInterface $response, + ): ResponseInterface { + $method = $this->getQueryParam('method'); + if (!$method) { + return $this->getAjaxResponse( + $response, + 'application/json', + ['error' => 'Parameter "method" missing'], + 400 + ); + } + return $this->callAjaxMethod($request, $response, $method); + } +} diff --git a/module/VuFind/src/VuFind/Action/Ajax/OnlinePaymentNotifyAction.php b/module/VuFind/src/VuFind/Action/Ajax/OnlinePaymentNotifyAction.php new file mode 100644 index 000000000000..279fe2abfd0e --- /dev/null +++ b/module/VuFind/src/VuFind/Action/Ajax/OnlinePaymentNotifyAction.php @@ -0,0 +1,83 @@ +. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ + +namespace VuFind\Action\Ajax; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\Action\AbstractAction; +use VuFind\Action\AjaxResponseTrait; +use VuFind\AjaxHandler\PluginManager as AjaxPluginManager; +use VuFind\I18n\Translator\TranslatorAwareInterface; +use VuFind\I18n\Translator\TranslatorAwareTrait; +use VuFind\ServiceManager\Factory\Autowire; + +/** + * Handle online payment notification callback. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +class OnlinePaymentNotifyAction extends AbstractAction implements TranslatorAwareInterface +{ + use AjaxResponseTrait; + // For AjaxResponseTrait: + use TranslatorAwareTrait; + + /** + * Constructor. + * + * @param AjaxPluginManager $ajaxManager AJAX Handler Plugin Manager + */ + #[Autowire()] + public function __construct( + AjaxPluginManager $ajaxManager + ) { + parent::__construct(); + $this->ajaxManager = $ajaxManager; + } + + /** + * Make an AJAX call with a JSON-formatted response. + * + * @param ServerRequestInterface $request Server request + * @param ResponseInterface $response Response + * + * @return ResponseInterface + */ + public function action( + ServerRequestInterface $request, + ResponseInterface $response, + ): ResponseInterface { + return $this->callAjaxMethod($request, $response, 'onlinePaymentNotify', 'text/html'); + } +} diff --git a/module/VuFind/src/VuFind/Action/Ajax/RecommendAction.php b/module/VuFind/src/VuFind/Action/Ajax/RecommendAction.php new file mode 100644 index 000000000000..5d6d31677992 --- /dev/null +++ b/module/VuFind/src/VuFind/Action/Ajax/RecommendAction.php @@ -0,0 +1,83 @@ +. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ + +namespace VuFind\Action\Ajax; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\Action\AbstractAction; +use VuFind\Action\AjaxResponseTrait; +use VuFind\AjaxHandler\PluginManager as AjaxPluginManager; +use VuFind\I18n\Translator\TranslatorAwareInterface; +use VuFind\I18n\Translator\TranslatorAwareTrait; +use VuFind\ServiceManager\Factory\Autowire; + +/** + * Load a recommendation module via AJAX. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +class RecommendAction extends AbstractAction implements TranslatorAwareInterface +{ + use AjaxResponseTrait; + // For AjaxResponseTrait: + use TranslatorAwareTrait; + + /** + * Constructor. + * + * @param AjaxPluginManager $ajaxManager AJAX Handler Plugin Manager + */ + #[Autowire()] + public function __construct( + AjaxPluginManager $ajaxManager + ) { + parent::__construct(); + $this->ajaxManager = $ajaxManager; + } + + /** + * Make an AJAX call with a JSON-formatted response. + * + * @param ServerRequestInterface $request Server request + * @param ResponseInterface $response Response + * + * @return ResponseInterface + */ + public function action( + ServerRequestInterface $request, + ResponseInterface $response, + ): ResponseInterface { + return $this->callAjaxMethod($request, $response, 'recommend', 'text/html'); + } +} diff --git a/module/VuFind/src/VuFind/Action/Ajax/SystemStatusAction.php b/module/VuFind/src/VuFind/Action/Ajax/SystemStatusAction.php new file mode 100644 index 000000000000..9f503580691a --- /dev/null +++ b/module/VuFind/src/VuFind/Action/Ajax/SystemStatusAction.php @@ -0,0 +1,83 @@ +. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ + +namespace VuFind\Action\Ajax; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\Action\AbstractAction; +use VuFind\Action\AjaxResponseTrait; +use VuFind\AjaxHandler\PluginManager as AjaxPluginManager; +use VuFind\I18n\Translator\TranslatorAwareInterface; +use VuFind\I18n\Translator\TranslatorAwareTrait; +use VuFind\ServiceManager\Factory\Autowire; + +/** + * Check status and return a status message for e.g. a load balancer. + * + * @category VuFind + * @package Action + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +class SystemStatusAction extends AbstractAction implements TranslatorAwareInterface +{ + use AjaxResponseTrait; + // For AjaxResponseTrait: + use TranslatorAwareTrait; + + /** + * Constructor. + * + * @param AjaxPluginManager $ajaxManager AJAX Handler Plugin Manager + */ + #[Autowire()] + public function __construct( + AjaxPluginManager $ajaxManager + ) { + parent::__construct(); + $this->ajaxManager = $ajaxManager; + } + + /** + * Make an AJAX call with a JSON-formatted response. + * + * @param ServerRequestInterface $request Server request + * @param ResponseInterface $response Response + * + * @return ResponseInterface + */ + public function action( + ServerRequestInterface $request, + ResponseInterface $response, + ): ResponseInterface { + return $this->callAjaxMethod($request, $response, 'systemStatus', 'text/plain'); + } +} diff --git a/module/VuFind/src/VuFind/Action/AjaxResponseTrait.php b/module/VuFind/src/VuFind/Action/AjaxResponseTrait.php new file mode 100644 index 000000000000..89279157d0f9 --- /dev/null +++ b/module/VuFind/src/VuFind/Action/AjaxResponseTrait.php @@ -0,0 +1,177 @@ +. + * + * @category VuFind + * @package Controller + * @author Chris Hallberg + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ + +namespace VuFind\Action; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\AjaxHandler\AjaxHandlerInterface; +use VuFind\AjaxHandler\PluginManager; + +/** + * Trait to allow AJAX response generation. + * + * Dependencies: + * - \VuFind\I18n\Translator\TranslatorAwareTrait + * - Injection of $this->ajaxManager (for some functionality) + * + * @category VuFind + * @package Action + * @author Chris Hallberg + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ +trait AjaxResponseTrait +{ + /** + * AJAX Handler plugin manager. + * + * @var PluginManager + */ + protected $ajaxManager = null; + + /** + * Format the content of the AJAX response based on the response type. + * + * @param string $type Content-type of output + * @param mixed $data The response data + * @param int $httpCode A custom HTTP Status Code + * + * @return string + * @throws \Exception + */ + protected function formatContent($type, $data, $httpCode) + { + switch ($type) { + case 'application/javascript': + case 'application/json': + return json_encode(compact('data')); + case 'text/plain': + return ((null !== $httpCode && $httpCode >= 400) ? 'ERROR ' : 'OK ') + . $data; + case 'text/html': + return $data ?: ''; + default: + throw new \Exception("Unsupported content type: $type"); + } + } + + /** + * Get a response with the AJAX output data. + * + * @param ResponseInterface $response Response + * @param string $type Content type to output + * @param mixed $data The response data + * @param ?int $httpCode A custom HTTP Status Code or null for default (200) + * + * @return ResponseInterface + * @throws \Exception + */ + protected function getAjaxResponse( + ResponseInterface $response, + string $type, + mixed $data, + ?int $httpCode = null + ): ResponseInterface { + $response = $response->withHeader('Content-Type', $type) + ->withHeader('Cache-Control', 'no-cache, must-revalidate') + ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); + if ($httpCode !== null) { + $response = $response->withStatus($httpCode); + } + $response->getBody()->write($this->formatContent($type, $data, $httpCode)); + return $response; + } + + /** + * Turn an exception into error response. + * + * @param ResponseInterface $response Response + * @param string $type Content type to output + * @param \Exception $e Exception to output. + * + * @return ResponseInterface + */ + protected function getExceptionResponse(ResponseInterface $response, string $type, \Exception $e): ResponseInterface + { + $debugMsg = ('development' == APPLICATION_ENV) + ? ': ' . $e->getMessage() : ''; + return $this->getAjaxResponse( + $response, + $type, + $this->translate('An error has occurred') . $debugMsg, + AjaxHandlerInterface::STATUS_HTTP_ERROR + ); + } + + /** + * Call an AJAX method and turn the result into a response. + * + * @param ServerRequestInterface $request Request + * @param ResponseInterface $response Response + * @param string $method AJAX method to call + * @param string $type Content type to output + * + * @return ResponseInterface + */ + protected function callAjaxMethod( + ServerRequestInterface $request, + ResponseInterface $response, + string $method, + string $type = 'application/json' + ): ResponseInterface { + // Check the AJAX handler plugin manager for the method. + if (!$this->ajaxManager) { + throw new \Exception('AJAX Handler Plugin Manager missing.'); + } + if ($this->ajaxManager->has($method)) { + try { + $handler = $this->ajaxManager->get($method); + return $this->getAjaxResponse( + $response, + $type, + ...$handler->handleRequest($request, $response) + ); + } catch (\Exception $e) { + return $this->getExceptionResponse($response, $type, $e); + } + } + + // If we got this far, we can't handle the requested method: + return $this->getAjaxResponse( + $response, + $type, + $this->translate('Invalid Method'), + AjaxHandlerInterface::STATUS_HTTP_BAD_REQUEST + ); + } +} diff --git a/module/VuFind/src/VuFind/Action/PluginManager.php b/module/VuFind/src/VuFind/Action/PluginManager.php index 76ab1087c92d..3c29129f8352 100644 --- a/module/VuFind/src/VuFind/Action/PluginManager.php +++ b/module/VuFind/src/VuFind/Action/PluginManager.php @@ -29,6 +29,7 @@ namespace VuFind\Action; +use VuFind\ServiceManager\Factory\AbstractAutowiringFactory; use VuFind\ServiceManager\Factory\AutowiringFactory; use function count; @@ -53,6 +54,9 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $aliases = [ + 'ajax/json' => Ajax\JsonAction::class, + 'ajax/onlinepaymentnotify' => Ajax\OnlinePaymentNotifyAction::class, + 'ajax/systemstatus' => Ajax\SystemStatusAction::class, ]; /** @@ -99,6 +103,7 @@ public function __construct( $configOrContainerInstance = null, array $v3config = [] ) { + $this->addAbstractFactory(AbstractAutowiringFactory::class); $this->addInitializer(ActionInitializer::class); parent::__construct($configOrContainerInstance, $v3config); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractBase.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractBase.php index f0158ffebb00..d6676c935fff 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractBase.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractBase.php @@ -29,6 +29,7 @@ namespace VuFind\AjaxHandler; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Session\Settings as SessionSettings; /** @@ -43,11 +44,19 @@ abstract class AbstractBase implements AjaxHandlerInterface { /** - * Session settings. + * Constructor. * - * @var SessionSettings + * @param ?SessionSettings $sessionSettings Session settings */ - protected $sessionSettings = null; + public function __construct( + protected ?SessionSettings $sessionSettings + ) { + // Prevent errors, notices etc. from being displayed so that they don't mess + // with the output (only in production mode): + if ('production' === APPLICATION_ENV) { + ini_set('display_errors', '0'); + } + } /** * Prevent session writes -- this is designed to be called prior to time- @@ -65,6 +74,59 @@ protected function disableSessionWrites() $this->sessionSettings->disableWrite(); } + /** + * Get a parameter from POST fields or query string. + * + * @param ServerRequestInterface $request Request + * @param string $param Param name + * @param array|string|null $default Default value + * + * @return array|string|null + */ + protected function getPostOrQueryParam( + ServerRequestInterface $request, + string $param, + array|string|null $default = null + ): array|string|null { + return $this->getPostParam($request, $param) + ?? $this->getQueryParam($request, $param) + ?? $default; + } + + /** + * Get a parameter from POST fields. + * + * @param ServerRequestInterface $request Request + * @param string $param Param name + * @param array|string|null $default Default value + * + * @return array|string|null + */ + protected function getPostParam( + ServerRequestInterface $request, + string $param, + array|string|null $default = null + ): array|string|null { + return $request->getParsedBody()[$param] ?? $default; + } + + /** + * Get a parameter from query string. + * + * @param ServerRequestInterface $request Request + * @param string $param Param name + * @param array|string|null $default Default value + * + * @return array|string|null + */ + protected function getQueryParam( + ServerRequestInterface $request, + string $param, + array|string|null $default = null + ): array|string|null { + return $request->getQueryParams()[$param] ?? $default; + } + /** * Format a response array. * diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsAndUserAction.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsAndUserAction.php index 1dfbb029e439..aec5bb8d5049 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsAndUserAction.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsAndUserAction.php @@ -62,6 +62,6 @@ public function __construct( protected ILSAuthenticator $ilsAuthenticator, protected ?UserEntityInterface $user ) { - $this->sessionSettings = $ss; + parent::__construct($ss); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererAction.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererAction.php index 1c074f0e0284..a76bb2b00d36 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererAction.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererAction.php @@ -29,12 +29,13 @@ namespace VuFind\AjaxHandler; -use Laminas\View\Renderer\PhpRenderer; use VuFind\Auth\ILSAuthenticator; use VuFind\Db\Entity\UserEntityInterface; use VuFind\I18n\Translator\TranslatorAwareInterface; use VuFind\ILS\Connection; +use VuFind\ServiceManager\Factory\Autowire; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Abstract base class for handlers depending on the ILS and a logged-in user. @@ -52,19 +53,20 @@ abstract class AbstractIlsUserAndRendererAction extends AbstractBase implements /** * Constructor. * - * @param SessionSettings $ss Session settings - * @param Connection $ils ILS connection - * @param ILSAuthenticator $ilsAuthenticator ILS authenticator - * @param ?UserEntityInterface $user Logged in user (or null) - * @param PhpRenderer $renderer View renderer + * @param SessionSettings $ss Session settings + * @param Connection $ils ILS connection + * @param ILSAuthenticator $ilsAuthenticator ILS authenticator + * @param ?UserEntityInterface $user Logged in user (or null) + * @param TemplateRendererInterface $renderer Template renderer */ + #[Autowire()] public function __construct( SessionSettings $ss, protected Connection $ils, protected ILSAuthenticator $ilsAuthenticator, protected ?UserEntityInterface $user, - protected PhpRenderer $renderer + protected TemplateRendererInterface $renderer ) { - $this->sessionSettings = $ss; + parent::__construct($ss); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererActionFactory.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererActionFactory.php index 3679335dceba..ffd8b1762f8e 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererActionFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractIlsUserAndRendererActionFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for AbstractIlsAndUserAction AJAX handlers. @@ -71,7 +72,7 @@ public function __invoke( $container->get(\VuFind\ILS\Connection::class), $container->get(\VuFind\Auth\ILSAuthenticator::class), $container->get(\VuFind\Auth\Manager::class)->getUserObject(), - $container->get('ViewRenderer'), + $container->get(TemplateRendererInterface::class), ...($options ?: []) ); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractOnlinePaymentAction.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractOnlinePaymentAction.php index 2ebd95bae95a..df56771837b0 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractOnlinePaymentAction.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractOnlinePaymentAction.php @@ -65,7 +65,7 @@ public function __construct( protected OnlinePaymentManager $onlinePaymentManager, AuditEventServiceInterface $auditEventService ) { - $this->sessionSettings = $sessionSettings; + parent::__construct($sessionSettings); $this->auditEventService = $auditEventService; } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractRelaisAction.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractRelaisAction.php index 2cb7faa2eaac..e8821990c093 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractRelaisAction.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractRelaisAction.php @@ -59,6 +59,6 @@ public function __construct( protected Relais $relais, protected ?UserEntityInterface $user ) { - $this->sessionSettings = $ss; + parent::__construct($ss); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AbstractUserRequestAction.php b/module/VuFind/src/VuFind/AjaxHandler/AbstractUserRequestAction.php index 78b84349411d..11b962d9eb3e 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AbstractUserRequestAction.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AbstractUserRequestAction.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Account\AccountStatusLevelType; /** @@ -55,11 +55,11 @@ abstract class AbstractUserRequestAction extends AbstractIlsUserAndRendererActio /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * - * @return array [response data, internal status code, HTTP status code] + * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug $patron = $this->ilsAuthenticator->storedCatalogLogin(); @@ -72,7 +72,7 @@ public function handleRequest(Params $params) $requests = $this->ils->{$this->lookupMethod}($patron); $result = $this->getRequestSummary($requests); $result['level'] = $this->getAccountStatusLevel($result); - $result['html'] = $this->renderer->render('ajax/account/requests.phtml', $result); + $result['html'] = $this->renderer->renderTemplateAsString($request, 'ajax/account/requests.phtml', $result); return $this->formatResponse($result); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/AjaxHandlerInterface.php b/module/VuFind/src/VuFind/AjaxHandler/AjaxHandlerInterface.php index 0a1d75411237..245dcd62c73d 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/AjaxHandlerInterface.php +++ b/module/VuFind/src/VuFind/AjaxHandler/AjaxHandlerInterface.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * AJAX handler interface. @@ -52,9 +52,9 @@ interface AjaxHandlerInterface /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params); + public function handleRequest(ServerRequestInterface $request): array; } diff --git a/module/VuFind/src/VuFind/AjaxHandler/CheckRequestIsValid.php b/module/VuFind/src/VuFind/AjaxHandler/CheckRequestIsValid.php index 4da8ac86e729..6cfbdb649631 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/CheckRequestIsValid.php +++ b/module/VuFind/src/VuFind/AjaxHandler/CheckRequestIsValid.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use function is_array; @@ -82,18 +82,18 @@ protected function getStatusMessage($requestType, $results) /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug // process and validate input: - $id = $params->fromQuery('id'); - $jsonData = $params->fromQuery('data'); - $requestType = $params->fromQuery('requestType'); + $id = $this->getQueryParam($request, 'id'); + $jsonData = $this->getQueryParam($request, 'data'); + $requestType = $this->getQueryParam($request, 'requestType'); if (empty($id) || empty($jsonData) || !($data = json_decode($jsonData, true))) { return $this->formatResponse( $this->translate('bulk_error_missing'), diff --git a/module/VuFind/src/VuFind/AjaxHandler/CommentRecord.php b/module/VuFind/src/VuFind/AjaxHandler/CommentRecord.php index 4b6e1890871c..1fafecb284ac 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/CommentRecord.php +++ b/module/VuFind/src/VuFind/AjaxHandler/CommentRecord.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Captcha\Service\CaptchaService; use VuFind\Config\AccountCapabilities; use VuFind\Db\Entity\UserEntityInterface; @@ -76,33 +76,34 @@ public function __construct( protected AccountCapabilities $accountCapabilities, protected RatingsService $ratingsService ) { + parent::__construct(null); } /** * Is CAPTCHA valid? (Also returns true if CAPTCHA is disabled). * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return bool */ - protected function checkCaptcha(Params $params) + protected function checkCaptcha(ServerRequestInterface $request) { // Not enabled? Report success! if (!$this->captcha->active('userComments')) { return true; } $this->captcha->setErrorMode('none'); - return $this->captcha->verify($params->fromPost(), $params->fromQuery()); + return $this->captcha->verify($request->getParsedBody(), $request->getQueryParams()); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { // Make sure comments are enabled: if (!$this->enabled) { @@ -119,9 +120,9 @@ public function handleRequest(Params $params) ); } - $id = $params->fromPost('id'); - $source = $params->fromPost('source', DEFAULT_SEARCH_BACKEND); - $comment = $params->fromPost('comment'); + $id = $this->getPostParam($request, 'id'); + $source = $this->getPostParam($request, 'source', DEFAULT_SEARCH_BACKEND); + $comment = $this->getPostParam($request, 'comment'); if (empty($id) || empty($comment)) { return $this->formatResponse( $this->translate('bulk_error_missing'), @@ -130,7 +131,7 @@ public function handleRequest(Params $params) } $driver = $this->recordLoader->load($id, $source, false); - if (!$this->checkCaptcha($params)) { + if (!$this->checkCaptcha($request)) { return $this->formatResponse( $this->translate('captcha_not_passed'), self::STATUS_HTTP_FORBIDDEN @@ -144,7 +145,7 @@ public function handleRequest(Params $params) $resource ); - $rating = $params->fromPost('rating', ''); + $rating = $this->getPostParam($request, 'rating', ''); if ( $driver->isRatingAllowed() && ('' !== $rating diff --git a/module/VuFind/src/VuFind/AjaxHandler/DeleteRecordComment.php b/module/VuFind/src/VuFind/AjaxHandler/DeleteRecordComment.php index 9de09e08efa9..4f69193da644 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/DeleteRecordComment.php +++ b/module/VuFind/src/VuFind/AjaxHandler/DeleteRecordComment.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Db\Entity\UserEntityInterface; use VuFind\Db\Service\CommentsServiceInterface; use VuFind\I18n\Translator\TranslatorAwareInterface; @@ -59,16 +59,17 @@ public function __construct( protected ?UserEntityInterface $user, protected bool $enabled = true ) { + parent::__construct(null); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { // Make sure comments are enabled: if (!$this->enabled) { @@ -85,7 +86,7 @@ public function handleRequest(Params $params) ); } - $id = $params->fromQuery('id'); + $id = $this->getQueryParam($request, 'id'); if (empty($id)) { return $this->formatResponse( $this->translate('bulk_error_missing'), diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetACSuggestions.php b/module/VuFind/src/VuFind/AjaxHandler/GetACSuggestions.php index 3bf162253a93..f5154a828116 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetACSuggestions.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetACSuggestions.php @@ -29,8 +29,8 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Stdlib\Parameters; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Autocomplete\Suggester; use VuFind\Session\Settings as SessionSettings; @@ -53,20 +53,20 @@ class GetACSuggestions extends AbstractBase */ public function __construct(SessionSettings $ss, protected Suggester $suggester) { - $this->sessionSettings = $ss; + parent::__construct($ss); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $query = new Parameters($params->fromQuery()); + $query = new Parameters($request->getQueryParams()); $suggestions = $this->suggester->getSuggestions($query); return $this->formatResponse(compact('suggestions')); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetCookieConsent.php b/module/VuFind/src/VuFind/AjaxHandler/GetCookieConsent.php index 8934e77944e1..7b3aa0584b0b 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetCookieConsent.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetCookieConsent.php @@ -29,9 +29,9 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\ServiceManager\Factory\Autowire; +use VuFind\View\Renderer\TemplateRendererInterface; /** * "Get Cookie Consent Overlay" AJAX handler. @@ -49,24 +49,24 @@ class GetCookieConsent extends AbstractBase /** * Constructor. * - * @param RendererInterface $renderer View renderer + * @param TemplateRendererInterface $renderer Template renderer */ + #[Autowire()] public function __construct( - #[Autowire(service: 'ViewRenderer')] - protected RendererInterface $renderer + protected TemplateRendererInterface $renderer ) { } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { - $html = $this->renderer->render('CookieConsent/cookie-consent-overlay.phtml'); + $html = $this->renderer->renderTemplateAsString($request, 'CookieConsent/cookie-consent-overlay.phtml'); return $this->formatResponse(compact('html')); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatus.php b/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatus.php index 84727d73ee5e..f6a13836c71b 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatus.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatus.php @@ -30,10 +30,10 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\ILS\Connection; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; /** * "Get ILS Status" AJAX handler. @@ -50,55 +50,36 @@ */ class GetIlsStatus extends AbstractBase { - /** - * ILS connection. - * - * @var Connection - */ - protected $ils; - - /** - * View renderer. - * - * @var RendererInterface - */ - protected $renderer; - /** * Constructor. * - * @param SessionSettings $ss Session settings - * @param Connection $ils ILS connection - * @param RendererInterface $renderer View renderer + * @param SessionSettings $ss Session settings + * @param Connection $ils ILS connection + * @param TemplateRendererInterface $renderer Template renderer */ public function __construct( SessionSettings $ss, - Connection $ils, - RendererInterface $renderer + protected Connection $ils, + protected TemplateRendererInterface $renderer ) { - $this->sessionSettings = $ss; - $this->ils = $ils; - $this->renderer = $renderer; + parent::__construct($ss); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $html = null; $this->disableSessionWrites(); if ($this->ils->getOfflineMode(true) == 'ils-offline') { - $offlineModeMsg = $params->fromPost( - 'offlineModeMsg', - $params->fromQuery('offlineModeMsg') - ); + $offlineModeMsg = $this->getPostOrQueryParam($request, 'offlineModeMsg'); $html = $this->renderer - ->render('Helpers/ils-offline.phtml', compact('offlineModeMsg')); + ->renderTemplateAsString($request, 'Helpers/ils-offline.phtml', compact('offlineModeMsg')); } return $this->formatResponse(['html' => $html ?? '']); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatusFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatusFactory.php index bd4bb39f558c..d8fe3e691364 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatusFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetIlsStatusFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetIlsStatus AJAX handler. @@ -72,7 +73,7 @@ public function __invoke( return new $requestedName( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\ILS\Connection::class), - $container->get('ViewRenderer') + $container->get(TemplateRendererInterface::class) ); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 4292af8460ba..aee8d69167e3 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -33,8 +33,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Config\Config; use VuFind\Exception\ILS as ILSException; use VuFind\I18n\Translator\TranslatorAwareInterface; @@ -43,6 +42,7 @@ use VuFind\ILS\Logic\AvailabilityStatusManager; use VuFind\ILS\Logic\Holds; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; use function array_map; use function array_unique; @@ -79,7 +79,7 @@ class GetItemStatuses extends AbstractBase implements * @param SessionSettings $ss Session settings * @param Config $config Top-level configuration * @param Connection $ils ILS connection - * @param RendererInterface $renderer View renderer + * @param TemplateRendererInterface $renderer Template renderer * @param Holds $holdLogic Holds logic * @param AvailabilityStatusManager $availabilityStatusManager Availability status manager */ @@ -87,11 +87,11 @@ public function __construct( SessionSettings $ss, protected Config $config, protected Connection $ils, - protected RendererInterface $renderer, + protected TemplateRendererInterface $renderer, protected Holds $holdLogic, protected AvailabilityStatusManager $availabilityStatusManager ) { - $this->sessionSettings = $ss; + parent::__construct($ss); } /** @@ -186,11 +186,12 @@ protected function getCallnumberHandler($list = null, $displaySetting = null) /** * Reduce an array of service names to a human-readable string. * - * @param array $rawServices Names of available services. + * @param ServerRequestInterface $request Request + * @param array $rawServices Names of available services * * @return string */ - protected function reduceServices(array $rawServices) + protected function reduceServices(ServerRequestInterface $request, array $rawServices) { // Normalize, dedup and sort available services $normalize = function ($in) { @@ -206,7 +207,8 @@ protected function reduceServices(array $rawServices) $services = [$preferred]; } - return $this->renderer->render( + return $this->renderer->renderTemplateAsString( + $request, 'ajax/status-available-services.phtml', ['services' => $services] ); @@ -230,13 +232,17 @@ protected function getCallNumberArray(array $item): array /** * Render the callnumber HTML. * - * @param string $callnumberSetting The callnumber mode setting - * @param array $callnumbers Callnumbers to render + * @param ServerRequestInterface $request Request + * @param string $callnumberSetting The callnumber mode setting + * @param array $callnumbers Callnumbers to render * * @return string */ - protected function renderCallnumbers(string $callnumberSetting, array $callnumbers): string - { + protected function renderCallnumbers( + ServerRequestInterface $request, + string $callnumberSetting, + array $callnumbers + ): string { $html = []; $callnumberHandler = $this->getCallnumberHandler($callnumbers, $callnumberSetting); @@ -252,7 +258,8 @@ protected function renderCallnumbers(string $callnumberSetting, array $callnumbe $displayCallnumber = $actualCallnumber = $number; } - $html[] = $this->renderer->render( + $html[] = $this->renderer->renderTemplateAsString( + $request, 'ajax/itemCallnumber', compact('actualCallnumber', 'displayCallnumber', 'callnumberHandler') ); @@ -265,16 +272,18 @@ protected function renderCallnumbers(string $callnumberSetting, array $callnumbe * Support method for getItemStatuses() -- process a single bibliographic record * for location settings other than "group". * - * @param array $record Information on items linked to a single bib - * record - * @param string $locationSetting The location mode setting used for - * pickValue() - * @param string $callnumberSetting The callnumber mode setting used for - * pickValue() + * @param ServerRequestInterface $request Request + * @param array $record Information on items linked to a single bib + * record + * @param string $locationSetting The location mode setting used for + * pickValue() + * @param string $callnumberSetting The callnumber mode setting used for + * pickValue() * * @return array Summarized availability information */ protected function getItemStatus( + ServerRequestInterface $request, $record, $locationSetting, $callnumberSetting @@ -313,9 +322,9 @@ protected function getItemStatus( $combinedAvailability = $combinedInfo['availability']; if (!empty($services)) { - $availabilityMessage = $this->reduceServices($services); + $availabilityMessage = $this->reduceServices($request, $services); } else { - $availabilityMessage = $this->getAvailabilityMessage($combinedAvailability); + $availabilityMessage = $this->getAvailabilityMessage($request, $combinedAvailability); } $reserve = ($record[0]['reserve'] ?? 'N') === 'Y'; @@ -330,7 +339,7 @@ protected function getItemStatus( 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' => $this->translate($reserve ? 'on_reserve' : 'Not On Reserve'), - 'callnumberHtml' => $this->renderCallnumbers($callnumberSetting, $callNumber), + 'callnumberHtml' => $this->renderCallnumbers($request, $callnumberSetting, $callNumber), ]; } @@ -338,14 +347,15 @@ protected function getItemStatus( * Support method for getItemStatuses() -- process a single bibliographic record * for "group" location setting. * - * @param array $record Information on items linked to a single - * bib record - * @param string $callnumberSetting The callnumber mode setting used for - * pickValue() + * @param ServerRequestInterface $request Request, + * @param array $record Information on items linked to a single + * bib record + * @param string $callnumberSetting The callnumber mode setting used for + * pickValue() * * @return array Summarized availability information */ - protected function getItemStatusGroup($record, $callnumberSetting) + protected function getItemStatusGroup(ServerRequestInterface $request, $record, $callnumberSetting) { // Summarize call number, location and availability info across all items: $locations = []; @@ -372,7 +382,7 @@ protected function getItemStatusGroup($record, $callnumberSetting) 'availability' => $locationStatus['availability'], 'location' => $this->translateWithPrefix('location_', $location), 'callnumberHtml' => - $this->renderCallnumbers($callnumberSetting, $locationCallnumbers), + $this->renderCallnumbers($request, $callnumberSetting, $locationCallnumbers), ]; $locationList[] = $locationInfo; } @@ -387,9 +397,10 @@ protected function getItemStatusGroup($record, $callnumberSetting) return [ 'id' => $record[0]['id'], 'availability' => $combinedAvailability->availabilityAsString(), - 'availability_message' => $this->getAvailabilityMessage($combinedAvailability), + 'availability_message' => $this->getAvailabilityMessage($request, $combinedAvailability), 'location' => false, - 'locationList' => $this->renderer->render('ajax/itemLocationList', ['locationList' => $locationList]), + 'locationList' => $this->renderer + ->renderTemplateAsString($request, 'ajax/itemLocationList', ['locationList' => $locationList]), 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' => $this->translate($reserve ? 'on_reserve' : 'Not On Reserve'), @@ -423,13 +434,17 @@ protected function getItemStatusError($record, $msg = '') /** * Get a message for availability status. * + * @param ServerRequestInterface $request Request * @param AvailabilityStatusInterface $availability Availability Status * * @return string */ - protected function getAvailabilityMessage(AvailabilityStatusInterface $availability): string - { - return $this->renderer->render( + protected function getAvailabilityMessage( + ServerRequestInterface $request, + AvailabilityStatusInterface $availability + ): string { + return $this->renderer->renderTemplateAsString( + $request, 'ajax/status.phtml', ['availabilityStatus' => $availability] ); @@ -438,13 +453,14 @@ protected function getAvailabilityMessage(AvailabilityStatusInterface $availabil /** * Render full item status. * - * @param array $record Record - * @param array $simpleStatus Simple status result - * @param array $values Additional values for the template + * @param ServerRequestInterface $request Request + * @param array $record Record + * @param array $simpleStatus Simple status result + * @param array $values Additional values for the template * * @return string */ - protected function renderFullStatus($record, $simpleStatus, array $values = []) + protected function renderFullStatus(ServerRequestInterface $request, $record, $simpleStatus, array $values = []) { // Default case: no extra holdings fields are shown $holdingsTextFieldsToShow = []; @@ -467,22 +483,22 @@ protected function renderFullStatus($record, $simpleStatus, array $values = []) $values ); - return $this->renderer->render('ajax/status-full.phtml', $values); + return $this->renderer->renderTemplateAsString($request, 'ajax/status-full.phtml', $values); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $results = []; $this->disableSessionWrites(); // avoid session write timing bug - $ids = $params->fromPost('id') ?? $params->fromQuery('id', []); - $searchId = $params->fromPost('sid') ?? $params->fromQuery('sid'); + $ids = $this->getPostOrQueryParam($request, 'id', []); + $searchId = $this->getPostOrQueryParam($request, 'sid'); try { $results = $this->ils->getStatuses($ids); } catch (ILSException $e) { @@ -532,15 +548,17 @@ public function handleRequest(Params $params) $current = $this ->getItemStatusError( $record, - $this->getAvailabilityMessage($unknownStatus) + $this->getAvailabilityMessage($request, $unknownStatus) ); } elseif ($locationSetting === 'group') { $current = $this->getItemStatusGroup( + $request, $record, $callnumberSetting ); } else { $current = $this->getItemStatus( + $request, $record, $locationSetting, $callnumberSetting @@ -550,6 +568,7 @@ public function handleRequest(Params $params) // encountered, append the HTML: if ($showFullStatus && empty($record[0]['error'])) { $current['full_status'] = $this->renderFullStatus( + $request, $record, $current, compact('searchId', 'current'), @@ -569,7 +588,7 @@ public function handleRequest(Params $params) $statuses[] = [ 'id' => (string)$missingId, // array_flip may have converted to int 'availability' => 'false', - 'availability_message' => $this->getAvailabilityMessage($availabilityStatus), + 'availability_message' => $this->getAvailabilityMessage($request, $availabilityStatus), 'location' => $this->translate('Unknown'), 'locationList' => false, 'reserve' => 'false', diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatusesFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatusesFactory.php index 1e314fd5cc53..00ee472de5d0 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatusesFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatusesFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetItemStatus AJAX handler. @@ -73,7 +74,7 @@ public function __invoke( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigObject('config'), $container->get(\VuFind\ILS\Connection::class), - $container->get('ViewRenderer'), + $container->get(TemplateRendererInterface::class), $container->get(\VuFind\ILS\Logic\Holds::class), $container->get(\VuFind\ILS\Logic\AvailabilityStatusManager::class) ); diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetLibraryPickupLocations.php b/module/VuFind/src/VuFind/AjaxHandler/GetLibraryPickupLocations.php index 4cb51133fb59..02c2676f1cb2 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetLibraryPickupLocations.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetLibraryPickupLocations.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * "Get Library Pickup Locations" AJAX handler. @@ -47,15 +47,15 @@ class GetLibraryPickupLocations extends AbstractIlsAndUserAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $id = $params->fromQuery('id'); - $pickupLib = $params->fromQuery('pickupLib'); + $id = $this->getQueryParam($request, 'id'); + $pickupLib = $this->getQueryParam($request, 'pickupLib'); if (null === $id || null === $pickupLib) { return $this->formatResponse( $this->translate('bulk_error_missing'), diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTML.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTML.php index a5cd2dc8714d..e5163ec68b47 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTML.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTML.php @@ -29,9 +29,9 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Record\Loader; +use VuFind\View\Renderer\TemplateRendererInterface; /** * AJAX handler to get list of comments for a record as HTML. @@ -44,47 +44,33 @@ */ class GetRecordCommentsAsHTML extends AbstractBase { - /** - * Record loader. - * - * @var Loader - */ - protected $loader; - - /** - * View renderer. - * - * @var RendererInterface - */ - protected $renderer; - /** * Constructor. * - * @param Loader $loader Record loader - * @param RendererInterface $renderer View renderer + * @param Loader $loader Record loader + * @param TemplateRendererInterface $renderer Template renderer */ - public function __construct(Loader $loader, RendererInterface $renderer) - { - $this->loader = $loader; - $this->renderer = $renderer; + public function __construct( + protected Loader $loader, + protected TemplateRendererInterface $renderer + ) { + parent::__construct(null); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $driver = $this->loader->load( - $params->fromQuery('id'), - $params->fromQuery('source', DEFAULT_SEARCH_BACKEND) + $this->getQueryParam($request, 'id'), + $this->getQueryParam($request, 'source', DEFAULT_SEARCH_BACKEND) ); - $html = $this->renderer - ->render('record/comments-list.phtml', compact('driver')); + $html = $this->renderer->renderTemplateAsString($request, 'record/comments-list.phtml', compact('driver')); return $this->formatResponse(compact('html')); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTMLFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTMLFactory.php index 4386e89a37f1..93f3ae832952 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTMLFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCommentsAsHTMLFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetRecordCommentsAsHTML AJAX handler. @@ -71,7 +72,7 @@ public function __invoke( } return new $requestedName( $container->get(\VuFind\Record\Loader::class), - $container->get('ViewRenderer') + $container->get(TemplateRendererInterface::class) ); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCover.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCover.php index 4cfd1f48ee66..82d9d4961b9b 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCover.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCover.php @@ -29,12 +29,12 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\PhpRenderer; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Cache\CacheTrait; use VuFind\Cover\Router as CoverRouter; use VuFind\Record\Loader as RecordLoader; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; use function in_array; @@ -51,75 +51,44 @@ class GetRecordCover extends AbstractBase implements AjaxHandlerInterface { use CacheTrait; - /** - * Record loader. - * - * @var RecordLoader - */ - protected $recordLoader; - - /** - * Cover router. - * - * @var CoverRouter - */ - protected $coverRouter; - - /** - * PHP renderer. - * - * @var PhpRenderer - */ - protected $renderer; - - /** - * If true we will render a fallback html template in case no image could be - * loaded. - * - * @var bool - */ - protected $useCoverFallbacksOnFail = false; - /** * GetRecordCover constructor. * - * @param SessionSettings $ss Session settings - * @param RecordLoader $recordLoader Record loader - * @param CoverRouter $coverRouter Cover router - * @param PhpRenderer $renderer PHP renderer (only - * required if $userCoverFallbacksOnFail is set to true) - * @param bool $useCoverFallbacksOnFail If true we will render a - * fallback html template in case no image could be loaded + * @param SessionSettings $ss Session settings + * @param RecordLoader $recordLoader Record loader + * @param CoverRouter $coverRouter Cover router + * @param ?TemplateRendererInterface $renderer Template renderer (required if + * $userCoverFallbacksOnFail is + * set to true) + * @param bool $useCoverFallbacksOnFail If true we will render a + * fallback html template + * in case no image could + * be loaded */ public function __construct( SessionSettings $ss, - RecordLoader $recordLoader, - CoverRouter $coverRouter, - ?PhpRenderer $renderer = null, - $useCoverFallbacksOnFail = false + protected RecordLoader $recordLoader, + protected CoverRouter $coverRouter, + protected ?TemplateRendererInterface $renderer, + protected $useCoverFallbacksOnFail = false ) { - $this->sessionSettings = $ss; - $this->recordLoader = $recordLoader; - $this->coverRouter = $coverRouter; - $this->renderer = $renderer; - $this->useCoverFallbacksOnFail = $useCoverFallbacksOnFail; + parent::__construct($ss); } /** - * Handle request. + * Handle a request. * - * @param Params $params Request parameters + * @param ServerRequestInterface $request Request * - * @return array - * @throws \Exception + * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); - $recordId = $params->fromQuery('recordId'); - $recordSource = $params->fromQuery('source', DEFAULT_SEARCH_BACKEND); - $size = $params->fromQuery('size', 'small'); + $recordId = $this->getQueryParam($request, 'recordId'); + $recordSource = $this->getQueryParam($request, 'source', DEFAULT_SEARCH_BACKEND); + $size = $this->getQueryParam($request, 'size', 'small'); if (!in_array($size, ['small', 'medium', 'large'])) { $size = 'small'; } @@ -136,7 +105,8 @@ public function handleRequest(Params $params) ? $this->formatResponse(array_merge($metadata, compact('size'))) : $this->formatResponse( [ - 'html' => $this->renderer->render( + 'html' => $this->renderer->renderTemplateAsString( + $request, 'record/coverReplacement', ['driver' => $record] ), diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCoverFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCoverFactory.php index 68b40a797a21..b4e5cfb8f511 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordCoverFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordCoverFactory.php @@ -34,6 +34,7 @@ use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetRecordCover AJAX handler. @@ -74,7 +75,7 @@ public function __invoke( $container->get(\VuFind\Record\Loader::class), $container->get(\VuFind\Cover\Router::class), // We only need the view renderer if we're going to use fallbacks: - $useFallbacks ? $container->get('ViewRenderer') : null, + $useFallbacks ? $container->get(TemplateRendererInterface::class) : null, $useFallbacks ); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetails.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetails.php index d53ade14539e..ef2a5e13e0e5 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetails.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetails.php @@ -29,11 +29,11 @@ namespace VuFind\AjaxHandler; -use Laminas\Http\PhpEnvironment\Request; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Laminas\Psr7Bridge\Psr7ServerRequest; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Record\Loader; use VuFind\RecordTab\TabManager; +use VuFind\View\Renderer\TemplateRendererInterface; /** * "Get Record Details" AJAX handler. @@ -48,88 +48,49 @@ */ class GetRecordDetails extends AbstractBase { - /** - * Framework configuration. - * - * @var array - */ - protected $config; - - /** - * Request. - * - * @var Request - */ - protected $request; - - /** - * Record loader. - * - * @var Loader - */ - protected $recordLoader; - - /** - * Record tab plugin manager. - * - * @var TabManager - */ - protected $tabManager; - - /** - * View renderer. - * - * @var RendererInterface - */ - protected $renderer; - /** * Constructor. * - * @param array $config Framework configuration - * @param Request $request HTTP request - * @param Loader $loader Record loader - * @param TabManager $tm Record Tab manager - * @param RendererInterface $renderer Renderer + * @param array $config Framework configuration + * @param Loader $recordLoader Record loader + * @param TabManager $tabManager Record Tab manager + * @param TemplateRendererInterface $renderer Template renderer */ public function __construct( - array $config, - Request $request, - Loader $loader, - TabManager $tm, - RendererInterface $renderer + protected array $config, + protected Loader $recordLoader, + protected TabManager $tabManager, + protected TemplateRendererInterface $renderer, ) { - $this->config = $config; - $this->request = $request; - $this->recordLoader = $loader; - $this->tabManager = $tm; - $this->renderer = $renderer; } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { - $driver = $this->recordLoader - ->load($params->fromQuery('id'), $params->fromQuery('source')); + $driver = $this->recordLoader->load( + $this->getQueryParam($request, 'id'), + $this->getQueryParam($request, 'source') + ); $viewtype = preg_replace( '/\W/', '', - trim(strtolower($params->fromQuery('type'))) + trim(strtolower($this->getQueryParam($request, 'type'))) ); $details = $this->tabManager->getTabDetailsForRecord( $driver, - $this->request, + Psr7ServerRequest::toLaminas($request), 'Information' ); - $html = $this->renderer->render( + $html = $this->renderer->renderTemplateAsString( + $request, 'record/ajaxview-' . $viewtype . '.phtml', [ 'defaultTab' => $details['default'], diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetailsFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetailsFactory.php index d903055aa171..85e8e75ee9d0 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetailsFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordDetailsFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetRecordDetails AJAX handler. @@ -71,10 +72,9 @@ public function __invoke( } return new $requestedName( $container->get('Config'), - $container->get('Request'), $container->get(\VuFind\Record\Loader::class), $container->get(\VuFind\RecordTab\TabManager::class), - $container->get('ViewRenderer') + $container->get(TemplateRendererInterface::class) ); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordRating.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordRating.php index 2a57ce371a01..34fc50a1b20e 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordRating.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordRating.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Ratings\RatingsService; use VuFind\Record\Loader as RecordLoader; use VuFind\View\Helper\Root\Record as RecordHelper; @@ -57,19 +57,20 @@ public function __construct( protected RecordHelper $recordHelper, protected RatingsService $ratingsService ) { + parent::__construct(null); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { - $id = $params->fromQuery('id'); - $source = $params->fromQuery('source', DEFAULT_SEARCH_BACKEND); + $id = $this->getQueryParam($request, 'id'); + $source = $this->getQueryParam($request, 'source', DEFAULT_SEARCH_BACKEND); if (empty($id)) { return $this->formatResponse('', self::STATUS_HTTP_BAD_REQUEST); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordRatingFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordRatingFactory.php index 3020cc75573a..d784eacf67fe 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordRatingFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordRatingFactory.php @@ -34,6 +34,7 @@ use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; use VuFind\Ratings\RatingsService; +use VuFind\View\Helper\Root\Record; /** * Factory for GetRecordRating AJAX handler. @@ -72,7 +73,7 @@ public function __invoke( } return new $requestedName( $container->get(\VuFind\Record\Loader::class), - $container->get('ViewRenderer')->plugin('record'), + $container->get('ViewHelperManager')->get(Record::class), $container->get(RatingsService::class) ); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordTags.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordTags.php index 6508b5b21465..aba31abf8235 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordTags.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordTags.php @@ -29,10 +29,10 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Db\Entity\UserEntityInterface; use VuFind\Tags\TagsService; +use VuFind\View\Renderer\TemplateRendererInterface; /** * AJAX handler to get all tags for a record as HTML. @@ -48,31 +48,32 @@ class GetRecordTags extends AbstractBase /** * Constructor. * - * @param TagsService $tagsService Tags service - * @param ?UserEntityInterface $user Logged in user (or null) - * @param RendererInterface $renderer View renderer + * @param TagsService $tagsService Tags service + * @param ?UserEntityInterface $user Logged in user (or null) + * @param TemplateRendererInterface $renderer Template renderer */ public function __construct( protected TagsService $tagsService, protected ?UserEntityInterface $user, - protected RendererInterface $renderer + protected TemplateRendererInterface $renderer, ) { + parent::__construct(null); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $is_me_id = $this->user?->getId(); // Retrieve from database: - $id = $params->fromQuery('id'); - $source = $params->fromQuery('source', DEFAULT_SEARCH_BACKEND); + $id = $this->getQueryParam($request, 'id'); + $source = $this->getQueryParam($request, 'source', DEFAULT_SEARCH_BACKEND); $tags = $this->tagsService->getRecordTags( $id, $source, @@ -94,7 +95,7 @@ public function handleRequest(Params $params) } $viewParams = ['tagList' => $tagList, 'loggedin' => (bool)$this->user, 'driver' => "$source|$id"]; - $html = $this->renderer->render('record/taglist', $viewParams); + $html = $this->renderer->renderTemplateAsString($request, 'record/taglist', $viewParams); return $this->formatResponse(compact('html')); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordTagsFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordTagsFactory.php index 3097f8b071c2..15088b76e864 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordTagsFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordTagsFactory.php @@ -34,6 +34,7 @@ use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; use VuFind\Tags\TagsService; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetRecordTags AJAX handler. @@ -73,7 +74,7 @@ public function __invoke( return new $requestedName( $container->get(TagsService::class), $container->get(\VuFind\Auth\Manager::class)->getUserObject(), - $container->get('ViewRenderer') + $container->get(TemplateRendererInterface::class) ); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersions.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersions.php index 4e2743f23557..16542bf6bb3f 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersions.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersions.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Record\Loader; use VuFind\RecordTab\TabManager; use VuFind\Session\Settings as SessionSettings; @@ -84,7 +84,7 @@ public function __construct( Record $rp, TabManager $tm ) { - $this->sessionSettings = $ss; + parent::__construct($ss); $this->recordLoader = $loader; $this->recordPlugin = $rp; $this->tabManager = $tm; @@ -114,17 +114,17 @@ protected function getVersionsLinkForRecord($id, $source, $searchId) /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $id = $params->fromPost('id') ?: $params->fromQuery('id'); - $source = $params->fromPost('source') ?: $params->fromQuery('source'); - $searchId = $params->fromPost('sid') ?: $params->fromQuery('sid'); + $id = $this->getPostOrQueryParam($request, 'id'); + $source = $this->getPostOrQueryParam($request, 'source'); + $searchId = $this->getPostOrQueryParam($request, 'sid'); if (!is_array($id)) { return $this->formatResponse( diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersionsFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersionsFactory.php index 411fe9f0fc54..db5f1c08b8e8 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersionsFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRecordVersionsFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Helper\Root\Record; /** * Factory for GetRecordVersions AJAX handler. @@ -72,7 +73,7 @@ public function __invoke( $result = new $requestedName( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\Record\Loader::class), - $container->get('ViewRenderer')->plugin('record'), + $container->get('ViewHelperManager')->get(Record::class), $container->get(\VuFind\RecordTab\TabManager::class) ); return $result; diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetRequestGroupPickupLocations.php b/module/VuFind/src/VuFind/AjaxHandler/GetRequestGroupPickupLocations.php index f45ffcaa1c59..294a6d7ebc0c 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetRequestGroupPickupLocations.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetRequestGroupPickupLocations.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * "Get Request Group Pickup Locations" AJAX handler. @@ -47,15 +47,15 @@ class GetRequestGroupPickupLocations extends AbstractIlsAndUserAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $id = $params->fromQuery('id'); - $requestGroupId = $params->fromQuery('requestGroupId'); + $id = $this->getQueryParam($request, 'id'); + $requestGroupId = $this->getQueryParam($request, 'requestGroupId'); if (null === $id || null === $requestGroupId) { return $this->formatResponse( $this->translate('bulk_error_missing'), diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinks.php b/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinks.php index 1d0c46b190fc..7b377bc459a7 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinks.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinks.php @@ -30,13 +30,13 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Config\Config; use VuFind\I18n\Translator\TranslatorAwareInterface; use VuFind\Resolver\Connection; use VuFind\Resolver\Driver\PluginManager as ResolverManager; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; /** * "Get Resolver Links" AJAX handler. @@ -55,59 +55,35 @@ class GetResolverLinks extends AbstractBase implements TranslatorAwareInterface { use \VuFind\I18n\Translator\TranslatorAwareTrait; - /** - * Resolver driver plugin manager. - * - * @var ResolverManager - */ - protected $pluginManager; - - /** - * View renderer. - * - * @var RendererInterface - */ - protected $renderer; - - /** - * Top-level VuFind configuration (config.ini). - * - * @var Config - */ - protected $config; - /** * Constructor. * - * @param SessionSettings $ss Session settings - * @param ResolverManager $pm Resolver driver plugin manager - * @param RendererInterface $renderer View renderer - * @param Config $config Top-level VuFind configuration (config.ini) + * @param SessionSettings $ss Session settings + * @param ResolverManager $pluginManager Resolver driver plugin manager + * @param TemplateRendererInterface $renderer Template renderer + * @param Config $config Top-level VuFind configuration (config.ini) */ public function __construct( SessionSettings $ss, - ResolverManager $pm, - RendererInterface $renderer, - Config $config + protected ResolverManager $pluginManager, + protected TemplateRendererInterface $renderer, + protected Config $config ) { - $this->sessionSettings = $ss; - $this->pluginManager = $pm; - $this->renderer = $renderer; - $this->config = $config; + parent::__construct($ss); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $openUrl = $params->fromQuery('openurl', ''); - $searchClassId = $params->fromQuery('searchClassId', ''); + $openUrl = $this->getQueryParam($request, 'openurl', ''); + $searchClassId = $this->getQueryParam($request, 'searchClassId', ''); $resolverType = $this->config->OpenURL->resolver ?? 'generic'; if (!$this->pluginManager->has($resolverType)) { @@ -165,7 +141,7 @@ public function handleRequest(Params $params) 'searchClassId' => $searchClassId, 'moreOptionsLink' => $moreOptionsLink, ]; - $html = $this->renderer->render('ajax/resolverLinks.phtml', $view); + $html = $this->renderer->renderTemplateAsString($request, 'ajax/resolverLinks.phtml', $view); // output HTML encoded in JSON object return $this->formatResponse(compact('html')); diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinksFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinksFactory.php index 06e0cc491388..c718e8174a9e 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinksFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetResolverLinksFactory.php @@ -33,6 +33,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetResolverLinks AJAX handler. @@ -72,7 +73,7 @@ public function __invoke( return new $requestedName( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\Resolver\Driver\PluginManager::class), - $container->get('ViewRenderer'), + $container->get(TemplateRendererInterface::class), $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigObject('config') ); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetResultCount.php b/module/VuFind/src/VuFind/AjaxHandler/GetResultCount.php index 7f13cabf5b8f..1ff177668c02 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetResultCount.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetResultCount.php @@ -31,8 +31,8 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Stdlib\Parameters; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Search\Results\PluginManager as ResultsManager; use VuFind\Session\Settings as SessionSettings; @@ -64,23 +64,23 @@ class GetResultCount extends AbstractBase public function __construct(ResultsManager $resultsManager, SessionSettings $ss) { $this->resultsManager = $resultsManager; - $this->sessionSettings = $ss; + parent::__construct($ss); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); - $queryString = $params->fromQuery('querystring'); + $queryString = $this->getQueryParam($request, 'querystring'); parse_str(parse_url($queryString, PHP_URL_QUERY), $searchParams); - $backend = $params->fromQuery('source', DEFAULT_SEARCH_BACKEND); + $backend = $this->getQueryParam($request, 'source', DEFAULT_SEARCH_BACKEND); $results = $this->resultsManager->get($backend); $paramsObj = $results->getParams(); $paramsObj->getOptions()->disableHighlighting(); diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetSaveStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetSaveStatuses.php index ec3f3c1bc108..df8e9c0dff43 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetSaveStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetSaveStatuses.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Db\Entity\UserEntityInterface; use VuFind\Db\Entity\UserResourceEntityInterface; use VuFind\Db\Service\UserResourceServiceInterface; @@ -68,7 +68,7 @@ public function __construct( protected RouteHelper $routeHelper, protected UserResourceServiceInterface $userResourceService ) { - $this->sessionSettings = $ss; + parent::__construct($ss); } /** @@ -117,11 +117,11 @@ protected function getDataFromUser($ids, $sources) /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug // check if user is logged in @@ -133,8 +133,8 @@ public function handleRequest(Params $params) } // loop through each ID check if it is saved to any of the user's lists - $ids = $params->fromPost('id', $params->fromQuery('id', [])); - $sources = $params->fromPost('source', $params->fromQuery('source', [])); + $ids = $this->getPostOrQueryParam($request, 'id', []); + $sources = $this->getPostOrQueryParam($request, 'source', []); if (!is_array($ids) || !is_array($sources)) { return $this->formatResponse( $this->translate('Argument must be array.'), diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php b/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php index 7827f3065c61..9e8f23f67270 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php @@ -29,10 +29,11 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params as ParamsHelper; use Laminas\Stdlib\Parameters; -use Laminas\View\Model\ViewModel; -use Laminas\View\Renderer\PhpRenderer; +use Laminas\View\Helper\EscapeHtml; +use Laminas\View\Helper\PaginationControl; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\Cart; use VuFind\Db\Entity\UserEntityInterface; use VuFind\Record\Loader as RecordLoader; use VuFind\Search\Base\Results; @@ -41,6 +42,8 @@ use VuFind\Search\ResultScroller; use VuFind\Search\SearchNormalizer; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Helper\Root\LocalizedNumber; +use VuFind\View\Renderer\TemplateRendererInterface; use function call_user_func; @@ -109,67 +112,75 @@ class GetSearchResults extends \VuFind\AjaxHandler\AbstractBase implements /** * Constructor. * - * @param SessionSettings $sessionSettings Session settings - * @param ResultsManager $resultsManager Results Manager - * @param PhpRenderer $renderer View renderer - * @param RecordLoader $recordLoader Record loader - * @param ?UserEntityInterface $user Logged-in user - * @param string $sessionId Session ID - * @param SearchNormalizer $searchNormalizer Search normalizer - * @param array $config Main configuration - * @param Memory $searchMemory Search memory - * @param ResultScroller $resultScroller Result scroller helper + * @param SessionSettings $sessionSettings Session settings + * @param ResultsManager $resultsManager Results Manager + * @param TemplateRendererInterface $renderer Template renderer + * @param RecordLoader $recordLoader Record loader + * @param ?UserEntityInterface $user Logged-in user + * @param string $sessionId Session ID + * @param SearchNormalizer $searchNormalizer Search normalizer + * @param array $config Main configuration + * @param Memory $searchMemory Search memory + * @param ResultScroller $resultScroller Result scroller helper + * @param Cart $cart Cart service + * @param PaginationControl $paginationControl Pagination control view helper + * @param LocalizedNumber $localizedNumber Localized number view helper + * @param EscapeHtml $escapeHtml Escape HTML view helper */ public function __construct( SessionSettings $sessionSettings, protected ResultsManager $resultsManager, - protected PhpRenderer $renderer, + protected TemplateRendererInterface $renderer, protected RecordLoader $recordLoader, protected ?UserEntityInterface $user, protected string $sessionId, protected SearchNormalizer $searchNormalizer, protected array $config, protected Memory $searchMemory, - protected ResultScroller $resultScroller + protected ResultScroller $resultScroller, + protected Cart $cart, + protected PaginationControl $paginationControl, + protected LocalizedNumber $localizedNumber, + protected EscapeHtml $escapeHtml, ) { - $this->sessionSettings = $sessionSettings; + parent::__construct($sessionSettings); } /** * Handle a request. * - * @param ParamsHelper $requestParams Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(ParamsHelper $requestParams) + public function handleRequest(ServerRequestInterface $request): array { - $results = $this->getSearchResults($requestParams); + $results = $this->getSearchResults($request); if (!$results) { return $this->formatResponse(['error' => 'Invalid request'], 400); } - $elements = $this->getElements($requestParams, $results); + $elements = $this->getElements($request, $results); return $this->formatResponse(compact('elements')); } /** * Get search results. * - * @param ParamsHelper $requestParams Request params + * @param ServerRequestInterface $request Request * * @return ?Results */ - protected function getSearchResults(ParamsHelper $requestParams): ?Results + protected function getSearchResults(ServerRequestInterface $request): ?Results { - parse_str($requestParams->fromQuery('querystring', ''), $searchParams); - $backend = $requestParams->fromQuery('source', DEFAULT_SEARCH_BACKEND); + parse_str($this->getQueryParam($request, 'querystring', ''), $searchParams); + $backend = $this->getQueryParam($request, 'source', DEFAULT_SEARCH_BACKEND); $results = $this->resultsManager->get($backend); $paramsObj = $results->getParams(); $paramsObj->getOptions()->spellcheckEnabled(false); $paramsObj->initFromRequest(new Parameters($searchParams)); - if ($requestParams->fromQuery('history')) { + if ($this->getQueryParam($request, 'history')) { $this->saveSearchToHistory($results); } @@ -187,16 +198,16 @@ protected function getSearchResults(ParamsHelper $requestParams): ?Results /** * Render page elements. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param Results $results Search results * * @return array */ - protected function getElements(ParamsHelper $requestParams, Results $results): array + protected function getElements(ServerRequestInterface $request, Results $results): array { $result = []; foreach ($this->elements as $selector => $element) { - $content = call_user_func([$this, $element['method']], $requestParams, $results); + $content = call_user_func([$this, $element['method']], $request, $results); if (null !== $content) { $result[$selector] = [ 'content' => $content, @@ -211,32 +222,32 @@ protected function getElements(ParamsHelper $requestParams, Results $results): a /** * Render search results. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param Results $results Search results * * @return ?string */ - protected function renderResults(ParamsHelper $requestParams, Results $results): ?string + protected function renderResults(ServerRequestInterface $request, Results $results): ?string { [$baseAction] = explode('-', $results->getOptions()->getSearchAction()); $templatePath = "$baseAction/results-list.phtml"; - if ('search' !== $baseAction && !$this->renderer->resolver($templatePath)) { + if ('search' !== $baseAction && !$this->renderer->resolveTemplateFilename($templatePath)) { $templatePath = 'search/results-list.phtml'; } $options = $results->getOptions(); - $cart = $this->renderer->plugin('cart'); $showBulkOptions = $options->supportsCart() && ($this->config['Site']['showBulkOptions'] ?? false); // Checkboxes if appropriate: $showCartControls = $options->supportsCart() - && $cart()->isActive() - && ($showBulkOptions || !$cart()->isActiveInSearch()); + && $this->cart->isActive() + && ($showBulkOptions || !$this->cart->isActiveInSearch()); // Enable bulk options if appropriate: $showCheckboxes = $showCartControls || $showBulkOptions; // Include request parameters: - parse_str($requestParams->fromQuery('querystring', ''), $searchQueryParams); + parse_str($this->getQueryParam($request, 'querystring', ''), $searchQueryParams); - return $this->renderer->render( + return $this->renderer->renderTemplateAsString( + $request, $templatePath, [ 'request' => $searchQueryParams, @@ -245,7 +256,7 @@ protected function renderResults(ParamsHelper $requestParams, Results $results): 'showBulkOptions' => $showBulkOptions, 'showCartControls' => $showCartControls, 'showCheckboxes' => $showCheckboxes, - 'saveToHistory' => (bool)$requestParams->fromQuery('history', false), + 'saveToHistory' => (bool)$this->getQueryParam($request, 'history', false), ] ); } @@ -253,18 +264,18 @@ protected function renderResults(ParamsHelper $requestParams, Results $results): /** * Render pagination. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results - * @param string $template Paginator template - * @param string $ulClass Additional class for the pagination container - * @param string $navClass Additional class for the nav element + * @param ServerRequestInterface $request Request + * @param Results $results Search results + * @param string $template Paginator template + * @param string $ulClass Additional class for the pagination container + * @param string $navClass Additional class for the nav element * * @return ?string * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function renderPagination( - ParamsHelper $requestParams, + ServerRequestInterface $request, Results $results, string $template = 'Helpers/pagination.phtml', string $ulClass = '', @@ -277,8 +288,7 @@ protected function renderPagination( if ($navClass) { $paginationOptions['navClassName'] = $navClass; } - $pagination = $this->renderer->plugin('paginationControl'); - return $pagination( + return ($this->paginationControl)( $results->getPaginator(), 'Sliding', $template, @@ -289,52 +299,56 @@ protected function renderPagination( /** * Render simple pagination. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param Results $results Search results * * @return ?string */ - protected function renderPaginationSimple(ParamsHelper $requestParams, Results $results): ?string - { - return $this->renderPagination($requestParams, $results, 'Helpers/pagination-simple.phtml'); + protected function renderPaginationSimple( + ServerRequestInterface $request, + Results $results + ): ?string { + return $this->renderPagination($request, $results, 'Helpers/pagination-simple.phtml'); } /** * Render top pagination. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param Results $results Search results * * @return ?string */ - protected function renderPaginationTop(ParamsHelper $requestParams, Results $results): ?string - { - return $this->renderPagination($requestParams, $results, 'Helpers/pagination-top.phtml'); + protected function renderPaginationTop( + ServerRequestInterface $request, + Results $results + ): ?string { + return $this->renderPagination($request, $results, 'Helpers/pagination-top.phtml'); } /** * Render search stats. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param Results $results Search results * * @return ?string */ - protected function renderSearchStats(ParamsHelper $requestParams, Results $results): ?string - { - if (!($statsKey = $requestParams->fromQuery('statsKey'))) { + protected function renderSearchStats( + ServerRequestInterface $request, + Results $results + ): ?string { + if (!($statsKey = $this->getQueryParam($request, 'statsKey'))) { return null; } - $localizedNumber = $this->renderer->plugin('localizedNumber'); - $escapeHtml = $this->renderer->plugin('escapeHtml'); $lookfor = $results->getUrlQuery()->isQuerySuppressed() ? '' : $results->getParams()->getDisplayQuery(); $transParams = [ - '%%start%%' => $localizedNumber($results->getStartRecord()), - '%%end%%' => $localizedNumber($results->getEndRecord()), - '%%total%%' => $localizedNumber($results->getResultTotal()), - '%%lookfor%%' => $escapeHtml($lookfor), + '%%start%%' => ($this->localizedNumber)($results->getStartRecord()), + '%%end%%' => ($this->localizedNumber)($results->getEndRecord()), + '%%total%%' => ($this->localizedNumber)($results->getResultTotal()), + '%%lookfor%%' => ($this->escapeHtml)($lookfor), ]; return $this->translate($statsKey, $transParams); @@ -343,21 +357,29 @@ protected function renderSearchStats(ParamsHelper $requestParams, Results $resul /** * Render analytics. * - * @param ParamsHelper $requestParams Request params - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param Results $results Search results * * @return ?string * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - protected function renderAnalytics(ParamsHelper $requestParams, Results $results): ?string - { + protected function renderAnalytics( + ServerRequestInterface $request, + Results $results + ): ?string { // Mimic the typical page structure so that analytics helpers can find the // search results: - $view = new ViewModel(); - $view->setTemplate('Helpers/analytics.phtml'); - $view->addChild(new ViewModel(compact('results'))); - return $this->renderer->render($view); + return $this->renderer->renderTemplateAsString( + $request, + 'Helpers/analytics.phtml', + childTemplates: [ + [ + 'template' => 'layout/bare.phtml', + 'params' => compact('results'), + ], + ] + ); } /** diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetSearchResultsFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetSearchResultsFactory.php index 640fb0224263..b99b22c1477b 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetSearchResultsFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetSearchResultsFactory.php @@ -31,8 +31,13 @@ use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\Exception\ServiceNotFoundException; +use Laminas\View\Helper\EscapeHtml; +use Laminas\View\Helper\PaginationControl; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\Cart; +use VuFind\View\Helper\Root\LocalizedNumber; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetSearchResults AJAX handler. @@ -69,17 +74,22 @@ public function __invoke( if (!empty($options)) { throw new \Exception('Unexpected options passed to factory.'); } + $viewHelperManager = $container->get('ViewHelperManager'); $result = new $requestedName( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\Search\Results\PluginManager::class), - $container->get('ViewRenderer'), + $container->get(TemplateRendererInterface::class), $container->get(\VuFind\Record\Loader::class), $container->get(\VuFind\Auth\Manager::class)->getUserObject(), $container->get(\Laminas\Session\SessionManager::class)->getId(), $container->get(\VuFind\Search\SearchNormalizer::class), $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigArray('config'), $container->get(\VuFind\Search\Memory::class), - $container->get(\VuFind\Search\ResultScroller::class) + $container->get(\VuFind\Search\ResultScroller::class), + $container->get(Cart::class), + $viewHelperManager->get(PaginationControl::class), + $viewHelperManager->get(LocalizedNumber::class), + $viewHelperManager->get(EscapeHtml::class), ); return $result; } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetSideFacets.php b/module/VuFind/src/VuFind/AjaxHandler/GetSideFacets.php index ddd9df9cb4ff..464ce0166110 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetSideFacets.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetSideFacets.php @@ -30,14 +30,14 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Recommend\PluginManager as RecommendPluginManager; use VuFind\Recommend\SideFacets; use VuFind\Search\Base\Results; use VuFind\Search\RecommendListener; use VuFind\Search\SearchRunner; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; use function in_array; use function is_callable; @@ -56,63 +56,36 @@ class GetSideFacets extends \VuFind\AjaxHandler\AbstractBase implements \Psr\Log { use \VuFind\Log\LoggerAwareTrait; - /** - * Recommend plugin manager. - * - * @var RecommendPluginManager - */ - protected $recommendPluginManager; - - /** - * Search runner. - * - * @var SearchRunner - */ - protected $searchRunner; - - /** - * View renderer. - * - * @var RendererInterface - */ - protected $renderer; - /** * Constructor. * - * @param SessionSettings $ss Session settings - * @param RecommendPluginManager $rpm Recommend plugin manager - * @param SearchRunner $sr Search runner - * @param RendererInterface $renderer View renderer + * @param SessionSettings $ss Session settings + * @param RecommendPluginManager $recommendPluginManager Recommend plugin manager + * @param SearchRunner $searchRunner Search runner + * @param TemplateRendererInterface $renderer Template renderer */ public function __construct( SessionSettings $ss, - \VuFind\Recommend\PluginManager $rpm, - SearchRunner $sr, - RendererInterface $renderer + protected \VuFind\Recommend\PluginManager $recommendPluginManager, + protected SearchRunner $searchRunner, + protected TemplateRendererInterface $renderer ) { - $this->sessionSettings = $ss; - $this->recommendPluginManager = $rpm; - $this->searchRunner = $sr; - $this->renderer = $renderer; + parent::__construct($ss); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - // Allow both GET and POST variables: - $request = $params->fromQuery() + $params->fromPost(); - - $configIndex = $request['configIndex'] ?? 0; - $configLocation = $request['location'] ?? 'side'; + $configIndex = $this->getPostOrQueryParam($request, 'configIndex', 0); + $configLocation = $this->getPostOrQueryParam($request, 'location', 'side'); $results = $this->getFacetResults($request, $configIndex, $configLocation); if ($results instanceof \VuFind\Search\EmptySet\Results) { $this->logError('Faceting request failed'); @@ -121,11 +94,11 @@ public function handleRequest(Params $params) // Set appropriate query suppression / extra field behavior: $queryHelper = $results->getUrlQuery(); - $queryHelper->setSuppressQuery((bool)($request['querySuppressed'] ?? false)); - $extraFields = array_filter(explode(',', $request['extraFields'] ?? '')); + $queryHelper->setSuppressQuery((bool)($this->getPostOrQueryParam($request, 'querySuppressed', false))); + $extraFields = array_filter(explode(',', $this->getPostOrQueryParam($request, 'extraFields', ''))); foreach ($extraFields as $field) { - if (isset($request[$field])) { - $queryHelper->setDefaultParameter($field, $request[$field]); + if (null !== ($value = $this->getPostOrQueryParam($request, $field))) { + $queryHelper->setDefaultParameter($field, $value); } } @@ -140,21 +113,23 @@ public function handleRequest(Params $params) $context = [ 'recommend' => $recommend, 'params' => $results->getParams(), - 'searchClassId' => $request['searchClassId'] ?? DEFAULT_SEARCH_BACKEND, + 'searchClassId' => $this->getPostOrQueryParam($request, 'searchClassId', DEFAULT_SEARCH_BACKEND), ]; - if (isset($request['enabledFacets'])) { + if ($enabledFacets = $this->getPostOrQueryParam($request, 'enabledFacets')) { // Render requested facets separately $facets = $this->formatFacets( + $request, $context, $recommend, - $request['enabledFacets'], + (array)$enabledFacets, $results ); return $this->formatResponse(compact('facets')); } // Render full sidefacets - $html = $this->renderer->render( + $html = $this->renderer->renderTemplateAsString( + $request, 'Recommend/SideFacets.phtml', $context ); @@ -164,13 +139,13 @@ public function handleRequest(Params $params) /** * Perform search and return the results. * - * @param array $request Request params - * @param string $index Index of SideFacetsDeferred in configuration - * @param string $loc Location where SideFacetsDeferred is configured + * @param ServerRequestInterface $request Request + * @param string $index Index of SideFacetsDeferred in configuration + * @param string $loc Location where SideFacetsDeferred is configured * * @return Results */ - protected function getFacetResults(array $request, $index, $loc) + protected function getFacetResults(ServerRequestInterface $request, $index, $loc) { $setupCallback = function ($runner, $params, $searchId) use ($index, $loc): void { $listener = new RecommendListener( @@ -199,12 +174,12 @@ protected function getFacetResults(array $request, $index, $loc) $runner = $this->searchRunner; $results = $runner->run( - $request, - $request['searchClassId'] ?? DEFAULT_SEARCH_BACKEND, + $request->getParsedBody() + $request->getQueryParams(), + $this->getPostOrQueryParam($request, 'searchClassId', DEFAULT_SEARCH_BACKEND), $setupCallback ); // Restore limit overridden by the setup callback above: - if ($limit = $request['limit'] ?? null) { + if ($limit = $this->getPostOrQueryParam($request, 'limit')) { $results->getParams()->setLimit($limit); } return $results; @@ -213,14 +188,16 @@ protected function getFacetResults(array $request, $index, $loc) /** * Format facets according to their type. * - * @param array $context View rendering context - * @param SideFacets $recommend Recommendation module - * @param array $facets Facets to process - * @param Results $results Search results + * @param ServerRequestInterface $request Request + * @param array $context View rendering context + * @param SideFacets $recommend Recommendation module + * @param array $facets Facets to process + * @param Results $results Search results * * @return array */ protected function formatFacets( + ServerRequestInterface $request, $context, SideFacets $recommend, $facets, @@ -239,7 +216,8 @@ protected function formatFacets( 'list' => [], ]; $context['collapsedFacets'] = []; - $response[$facet]['html'] = $this->renderer->render( + $response[$facet]['html'] = $this->renderer->renderTemplateAsString( + $request, 'Recommend/SideFacets/facet.phtml', $context ); diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetSideFacetsFactory.php b/module/VuFind/src/VuFind/AjaxHandler/GetSideFacetsFactory.php index d12cb1aa2ccf..1846e6fb7905 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetSideFacetsFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetSideFacetsFactory.php @@ -34,6 +34,7 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for GetSideFacets AJAX handler. @@ -75,7 +76,7 @@ public function __invoke( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\Recommend\PluginManager::class), $container->get(\VuFind\Search\SearchRunner::class), - $container->get('ViewRenderer') + $container->get(TemplateRendererInterface::class) ); return $result; } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetUserFines.php b/module/VuFind/src/VuFind/AjaxHandler/GetUserFines.php index 8bb36e6deea9..44510f51c3e3 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetUserFines.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetUserFines.php @@ -29,14 +29,14 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\PhpRenderer; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Account\AccountStatusLevelType; use VuFind\Auth\ILSAuthenticator; use VuFind\Db\Entity\UserEntityInterface; use VuFind\ILS\Connection; use VuFind\Service\CurrencyFormatter; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Renderer\TemplateRendererInterface; /** * "Get User Fines" AJAX handler. @@ -54,19 +54,19 @@ class GetUserFines extends AbstractIlsUserAndRendererAction /** * Constructor. * - * @param SessionSettings $ss Session settings - * @param Connection $ils ILS connection - * @param ILSAuthenticator $ilsAuthenticator ILS authenticator - * @param ?UserEntityInterface $user Logged in user (or false) - * @param PhpRenderer $renderer Renderer - * @param CurrencyFormatter $currencyFormatter Currency formatter + * @param SessionSettings $ss Session settings + * @param Connection $ils ILS connection + * @param ILSAuthenticator $ilsAuthenticator ILS authenticator + * @param ?UserEntityInterface $user Logged in user (or false) + * @param TemplateRendererInterface $renderer Renderer + * @param CurrencyFormatter $currencyFormatter Currency formatter */ public function __construct( SessionSettings $ss, Connection $ils, ILSAuthenticator $ilsAuthenticator, ?UserEntityInterface $user, - PhpRenderer $renderer, + TemplateRendererInterface $renderer, protected CurrencyFormatter $currencyFormatter, ) { parent::__construct($ss, $ils, $ilsAuthenticator, $user, $renderer); @@ -75,11 +75,11 @@ public function __construct( /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * - * @return array [response data, internal status code, HTTP status code] + * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug $patron = $this->ilsAuthenticator->storedCatalogLogin(); @@ -92,7 +92,7 @@ public function handleRequest(Params $params) $fines = $this->ils->getMyFines($patron); $result = $this->getFineSummary($fines, $this->currencyFormatter); $result['level'] = $this->getAccountStatusLevel($result); - $result['html'] = $this->renderer->render('ajax/account/fines.phtml', $result); + $result['html'] = $this->renderer->renderTemplateAsString($request, 'ajax/account/fines.phtml', $result); return $this->formatResponse($result); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php b/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php index 46e0557ab614..c8134df0f0c1 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetUserTransactions.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Account\AccountStatusLevelType; /** @@ -55,11 +55,11 @@ class GetUserTransactions extends AbstractIlsUserAndRendererAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * - * @return array [response data, internal status code, HTTP status code] + * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug $patron = $this->ilsAuthenticator->storedCatalogLogin(); @@ -90,7 +90,7 @@ public function handleRequest(Params $params) } while ($page <= $pageEnd); $result['level'] = $this->getAccountStatusLevel($result); - $result['html'] = $this->renderer->render('ajax/account/checkouts.phtml', $result); + $result['html'] = $this->renderer->renderTemplateAsString($request, 'ajax/account/checkouts.phtml', $result); return $this->formatResponse($result); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetVisData.php b/module/VuFind/src/VuFind/AjaxHandler/GetVisData.php index 48b7aa44a8f4..377b60dcd0bb 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetVisData.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetVisData.php @@ -31,8 +31,8 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Stdlib\Parameters; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Recommend\DateFacetTrait; use VuFind\Search\Base\DateRangeOptionsInterface; use VuFind\Search\Solr\Results; @@ -70,7 +70,7 @@ class GetVisData extends AbstractBase */ public function __construct(SessionSettings $ss, Results $results) { - $this->sessionSettings = $ss; + parent::__construct($ss); $this->results = $results; } @@ -116,22 +116,22 @@ protected function processFacetValues($filters, $fields) /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug $paramsObj = $this->results->getParams(); - $paramsObj->initFromRequest(new Parameters($params->fromQuery())); - foreach ($params->fromQuery('hf', []) as $hf) { + $paramsObj->initFromRequest(new Parameters($request->getQueryParams())); + foreach ((array)$this->getQueryParam($request, 'hf', []) as $hf) { $paramsObj->addHiddenFilter($hf); } $paramsObj->getOptions()->disableHighlighting(); $paramsObj->getOptions()->spellcheckEnabled(false); $filters = $paramsObj->getRawFilters(); - $rawDateFacets = $params->fromQuery('facetFields'); + $rawDateFacets = $this->getQueryParam($request, 'facetFields'); $dateFacets = empty($rawDateFacets) ? [] : explode(':', $rawDateFacets); $fields = $this->processDateFacets($this->results, $filters, $dateFacets); $facets = $this->processFacetValues($filters, $fields); diff --git a/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookup.php b/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookup.php index 9651176ba601..fbebc78ce10e 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookup.php +++ b/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookup.php @@ -29,9 +29,12 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use Laminas\View\Renderer\RendererInterface; -use VuFind\IdentifierLinker\PluginManager; +use Psr\Http\Message\ServerRequestInterface; +use VuFind\Http\RouteHelper; +use VuFind\Http\ServerUrlHelper; +use VuFind\IdentifierLinker\PluginManager as LinkerPluginManager; +use VuFind\View\Helper\Root\Icon; +use VuFind\View\Renderer\TemplateRendererInterface; use function count; @@ -78,15 +81,22 @@ class IdentifierLinksLookup extends AbstractBase /** * Constructor. * - * @param PluginManager $pluginManager Identifier Linker Plugin Manager - * @param RendererInterface $viewRenderer View renderer - * @param array $config Main configuration + * @param LinkerPluginManager $pluginManager Identifier Linker Plugin Manager + * @param TemplateRendererInterface $renderer Template renderer + * @param ServerUrlHelper $serverUrlHelper Server URL helper + * @param RouteHelper $routeHelper Route helper + * @param Icon $iconHelper Icon helper + * @param array $config Main configuration */ public function __construct( - protected PluginManager $pluginManager, - protected RendererInterface $viewRenderer, + protected LinkerPluginManager $pluginManager, + protected TemplateRendererInterface $renderer, + protected ServerUrlHelper $serverUrlHelper, + protected RouteHelper $routeHelper, + protected Icon $iconHelper, array $config ) { + parent::__construct(null); // DOI config section is supported as a legacy fallback for back-compatibility: $idConfig = $config['IdentifierLinks'] ?? $config['DOI'] ?? []; $this->resolvers @@ -103,14 +113,16 @@ public function __construct( /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $gatheredData = []; - $ids = json_decode($params->getController()->getRequest()->getContent(), true); + $stream = $request->getBody(); + $stream->rewind(); + $ids = json_decode($stream->getContents(), true); foreach ($this->resolvers as $resolver) { if ($this->pluginManager->has($resolver)) { $next = $this->pluginManager->get($resolver)->getLinks($ids); @@ -132,21 +144,26 @@ public function handleRequest(Params $params) } } } - $response = array_map([$this, 'renderResponseChunk'], $gatheredData); + $response = array_map(fn ($data) => $this->renderResponseChunk($request, $data), $gatheredData); return $this->formatResponse($response); } /** * Render the links for a single record. * - * @param array $data Data to render + * @param ServerRequestInterface $request Request + * @param array $data Data to render * * @return string */ - protected function renderResponseChunk(array $data): string + protected function renderResponseChunk(ServerRequestInterface $request, array $data): string { $newWindow = $this->openInNewWindow; - return $this->viewRenderer->render('ajax/identifierLinks.phtml', compact('data', 'newWindow')); + return $this->renderer->renderTemplateAsString( + $request, + 'ajax/identifierLinks.phtml', + compact('data', 'newWindow') + ); } /** @@ -158,23 +175,19 @@ protected function renderResponseChunk(array $data): string */ protected function processIconLinks(array $data): array { - $serverHelper = $this->viewRenderer->plugin('serverurl'); - $urlHelper = $this->viewRenderer->plugin('url'); - $iconHelper = $this->viewRenderer->plugin('icon'); - foreach ($data as &$links) { foreach ($links as &$link) { if ($this->proxyIcons && !empty($link['icon'])) { - $link['icon'] = $serverHelper( - $urlHelper( + $link['icon'] = $this->serverUrlHelper->getUrlForPath( + $this->routeHelper->getUrlFromRoute( 'cover-show', [], - ['query' => ['proxy' => $link['icon']]] + ['proxy' => $link['icon']] ) ); } if (!empty($link['localIcon'])) { - $link['localIcon'] = $iconHelper($link['localIcon'], 'icon-link__icon'); + $link['localIcon'] = ($this->iconHelper)($link['localIcon'], 'icon-link__icon'); } } unset($link); diff --git a/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookupFactory.php b/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookupFactory.php index e178d63d91c2..6cb78272ca84 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookupFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/IdentifierLinksLookupFactory.php @@ -33,6 +33,10 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; +use VuFind\Http\RouteHelper; +use VuFind\Http\ServerUrlHelper; +use VuFind\View\Helper\Root\Icon; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for IdentifierLinksLookup AJAX handler. @@ -72,7 +76,10 @@ public function __invoke( $config = $container->get(\VuFind\Config\ConfigManagerInterface::class)->getConfigArray('config'); return new $requestedName( $container->get(\VuFind\IdentifierLinker\PluginManager::class), - $container->get('ViewRenderer'), + $container->get(TemplateRendererInterface::class), + $container->get(ServerUrlHelper::class), + $container->get(RouteHelper::class), + $container->get('ViewHelperManager')->get(Icon::class), $config ); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/KeepAlive.php b/module/VuFind/src/VuFind/AjaxHandler/KeepAlive.php index eab2103fc2c5..330a0300fb38 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/KeepAlive.php +++ b/module/VuFind/src/VuFind/AjaxHandler/KeepAlive.php @@ -29,8 +29,8 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Session\SessionManager; +use Psr\Http\Message\ServerRequestInterface; /** * "Keep Alive" AJAX handler. @@ -60,19 +60,18 @@ class KeepAlive extends AbstractBase */ public function __construct(SessionManager $sm) { + parent::__construct(null); $this->sessionManager = $sm; } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { // Request ID from session to mark it active $this->sessionManager->getId(); diff --git a/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentNotify.php b/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentNotify.php index 3113a28df3b6..979db1d89192 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentNotify.php +++ b/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentNotify.php @@ -31,12 +31,10 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; -use VuFind\Controller\AjaxController; +use GuzzleHttp\Psr7\Message; +use Laminas\Psr7Bridge\Psr7ServerRequest; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Db\Type\AuditEventSubtype; -use VuFind\Http\PhpEnvironment\Request; - -use function assert; /** * External payment notification handler for online payment. @@ -55,24 +53,19 @@ class OnlinePaymentNotify extends AbstractOnlinePaymentAction * Note: This handler does not register the payment with the ILS since that happens in the response handler or * online payment monitor. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { - $controller = $params->getController(); - assert($controller instanceof AjaxController); - $request = $controller->getRequest(); - assert($request instanceof Request); - - $this->logger->debug('Online payment notify handler called. Request: ' . (string)$request); + $this->logger->debug('Online payment notify handler called. Request: ' . Message::toString($request)); - if (null === ($localIdentifier = $request->getQuery('local_payment_id'))) { + if (null === ($localIdentifier = $this->getQueryParam($request, 'local_payment_id'))) { $this->logError( 'Error processing payment: local_payment_id not provided. Query: ' - . $request->getQuery()->toString() - . ', post parameters: ' . $request->getPost()->toString() + . var_export($request->getQueryParams(), true) + . ', post parameters: ' . var_export($request->getParsedBody(), true) ); return $this->formatResponse('', self::STATUS_HTTP_BAD_REQUEST); } @@ -92,7 +85,8 @@ public function handleRequest(Params $params) } try { - $this->onlinePaymentManager->processPaymentHandlerResponse($payment, $request, true); + $this->onlinePaymentManager + ->processPaymentHandlerResponse($payment, Psr7ServerRequest::toLaminas($request), true); } catch (\Exception $e) { $this->logError( 'Error processing payment notification for ' . $payment->getSourceIls() . ", payment $localIdentifier" diff --git a/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentRegister.php b/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentRegister.php index d684a3257982..7a774ea67a9c 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentRegister.php +++ b/module/VuFind/src/VuFind/AjaxHandler/OnlinePaymentRegister.php @@ -31,7 +31,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * AJAX handler for registering an online payment with the ILS. @@ -47,13 +47,13 @@ class OnlinePaymentRegister extends AbstractOnlinePaymentAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { - $localIdentifier = $params->fromPost('localIdentifier') ?? $params->fromQuery('localIdentifier'); + $localIdentifier = $this->getPostOrQueryParam($request, 'localIdentifier'); if (!$localIdentifier) { return $this->formatResponse('', self::STATUS_HTTP_BAD_REQUEST); } diff --git a/module/VuFind/src/VuFind/AjaxHandler/Recommend.php b/module/VuFind/src/VuFind/AjaxHandler/Recommend.php index 21731dbb0cfb..9fa7a787735b 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/Recommend.php +++ b/module/VuFind/src/VuFind/AjaxHandler/Recommend.php @@ -29,13 +29,14 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Stdlib\Parameters; -use Laminas\View\Renderer\RendererInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\I18n\Translator\TranslatorAwareInterface; use VuFind\Recommend\PluginManager as RecommendManager; use VuFind\Search\Solr\Results; use VuFind\Session\Settings as SessionSettings; +use VuFind\View\Helper\Root\Recommend as RecommendHelper; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Load a recommendation module via AJAX. @@ -50,70 +51,48 @@ class Recommend extends AbstractBase implements TranslatorAwareInterface { use \VuFind\I18n\Translator\TranslatorAwareTrait; - /** - * Recommendation plugin manager. - * - * @var RecommendManager - */ - protected $pluginManager; - - /** - * Solr search results object. - * - * @var Results - */ - protected $results; - - /** - * View renderer. - * - * @var RendererInterface - */ - protected $renderer; - /** * Constructor. * - * @param SessionSettings $ss Session settings - * @param RecommendManager $pm Recommendation plugin manager - * @param Results $results Solr results object - * @param RendererInterface $renderer View renderer + * @param SessionSettings $sessionSettings Session settings + * @param RecommendManager $recommendPluginManager Recommendation plugin manager + * @param Results $results Solr results object + * @param TemplateRendererInterface $renderer Template renderer, + * @param RecommendHelper $recommendHelper Recommend view helper */ public function __construct( - SessionSettings $ss, - RecommendManager $pm, - Results $results, - RendererInterface $renderer + SessionSettings $sessionSettings, + protected RecommendManager $recommendPluginManager, + protected Results $results, + protected TemplateRendererInterface $renderer, + protected RecommendHelper $recommendHelper, ) { - $this->sessionSettings = $ss; - $this->pluginManager = $pm; - $this->results = $results; - $this->renderer = $renderer; + parent::__construct($sessionSettings); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug // Process recommendations -- for now, we assume Solr-based search objects, // since deferred recommendations work best for modules that don't care about // the details of the search objects anyway: - if (!($moduleName = $params->fromQuery('mod'))) { + if (!($moduleName = $this->getQueryParam($request, 'mod'))) { return $this->formatResponse( $this->translate('bulk_error_missing'), self::STATUS_HTTP_BAD_REQUEST ); } - $module = $this->pluginManager->get($moduleName); - $module->setConfig($params->fromQuery('params', '')); + $module = $this->recommendPluginManager->get($moduleName); + $module->setConfig($this->getQueryParam($request, 'params', '')); $paramsObj = $this->results->getParams(); - $request = new Parameters($params->fromQuery()); + $request = new Parameters($request->getQueryParams()); // Initialize search parameters from Ajax request parameters in case the // original request parameters were passed to the Ajax request. $paramsObj->initFromRequest($request); @@ -121,7 +100,6 @@ public function handleRequest(Params $params) $module->process($this->results); // Render recommendations: - $recommend = $this->renderer->plugin('recommend'); - return $this->formatResponse($recommend($module)); + return $this->formatResponse(($this->recommendHelper)($module)); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/RecommendFactory.php b/module/VuFind/src/VuFind/AjaxHandler/RecommendFactory.php index d05c66a2b570..bcf8120dbfec 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/RecommendFactory.php +++ b/module/VuFind/src/VuFind/AjaxHandler/RecommendFactory.php @@ -34,6 +34,8 @@ use Psr\Container\ContainerExceptionInterface as ContainerException; use Psr\Container\ContainerInterface; use VuFind\Search\Results\PluginManager as ResultsManager; +use VuFind\View\Helper\Root\Recommend; +use VuFind\View\Renderer\TemplateRendererInterface; /** * Factory for Recommend AJAX handler. @@ -74,7 +76,8 @@ public function __invoke( $container->get(\VuFind\Session\Settings::class), $container->get(\VuFind\Recommend\PluginManager::class), $container->get(ResultsManager::class)->get('Solr'), - $container->get('ViewRenderer') + $container->get(TemplateRendererInterface::class), + $container->get('ViewHelperManager')->get(Recommend::class), ); } } diff --git a/module/VuFind/src/VuFind/AjaxHandler/RelaisAvailability.php b/module/VuFind/src/VuFind/AjaxHandler/RelaisAvailability.php index 1ffcb4e48d0a..025a70c1a259 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/RelaisAvailability.php +++ b/module/VuFind/src/VuFind/AjaxHandler/RelaisAvailability.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * Relais: Check item availability using a generic patron ID. @@ -45,14 +45,14 @@ class RelaisAvailability extends AbstractRelaisAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $oclcNumber = $params->fromQuery('oclcNumber'); + $oclcNumber = $this->getQueryParam($request, 'oclcNumber'); // Authenticate $authorizationId = $this->relais->authenticatePatron(); diff --git a/module/VuFind/src/VuFind/AjaxHandler/RelaisInfo.php b/module/VuFind/src/VuFind/AjaxHandler/RelaisInfo.php index f941c0264373..1909a1ffad2d 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/RelaisInfo.php +++ b/module/VuFind/src/VuFind/AjaxHandler/RelaisInfo.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * Relais: Check if logged-in patron can order an item. @@ -45,14 +45,14 @@ class RelaisInfo extends AbstractRelaisAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $oclcNumber = $params->fromQuery('oclcNumber'); + $oclcNumber = $this->getQueryParam($request, 'oclcNumber'); $lin = $this->user?->getCatUsername(); // Authenticate diff --git a/module/VuFind/src/VuFind/AjaxHandler/RelaisOrder.php b/module/VuFind/src/VuFind/AjaxHandler/RelaisOrder.php index d6c496d67325..9e91358335ce 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/RelaisOrder.php +++ b/module/VuFind/src/VuFind/AjaxHandler/RelaisOrder.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; /** * Relais: Order an item. @@ -45,14 +45,14 @@ class RelaisOrder extends AbstractRelaisAction /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { $this->disableSessionWrites(); // avoid session write timing bug - $oclcNumber = $params->fromQuery('oclcNumber'); + $oclcNumber = $this->getQueryParam($request, 'oclcNumber'); $lin = $this->user?->getCatUsername(); diff --git a/module/VuFind/src/VuFind/AjaxHandler/SystemStatus.php b/module/VuFind/src/VuFind/AjaxHandler/SystemStatus.php index 770039400e40..680f9470b13a 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/SystemStatus.php +++ b/module/VuFind/src/VuFind/AjaxHandler/SystemStatus.php @@ -30,8 +30,8 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Session\SessionManager; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Config\Config; use VuFind\Db\Service\SessionServiceInterface; use VuFind\Search\Results\PluginManager as ResultsManager; @@ -64,18 +64,19 @@ public function __construct( protected Config $config, protected SessionServiceInterface $sessionService ) { + parent::__construct(null); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { // Check system status if ( @@ -92,7 +93,7 @@ public function handleRequest(Params $params) $this->log('info', 'SystemStatus log check', [], true); // Test search index - if ($params->fromPost('index') ?? $params->fromQuery('index', 1)) { + if ($this->getPostOrQueryParam($request, 'index', 1)) { try { $results = $this->resultsManager->get(DEFAULT_SEARCH_BACKEND); $paramsObj = $results->getParams(); @@ -107,7 +108,7 @@ public function handleRequest(Params $params) } // Test database connection - if ($params->fromPost('database') ?? $params->fromQuery('database', 1)) { + if ($this->getPostOrQueryParam($request, 'database', 1)) { try { $this->sessionService->getSessionById('healthcheck', false); } catch (\Exception $e) { diff --git a/module/VuFind/src/VuFind/AjaxHandler/TagRecord.php b/module/VuFind/src/VuFind/AjaxHandler/TagRecord.php index f99260670470..870be8894208 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/TagRecord.php +++ b/module/VuFind/src/VuFind/AjaxHandler/TagRecord.php @@ -29,7 +29,7 @@ namespace VuFind\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Db\Entity\UserEntityInterface; use VuFind\I18n\Translator\TranslatorAwareInterface; use VuFind\Record\Loader; @@ -62,16 +62,19 @@ public function __construct( protected TagsService $tagsService, protected ?UserEntityInterface $user ) { + parent::__construct(null); } /** * Handle a request. * - * @param Params $params Parameter helper from controller + * @param ServerRequestInterface $request Request * * @return array [response data, HTTP status code] + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function handleRequest(Params $params) + public function handleRequest(ServerRequestInterface $request): array { if (!$this->user) { return $this->formatResponse( @@ -80,13 +83,13 @@ public function handleRequest(Params $params) ); } - $id = $params->fromPost('id'); - $source = $params->fromPost('source', DEFAULT_SEARCH_BACKEND); - $tag = $params->fromPost('tag', ''); + $id = $this->getPostParam($request, 'id'); + $source = $this->getPostParam($request, 'source', DEFAULT_SEARCH_BACKEND); + $tag = $this->getPostParam($request, 'tag', ''); if (strlen($tag) > 0) { // don't add empty tags $driver = $this->loader->load($id, $source); - $serviceMethod = ('false' === $params->fromPost('remove', 'false')) + $serviceMethod = ('false' === $this->getPostParam($request, 'remove', 'false')) ? 'linkTagsToRecord' : 'unlinkTagsFromRecord'; $this->tagsService->$serviceMethod( diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php deleted file mode 100644 index af976cb26eed..000000000000 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ /dev/null @@ -1,113 +0,0 @@ -. - * - * @category VuFind - * @package Controller - * @author Chris Hallberg - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org/wiki/development:plugins:controllers Wiki - */ - -namespace VuFind\Controller; - -use Laminas\Mvc\Controller\AbstractActionController; -use VuFind\AjaxHandler\PluginManager; -use VuFind\I18n\Translator\TranslatorAwareInterface; - -/** - * This controller handles global AJAX functionality. - * - * @category VuFind - * @package Controller - * @author Chris Hallberg - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org/wiki/development:plugins:controllers Wiki - */ -class AjaxController extends AbstractActionController implements TranslatorAwareInterface -{ - use AjaxResponseTrait; - use \VuFind\I18n\Translator\TranslatorAwareTrait; - - /** - * Constructor. - * - * @param PluginManager $am AJAX Handler Plugin Manager - */ - public function __construct(PluginManager $am) - { - // Prevent errors, notices etc. from being displayed so that they don't mess - // with the output (only in production mode): - if ('production' === APPLICATION_ENV) { - ini_set('display_errors', '0'); - } - $this->ajaxManager = $am; - } - - /** - * Make an AJAX call with a JSON-formatted response. - * - * @return \Laminas\Http\Response - */ - public function jsonAction() - { - $method = $this->params()->fromQuery('method'); - if (!$method) { - return $this->getAjaxResponse('application/json', ['error' => 'Parameter "method" missing'], 400); - } - return $this->callAjaxMethod($method); - } - - /** - * Load a recommendation module via AJAX. - * - * @return \Laminas\Http\Response - */ - public function recommendAction() - { - return $this->callAjaxMethod('recommend', 'text/html'); - } - - /** - * Check status and return a status message for e.g. a load balancer. - * - * A simple OK as text/plain is returned if everything works properly. - * - * @return \Laminas\Http\Response - */ - public function systemStatusAction() - { - return $this->callAjaxMethod('systemStatus', 'text/plain'); - } - - /** - * Handle online payment notification callback. - * - * An empty response with HTTP code 200 is returned - * - * @return \Laminas\Http\Response - */ - public function onlinePaymentNotifyAction() - { - // Use text/html to avoid any output - return $this->callAjaxMethod('onlinePaymentNotify', 'text/html'); - } -} diff --git a/module/VuFind/src/VuFind/View/Renderer/LaminasTemplateRenderer.php b/module/VuFind/src/VuFind/View/Renderer/LaminasTemplateRenderer.php index 39150ba744bf..99b8ed23b7cc 100644 --- a/module/VuFind/src/VuFind/View/Renderer/LaminasTemplateRenderer.php +++ b/module/VuFind/src/VuFind/View/Renderer/LaminasTemplateRenderer.php @@ -34,7 +34,7 @@ use Laminas\Uri\Http; use Laminas\View\Model\ModelInterface; use Laminas\View\Model\ViewModel; -use Laminas\View\Renderer\RendererInterface; +use Laminas\View\Renderer\PhpRenderer; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use VuFind\Http\ServerUrlHelper; @@ -58,7 +58,7 @@ class LaminasTemplateRenderer implements TemplateRendererInterface * Constructor. * * @param ServerUrlHelper $serverUrlHelper Server URL helper - * @param RendererInterface $viewRenderer View renderer + * @param PhpRenderer $viewRenderer View renderer * @param ViewManager $viewManager View manager * @param InjectTemplateListener $injectTemplateListener Template injection listener (for prefixes) * @param bool $displayExceptions Display exceptions? @@ -69,7 +69,7 @@ class LaminasTemplateRenderer implements TemplateRendererInterface public function __construct( protected ServerUrlHelper $serverUrlHelper, #[Autowire(service: 'ViewRenderer')] - protected RendererInterface $viewRenderer, + protected PhpRenderer $viewRenderer, #[Autowire(service: 'ViewManager')] protected ViewManager $viewManager, protected InjectTemplateListener $injectTemplateListener, @@ -85,20 +85,23 @@ public function __construct( /** * Render a template and return the result in the response object. * - * @param ServerRequestInterface $request Request - * @param ResponseInterface $response Response object - * @param array $params Template parameters - * @param ?string $template Template name, or null to use default for the action + * @param ServerRequestInterface $request Request + * @param ResponseInterface $response Response object + * @param ?string $template Template name, or null to use default for the action + * @param array $params Template parameters + * @param array[] $childTemplates Any child templates; an array of associative array with keys + * 'template' and 'params' * * @return ResponseInterface */ public function renderTemplate( ServerRequestInterface $request, ResponseInterface $response, - array $params = [], ?string $template = null, + array $params = [], + array $childTemplates = [], ): ResponseInterface { - $response->getBody()->write($this->renderTemplateAsString($request, $params, $template)); + $response->getBody()->write($this->renderTemplateAsString($request, $template, $params, useLayout: true)); return $response; } @@ -120,8 +123,8 @@ public function renderErrorPage( return $this->renderTemplate( $request, $response->withStatus(500), - $params, - $this->errorTemplate + $this->errorTemplate, + $params ); } @@ -142,36 +145,61 @@ public function renderNotFoundPage( return $this->renderTemplate( $request, $response->withStatus(404), - $params + ['message' => 'Page not found.'], - $this->notFoundTemplate + $this->notFoundTemplate, + $params + ['message' => 'Page not found.'] ); } /** * Render a template and return the result as a string. * - * @param ServerRequestInterface $request Request - * @param array $params Template parameters - * @param ?string $template Template name, or null to use default for the action + * @param ServerRequestInterface $request Request + * @param ?string $template Template name, or null to use default for the action + * @param array $params Template parameters + * @param array[] $childTemplates Any child templates; an array of associative array with keys + * 'template' and 'params' + * @param bool $useLayout Render full page with the layout? * * @return string */ public function renderTemplateAsString( ServerRequestInterface $request, - array $params = [], ?string $template = null, + array $params = [], + array $childTemplates = [], + bool $useLayout = false, ): string { $view = $this->viewManager->getView(); $viewModel = $this->createViewModel($request, $params, $template); - $layout = $this->getLayout($request); - // Clear any previous children (e.g. when rendering an error): - if ($layout instanceof ViewModel) { - $layout->clearChildren(); + foreach ($childTemplates as $current) { + $viewModel->addChild($this->createViewModel($request, $current['params'] ?? [], $current['template'])); + } + if ($useLayout) { + $layout = $this->getLayout($request); + // Clear any previous children (e.g. when rendering an error): + if ($layout instanceof ViewModel) { + $layout->clearChildren(); + } + $layout->addChild($viewModel); + // Force renderer to return the result: + $layout->setOption('has_parent', true); + return $view->render($layout); } - $layout->addChild($viewModel); // Force renderer to return the result: - $layout->setOption('has_parent', true); - return $view->render($layout); + $viewModel->setOption('has_parent', true); + return $view->render($viewModel); + } + + /** + * Find the filename for a template. + * + * @param string $template Template + * + * @return ?string Filename, or null if not found + */ + public function resolveTemplateFilename(string $template): ?string + { + return $this->viewRenderer->resolver($template); } /** diff --git a/module/VuFind/src/VuFind/View/Renderer/TemplateRendererInterface.php b/module/VuFind/src/VuFind/View/Renderer/TemplateRendererInterface.php index 707eaf40aa70..3050235ac82f 100644 --- a/module/VuFind/src/VuFind/View/Renderer/TemplateRendererInterface.php +++ b/module/VuFind/src/VuFind/View/Renderer/TemplateRendererInterface.php @@ -46,18 +46,21 @@ interface TemplateRendererInterface /** * Render a template and return the result in the response object. * - * @param ServerRequestInterface $request Request - * @param ResponseInterface $response Response object - * @param array $params Template parameters - * @param ?string $template Template name, or null to use default for the action + * @param ServerRequestInterface $request Request + * @param ResponseInterface $response Response object + * @param ?string $template Template name, or null to use default for the action + * @param array $params Template parameters + * @param array[] $childTemplates Any child templates; an array of associative array with keys + * 'template' and 'params' * * @return ResponseInterface */ public function renderTemplate( ServerRequestInterface $request, ResponseInterface $response, - array $params = [], ?string $template = null, + array $params = [], + array $childTemplates = [], ): ResponseInterface; /** @@ -93,15 +96,29 @@ public function renderNotFoundPage( /** * Render a template and return the result as a string. * - * @param ServerRequestInterface $request Request - * @param array $params Template parameters - * @param ?string $template Template name, or null to use default for the action + * @param ServerRequestInterface $request Request + * @param ?string $template Template name, or null to use default for the action + * @param array $params Template parameters + * @param array[] $childTemplates Any child templates; an array of associative array with keys + * 'template' and 'params' + * @param bool $useLayout Render full page with the layout? * * @return string */ public function renderTemplateAsString( ServerRequestInterface $request, - array $params = [], ?string $template = null, + array $params = [], + array $childTemplates = [], + bool $useLayout = false, ): string; + + /** + * Find the filename for a template. + * + * @param string $template Template + * + * @return ?string Filename, or null if not found + */ + public function resolveTemplateFilename(string $template): ?string; } diff --git a/module/VuFind/src/VuFindTest/Unit/AjaxHandlerTestCase.php b/module/VuFind/src/VuFindTest/Unit/AjaxHandlerTestCase.php index 1eca0156edfb..5d46f9a2b54f 100644 --- a/module/VuFind/src/VuFindTest/Unit/AjaxHandlerTestCase.php +++ b/module/VuFind/src/VuFindTest/Unit/AjaxHandlerTestCase.php @@ -29,10 +29,11 @@ namespace VuFindTest\Unit; +use GuzzleHttp\Psr7\ServerRequest; use Laminas\Http\Request; -use Laminas\Mvc\Controller\Plugin\Params; use Laminas\Stdlib\Parameters; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Http\Message\ServerRequestInterface; use VuFind\Auth\Manager as AuthManager; use VuFind\Db\Entity\UserEntityInterface; @@ -93,27 +94,22 @@ protected function getMockAuthManager(?UserEntityInterface $user = null): MockOb } /** - * Build a Params helper for testing. + * Build a request for testing. * - * @param array $get GET parameters - * @param array $post POST parameters - * @param string $content Body content + * @param array $get GET parameters + * @param array $post POST parameters + * @param ?string $content Body content * - * @return Params + * @return ServerRequestInterface */ - protected function getParamsHelper(array $get = [], array $post = [], string $content = ''): Params + protected function getRequest(array $get = [], array $post = [], ?string $content = null): ServerRequestInterface { - $params = new Params(); - $request = new Request(); - $request->setQuery(new Parameters($get)); - $request->setPost(new Parameters($post)); - $request->setContent($content); - $controller = $this->container->createMock( - \Laminas\Mvc\Controller\AbstractActionController::class, - ['getRequest'] - ); - $controller->method('getRequest')->willReturn($request); - $params->setController($controller); - return $params; + $request = (new ServerRequest($post ? 'POST' : 'GET', 'http://localhost')) + ->withQueryParams($get) + ->withParsedBody($post); + if (null !== $content) { + $request->getBody()->write($content); + } + return $request; } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CheckRequestIsValidTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CheckRequestIsValidTest.php index 629ed1b23556..d1e22adfca23 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CheckRequestIsValidTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CheckRequestIsValidTest.php @@ -29,6 +29,7 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\AbstractIlsAndUserActionFactory; use VuFind\AjaxHandler\CheckRequestIsValid; use VuFind\Auth\ILSAuthenticator; @@ -72,9 +73,9 @@ protected function getHandler(?UserEntityInterface $user = null): CheckRequestIs public function testLoggedOutUser(): void { $handler = $this->getHandler(); - $this->assertEquals( + $this->assertSame( ['You must be logged in first', 401], - $handler->handleRequest($this->getParamsHelper(['id' => 1, 'data' => 1])) + $handler->handleRequest($this->getRequest(['id' => 1, 'data' => 1])) ); } @@ -86,9 +87,9 @@ public function testLoggedOutUser(): void public function testEmptyQuery(): void { $handler = $this->getHandler($this->getMockUser()); - $this->assertEquals( + $this->assertSame( ['bulk_error_missing', 400], - $handler->handleRequest($this->getParamsHelper()) + $handler->handleRequest($this->getRequest()) ); } @@ -113,7 +114,7 @@ protected function runSuccessfulTest($ilsMethod, $requestType = ''): array $this->container->set(ILSAuthenticator::class, $ilsAuth); $handler = $this->getHandler($this->getMockUser()); $params = ['id' => 1, 'data' => 2, 'requestType' => $requestType]; - return $handler->handleRequest($this->getParamsHelper($params)); + return $handler->handleRequest($this->getRequest($params)); } /** diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CommentRecordTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CommentRecordTest.php index a103fa99e8dd..fe82137fd4c4 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CommentRecordTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CommentRecordTest.php @@ -29,6 +29,7 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\CommentRecord; use VuFind\AjaxHandler\CommentRecordFactory; use VuFind\Config\AccountCapabilities; @@ -94,9 +95,9 @@ function () use ($authManager) { public function testDisabledResponse(): void { $handler = $this->getHandler(false); - $this->assertEquals( + $this->assertSame( ['Comments disabled', 400], - $handler->handleRequest($this->getParamsHelper()) + $handler->handleRequest($this->getRequest()) ); } @@ -108,9 +109,9 @@ public function testDisabledResponse(): void public function testLoggedOutUser(): void { $handler = $this->getHandler(true); - $this->assertEquals( + $this->assertSame( ['You must be logged in first', 401], - $handler->handleRequest($this->getParamsHelper()) + $handler->handleRequest($this->getRequest()) ); } @@ -122,9 +123,9 @@ public function testLoggedOutUser(): void public function testEmptyQuery(): void { $handler = $this->getHandler(true, $this->getMockUser()); - $this->assertEquals( + $this->assertSame( ['bulk_error_missing', 400], - $handler->handleRequest($this->getParamsHelper()) + $handler->handleRequest($this->getRequest()) ); } @@ -173,7 +174,7 @@ public function testSuccessfulTransaction(): void [ ['commentId' => true], ], - $handler->handleRequest($this->getParamsHelper([], $post)) + $handler->handleRequest($this->getRequest([], $post)) ); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/GetResolverLinksTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/GetResolverLinksTest.php index 940c882d5170..40af40d8843c 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/GetResolverLinksTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/GetResolverLinksTest.php @@ -29,11 +29,13 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\GetResolverLinks; use VuFind\AjaxHandler\GetResolverLinksFactory; use VuFind\Resolver\Driver\DriverInterface; use VuFind\Resolver\Driver\PluginManager; use VuFind\Session\Settings; +use VuFind\View\Renderer\TemplateRendererInterface; /** * GetResolverLinks test class. @@ -100,9 +102,16 @@ public function testResponse(): void $rm->expects($this->once())->method('get')->with('generic')->willReturn($mockPlugin); $this->container->set(PluginManager::class, $rm); + $request = $this->getRequest( + [ + 'openurl' => 'foo', + 'searchClassId' => 'scl', + ] + ); + // Set up view helper and renderer: - $view = $this->container->createMock(\Laminas\View\Renderer\PhpRenderer::class); - $expectedViewParams = [ + $renderer = $this->container->createMock(TemplateRendererInterface::class); + $expectedTemplateParams = [ 'openUrlBase' => false, 'openUrl' => 'foo', 'print' => [ @@ -131,12 +140,13 @@ public function testResponse(): void 'searchClassId' => 'scl', 'moreOptionsLink' => '', ]; - $view->expects($this->once())->method('render') + $renderer->expects($this->once())->method('renderTemplateAsString') ->with( + $request, 'ajax/resolverLinks.phtml', - $expectedViewParams + $expectedTemplateParams )->willReturn('html'); - $this->container->set('ViewRenderer', $view); + $this->container->set(TemplateRendererInterface::class, $renderer); // Set up configuration: $this->setupConfig(); @@ -144,19 +154,13 @@ public function testResponse(): void // Build and test the ajax handler: $factory = new GetResolverLinksFactory(); $handler = $factory($this->container, GetResolverLinks::class); - $params = $this->getParamsHelper( - [ - 'openurl' => 'foo', - 'searchClassId' => 'scl', - ] - ); $this->assertEquals( [ [ 'html' => 'html', ], ], - $handler->handleRequest($params) + $handler->handleRequest($request) ); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/IdentifierLinksLookupTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/IdentifierLinksLookupTest.php index 35aac11e03fe..6646d59cd285 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/IdentifierLinksLookupTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/IdentifierLinksLookupTest.php @@ -29,13 +29,16 @@ namespace VuFindTest\AjaxHandler; -use Laminas\View\Renderer\PhpRenderer; +use GuzzleHttp\Psr7\Response; +use Psr\Http\Message\ServerRequestInterface; use VuFind\AjaxHandler\IdentifierLinksLookup; use VuFind\AjaxHandler\IdentifierLinksLookupFactory; +use VuFind\Http\RouteHelper; +use VuFind\Http\ServerUrlHelper; use VuFind\IdentifierLinker\IdentifierLinkerInterface; use VuFind\IdentifierLinker\PluginManager; - -use function func_get_args; +use VuFind\View\Helper\Root\Icon; +use VuFind\View\Renderer\TemplateRendererInterface; /** * IdentifierLinksLookup test class. @@ -126,40 +129,53 @@ protected function setupPluginManager($plugins) */ protected function getHandlerResults($requested = [['doi' => 'bar']]) { - $plugins = [ - 'serverurl' => function ($path) { + $serverUrlHelper = $this->createMock(ServerUrlHelper::class); + $serverUrlHelper->method('getUrlForPath') + ->willReturnCallback(function (string $path): string { return "http://localhost/$path"; - }, - 'url' => function ($route, $options, $params) { - return "$route?" . http_build_query($params['query'] ?? []); - }, - 'icon' => function ($icon) { + }); + $this->container->set(ServerUrlHelper::class, $serverUrlHelper); + + $routeHelper = $this->createMock(RouteHelper::class); + $routeHelper->method('getUrlFromRoute') + ->willReturnCallback(function (string $route, array $options, array $query): string { + return "$route?" . http_build_query($query); + }); + $this->container->set(RouteHelper::class, $routeHelper); + + $iconHelper = $this->createMock(Icon::class); + $iconHelper->method('__invoke') + ->willReturnCallback(function (string $icon): string { return "($icon)"; - }, - ]; + }); - $mockRenderer = $this->container->createMock(PhpRenderer::class); - $mockRenderer->method('plugin') - ->willReturnCallback( - function ($plugin) use ($plugins) { - return $plugins[$plugin] ?? null; - } - ); + $viewHelperManager = $this->container->get('ViewHelperManager'); + $viewHelperManager->method('get') + ->with(Icon::class) + ->willReturn($iconHelper); + + $mockRenderer = $this->container->createMock(TemplateRendererInterface::class); // JSON encode parameters to the render method so that it returns a string // that we can make assertions about in our tests. - $mockRenderer->method('render') + $mockRenderer->method('renderTemplateAsString') ->willReturnCallback( - function () { - return json_encode(func_get_args()); + function ( + ServerRequestInterface $request, + ?string $template = null, + array $params = [], + array $childTemplates = [], + bool $useLayout = false, + ) { + return json_encode([$template, $params]); } ); - $this->container->set('ViewRenderer', $mockRenderer); + $this->container->set(TemplateRendererInterface::class, $mockRenderer); $factory = new IdentifierLinksLookupFactory(); $handler = $factory($this->container, IdentifierLinksLookup::class); - $params = $this->getParamsHelper(content: json_encode($requested)); - return $handler->handleRequest($params); + $request = $this->getRequest(content: json_encode($requested)); + return $handler->handleRequest($request); } /** diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/KeepAliveTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/KeepAliveTest.php index c62dd179e72f..7a353dd0e416 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/KeepAliveTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/KeepAliveTest.php @@ -29,6 +29,7 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use Laminas\Session\SessionManager; use VuFind\AjaxHandler\KeepAlive; use VuFind\AjaxHandler\KeepAliveFactory; @@ -56,7 +57,6 @@ public function testResponse() $this->container->set(SessionManager::class, $sm); $factory = new KeepAliveFactory(); $handler = $factory($this->container, KeepAlive::class); - $params = new \Laminas\Mvc\Controller\Plugin\Params(); - $this->assertEquals([true], $handler->handleRequest($params)); + $this->assertEquals([true], $handler->handleRequest($this->getRequest())); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RecommendTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RecommendTest.php index 5991780db6e9..24eb5e6c64db 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RecommendTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RecommendTest.php @@ -29,6 +29,7 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\Recommend; use VuFind\AjaxHandler\RecommendFactory; use VuFind\Recommend\PluginManager; @@ -36,7 +37,6 @@ use VuFind\Search\Results\PluginManager as ResultsManager; use VuFind\Search\Solr\Results; use VuFind\Session\Settings; -use VuFind\View\Helper\Root\Recommend as RecommendHelper; use function count; @@ -124,17 +124,13 @@ public function testResponse() ->willReturn($results); $this->container->set(ResultsManager::class, $resultsManager); - // Set up view helper and renderer: - $view = new \Laminas\View\Renderer\PhpRenderer(); + // Set up view helper plugin manager: $plugins = new \VuFindTest\Container\MockViewHelperContainer($this); - $plugins->set('recommend', $plugins->get(RecommendHelper::class)); - $view->setHelperPluginManager($plugins); - $this->container->set('ViewRenderer', $view); + $this->container->set('Laminas\View\HelperPluginManager', $plugins); // Build and test the ajax handler: $factory = new RecommendFactory(); $handler = $factory($this->container, Recommend::class); - $params = $this->getParamsHelper(['mod' => 'foo']); - $this->assertEquals([null], $handler->handleRequest($params)); + $this->assertEquals([null], $handler->handleRequest($this->getRequest(['mod' => 'foo']))); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisAvailabilityTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisAvailabilityTest.php index f082dfe72686..854acd568698 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisAvailabilityTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisAvailabilityTest.php @@ -29,7 +29,9 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\RelaisAvailability; +use VuFindTest\Unit\AjaxHandlerTestCase; /** * RelaisAvailability test class. @@ -40,7 +42,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Page */ -class RelaisAvailabilityTest extends \PHPUnit\Framework\TestCase +class RelaisAvailabilityTest extends AjaxHandlerTestCase { /** * Test authorization failure. @@ -54,8 +56,7 @@ public function testAuthorizationFailure(): void $this->createMock(\VuFind\Connection\Relais::class), null ); - $params = $this->createMock(\Laminas\Mvc\Controller\Plugin\Params::class); - $this->assertEquals(['Failed', 403], $handler->handleRequest($params)); + $this->assertSame(['Failed', 403], $handler->handleRequest($this->getRequest())); } /** @@ -82,9 +83,7 @@ public static function searchResponseProvider(): \Iterator #[\PHPUnit\Framework\Attributes\DataProvider('searchResponseProvider')] public function testSearchResponse(string $response, array $expected): void { - $params = $this->createMock(\Laminas\Mvc\Controller\Plugin\Params::class); - $params->expects($this->once())->method('fromQuery')->with('oclcNumber') - ->willReturn('oclcnum'); + $request = $this->getRequest(['oclcNumber' => 'oclcnum']); $relais = $this->createMock(\VuFind\Connection\Relais::class); $relais->expects($this->once())->method('authenticatePatron') ->willReturn('authorization-id'); @@ -96,6 +95,6 @@ public function testSearchResponse(string $response, array $expected): void $relais, null ); - $this->assertEquals($expected, $handler->handleRequest($params)); + $this->assertEquals($expected, $handler->handleRequest($request)); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisInfoTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisInfoTest.php index 91e9da965792..508683d0d5d4 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisInfoTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisInfoTest.php @@ -29,7 +29,9 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\RelaisInfo; +use VuFindTest\Unit\AjaxHandlerTestCase; /** * RelaisInfo test class. @@ -40,7 +42,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Page */ -class RelaisInfoTest extends \PHPUnit\Framework\TestCase +class RelaisInfoTest extends AjaxHandlerTestCase { /** * Test authorization failure. @@ -54,8 +56,7 @@ public function testAuthorizationFailure(): void $this->createMock(\VuFind\Connection\Relais::class), null ); - $params = $this->createMock(\Laminas\Mvc\Controller\Plugin\Params::class); - $this->assertEquals(['Failed', 403], $handler->handleRequest($params)); + $this->assertSame(['Failed', 403], $handler->handleRequest($this->getRequest())); } /** @@ -89,9 +90,7 @@ public function testAuthenticatedBehavior(?object $response, array $expected): v { $user = $this->createMock(\VuFind\Db\Entity\UserEntityInterface::class); $user->expects($this->once())->method('getCatUsername')->willReturn('user'); - $params = $this->createMock(\Laminas\Mvc\Controller\Plugin\Params::class); - $params->expects($this->once())->method('fromQuery')->with('oclcNumber') - ->willReturn('oclcnum'); + $request = $this->getRequest(['oclcNumber' => 'oclcnum']); $relais = $this->createMock(\VuFind\Connection\Relais::class); $relais->expects($this->once())->method('authenticatePatron') ->with('user', true) @@ -102,6 +101,6 @@ public function testAuthenticatedBehavior(?object $response, array $expected): v $relais, $user ); - $this->assertEquals($expected, $handler->handleRequest($params)); + $this->assertEquals($expected, $handler->handleRequest($request)); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisOrderTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisOrderTest.php index e7f2f1089edc..f097b6a1b12f 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisOrderTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RelaisOrderTest.php @@ -29,7 +29,11 @@ namespace VuFindTest\AjaxHandler; +use GuzzleHttp\Psr7\Response; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use VuFind\AjaxHandler\RelaisOrder; +use VuFindTest\Unit\AjaxHandlerTestCase; /** * RelaisOrder test class. @@ -40,7 +44,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Page */ -class RelaisOrderTest extends \PHPUnit\Framework\TestCase +class RelaisOrderTest extends AjaxHandlerTestCase { /** * Test authorization failure. @@ -54,8 +58,9 @@ public function testAuthorizationFailure(): void $this->createMock(\VuFind\Connection\Relais::class), null ); - $params = $this->createMock(\Laminas\Mvc\Controller\Plugin\Params::class); - $this->assertEquals(['Failed', 403], $handler->handleRequest($params)); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); + $this->assertSame(['Failed', 403], $handler->handleRequest($request)); } /** @@ -82,9 +87,7 @@ public function testAuthenticatedBehavior(string $response, array $expected): vo { $user = $this->createMock(\VuFind\Db\Entity\UserEntityInterface::class); $user->expects($this->once())->method('getCatUsername')->willReturn('user'); - $params = $this->createMock(\Laminas\Mvc\Controller\Plugin\Params::class); - $params->expects($this->once())->method('fromQuery')->with('oclcNumber') - ->willReturn('oclcnum'); + $request = $this->getRequest(['oclcNumber' => 'oclcnum']); $relais = $this->createMock(\VuFind\Connection\Relais::class); $relais->expects($this->once())->method('authenticatePatron') ->with('user') @@ -97,6 +100,6 @@ public function testAuthenticatedBehavior(string $response, array $expected): vo $relais, $user ); - $this->assertEquals($expected, $handler->handleRequest($params)); + $this->assertEquals($expected, $handler->handleRequest($request)); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/SystemStatusTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/SystemStatusTest.php index fc40ff5e1c15..31e706d97f50 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/SystemStatusTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/SystemStatusTest.php @@ -29,8 +29,9 @@ namespace VuFindTest\AjaxHandler; -use Laminas\Mvc\Controller\Plugin\Params; +use GuzzleHttp\Psr7\Response; use VuFind\AjaxHandler\SystemStatus; +use VuFindTest\Unit\AjaxHandlerTestCase; /** * SystemStatus test class. @@ -41,7 +42,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Page */ -class SystemStatusTest extends \PHPUnit\Framework\TestCase +class SystemStatusTest extends AjaxHandlerTestCase { /** * Test the AJAX handler's "health check file" response. @@ -55,8 +56,8 @@ public function testHealthCheckFile(): void $config = new \VuFind\Config\Config(['System' => ['healthCheckFile' => __FILE__]]); $sessionService = $this->createMock(\VuFind\Db\Service\SessionServiceInterface::class); $handler = new SystemStatus($sessionManager, $resultsManager, $config, $sessionService); - $response = $handler->handleRequest($this->getMockRequestParams()); - $this->assertEquals(['Health check file exists', 503], $response); + $response = $handler->handleRequest($this->getRequest()); + $this->assertSame(['Health check file exists', 503], $response); } /** @@ -77,11 +78,11 @@ public function testSolrFailure(): void $config = new \VuFind\Config\Config([]); $sessionService = $this->createMock(\VuFind\Db\Service\SessionServiceInterface::class); $handler = new SystemStatus($sessionManager, $resultsManager, $config, $sessionService); - $response = $handler->handleRequest($this->getMockRequestParams()); - $this->assertEquals(['Search index error: kaboom', 500], $response); + $response = $handler->handleRequest($this->getRequest()); + $this->assertSame(['Search index error: kaboom', 500], $response); // Disable index check: - $response = $handler->handleRequest($this->getMockRequestParams(['index' => '0'])); - $this->assertEquals([''], $response); + $response = $handler->handleRequest($this->getRequest(['index' => '0'])); + $this->assertSame([''], $response); } /** @@ -103,11 +104,11 @@ public function testDatabaseFailure(): void $e = new \Exception('kaboom'); $sessionService->expects($this->once())->method('getSessionById')->willThrowException($e); $handler = new SystemStatus($sessionManager, $resultsManager, $config, $sessionService); - $response = $handler->handleRequest($this->getMockRequestParams()); - $this->assertEquals(['Database error: kaboom', 500], $response); + $response = $handler->handleRequest($this->getRequest()); + $this->assertSame(['Database error: kaboom', 500], $response); // Disable database check: - $response = $handler->handleRequest($this->getMockRequestParams(['database' => '0'])); - $this->assertEquals([''], $response); + $response = $handler->handleRequest($this->getRequest(['database' => '0'])); + $this->assertSame([''], $response); } /** @@ -129,26 +130,7 @@ public function testSuccessfulResponse(): void $sessionService = $this->createMock(\VuFind\Db\Service\SessionServiceInterface::class); $sessionService->expects($this->once())->method('getSessionById'); $handler = new SystemStatus($sessionManager, $resultsManager, $config, $sessionService); - $response = $handler->handleRequest($this->getMockRequestParams()); - $this->assertEquals([''], $response); - } - - /** - * Get mock Params class for request params. - * - * @param array $requestParams Parameters to return - * - * @return MockObject&Params - */ - protected function getMockRequestParams(array $requestParams = []): Params - { - $params = $this->createMock(Params::class); - $params->method('fromQuery') - ->willReturnCallback( - function ($param, $default = null) use ($requestParams) { - return $requestParams[$param] ?? $default; - } - ); - return $params; + $response = $handler->handleRequest($this->getRequest()); + $this->assertSame([''], $response); } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Renderer/LaminasTemplateRendererTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Renderer/LaminasTemplateRendererTest.php index cda5675b65e4..d7edaafb0be5 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Renderer/LaminasTemplateRendererTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Renderer/LaminasTemplateRendererTest.php @@ -35,7 +35,7 @@ use Laminas\Diactoros\ServerRequest; use Laminas\Mvc\View\Http\ViewManager; use Laminas\View\Model\ViewModel; -use Laminas\View\Renderer\RendererInterface; +use Laminas\View\Renderer\PhpRenderer; use Laminas\View\View; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -227,7 +227,7 @@ protected function getRenderer(ViewModel $layout, ?string $content): LaminasTemp LaminasTemplateRenderer::class, [ 'config' => [], - 'ViewRenderer' => $this->createMock(RendererInterface::class), + 'ViewRenderer' => $this->createMock(PhpRenderer::class), 'ViewManager' => $viewManager, InjectTemplateListener::class => $injectTemplateListener, ] diff --git a/module/VuFindConsole/src/VuFindConsole/Command/Generate/ExtendServiceCommand.php b/module/VuFindConsole/src/VuFindConsole/Command/Generate/ExtendServiceCommand.php index 908cd157964d..2e80b08f9dbd 100644 --- a/module/VuFindConsole/src/VuFindConsole/Command/Generate/ExtendServiceCommand.php +++ b/module/VuFindConsole/src/VuFindConsole/Command/Generate/ExtendServiceCommand.php @@ -62,7 +62,7 @@ protected function configure() 'config_path', InputArgument::REQUIRED, "the path to the service in the framework config\ne.g." - . ' controllers/factories/VuFind\\\\Controller\\\\AjaxController' + . ' service_manager/factories/VuFind\\\\Cover\\\\Loader' )->addArgument( 'target_module', InputArgument::REQUIRED, diff --git a/themes/bootstrap5/templates/layout/bare.phtml b/themes/bootstrap5/templates/layout/bare.phtml new file mode 100644 index 000000000000..bea574beefbb --- /dev/null +++ b/themes/bootstrap5/templates/layout/bare.phtml @@ -0,0 +1,3 @@ +layout()->content;