From 1574594c08b8264e8fe45b2eea71b8772c5f2d73 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 25 Sep 2019 16:06:59 -0400
Subject: [PATCH] Make cover router factory more error-tolerant. - Allows the
 cover router to operate in more contexts (CLI vs. web)

---
 module/VuFind/src/VuFind/Cover/RouterFactory.php | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/module/VuFind/src/VuFind/Cover/RouterFactory.php b/module/VuFind/src/VuFind/Cover/RouterFactory.php
index 53d9d8351cc..431a226cc6e 100644
--- a/module/VuFind/src/VuFind/Cover/RouterFactory.php
+++ b/module/VuFind/src/VuFind/Cover/RouterFactory.php
@@ -61,8 +61,15 @@ class RouterFactory implements FactoryInterface
         if (!empty($options)) {
             throw new \Exception('Unexpected options sent to factory.');
         }
-        $base = $container->get('ControllerPluginManager')->get('url')
-            ->fromRoute('cover-show');
+        // Try to get the base URL from the controller plugin; fail over to
+        // the view helper if that doesn't work.
+        try {
+            $base = $container->get('ControllerPluginManager')->get('url')
+                ->fromRoute('cover-show');
+        } catch (\Exception $e) {
+            $base = $container->get('ViewRenderer')->plugin('url')
+                ->__invoke('cover-show');
+        }
         return new $requestedName($base);
     }
 }
-- 
GitLab