diff --git a/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php b/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php index 484ba5acccf01e51be17b8c5f9439dfa2698b350..71601c33c52b1e26b022fd0efd3ec5e34c661988 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php +++ b/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php @@ -77,7 +77,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements /** * Factory function for constructing the SessionContainer. * - * @var Callable + * @var callable */ protected $sessionFactory; @@ -220,10 +220,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * @param \VuFind\Date\Converter $dateConverter Date converter object * @param callable $sessionFactory Factory function returning * SessionContainer object - * @param SafeMoneyFormat $safeMoneyFormat Money formatting view helper + * @param ?SafeMoneyFormat $safeMoneyFormat Money formatting view helper */ public function __construct(\VuFind\Date\Converter $dateConverter, - $sessionFactory, SafeMoneyFormat $safeMoneyFormat + $sessionFactory, ?SafeMoneyFormat $safeMoneyFormat ) { $this->dateConverter = $dateConverter; $this->sessionFactory = $sessionFactory; @@ -2422,11 +2422,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements case 'Patron::Debt': case 'Patron::DebtGuarantees': $count = isset($details['current_outstanding']) - ? $this->safeMoneyFormat->__invoke($details['current_outstanding']) - : '-'; + ? $this->formatMoney($details['current_outstanding']) : '-'; $limit = isset($details['max_outstanding']) - ? $this->safeMoneyFormat->__invoke($details['max_outstanding']) - : '-'; + ? $this->formatMoney($details['max_outstanding']) : '-'; $params = [ '%%blockCount%%' => $count, '%%blockLimit%%' => $limit, @@ -2435,4 +2433,19 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } return $this->translate($this->patronStatusMappings[$reason] ?? '', $params); } + + /** + * Helper function for formatting currency + * + * @param $amount Number to format + * + * @return string + */ + protected function formatMoney($amount) + { + if (null === $this->safeMoneyFormat) { + throw new \Exception('SafeMoneyFormat helper not available'); + } + return ($this->safeMoneyFormat)($amount); + } } diff --git a/module/VuFind/src/VuFind/ILS/Driver/KohaRestFactory.php b/module/VuFind/src/VuFind/ILS/Driver/KohaRestFactory.php index 5875cad6551bbe1df24453510b0558208e12a1d9..e1ed6bc4f442da33a481c0e4565dabb1c3a97f8e 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/KohaRestFactory.php +++ b/module/VuFind/src/VuFind/ILS/Driver/KohaRestFactory.php @@ -67,9 +67,14 @@ class KohaRestFactory extends \VuFind\ILS\Driver\DriverWithDateConverterFactory $manager = $container->get(\Laminas\Session\SessionManager::class); return new \Laminas\Session\Container("KohaRest_$namespace", $manager); }; - $helper = $container->get('ViewHelperManager')->get('safeMoneyFormat'); + // Create safeMoneyFormat helper conditionally to avoid hard dependency on + // themes (which otherwise could cause problems for command line tools that + // use the ILS driver when the theme system is not active). + $helperManager = $container->get('ViewHelperManager'); + $safeMoneyFormat = $helperManager->has('safeMoneyFormat') + ? $helperManager->get('safeMoneyFormat') : null; return parent::__invoke( - $container, $requestedName, [$sessionFactory, $helper] + $container, $requestedName, [$sessionFactory, $safeMoneyFormat] ); } }