From ab3e5f39c931b711382054d46907fd124640ea87 Mon Sep 17 00:00:00 2001 From: mathieugrimault <30295397+mathieugrimault@users.noreply.github.com> Date: Wed, 19 Dec 2018 17:44:11 +0100 Subject: [PATCH] Allow local override of xsl files (#1288) - Also begin checking a root /xsl directory in preparation for possible future reorganization away from modules. --- module/VuFind/src/VuFind/XSLT/Processor.php | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/XSLT/Processor.php b/module/VuFind/src/VuFind/XSLT/Processor.php index 38ca7469161..fd4f47cabdf 100644 --- a/module/VuFind/src/VuFind/XSLT/Processor.php +++ b/module/VuFind/src/VuFind/XSLT/Processor.php @@ -41,6 +41,29 @@ use XSLTProcessor; */ class Processor { + /** + * Locate an XSLT file and return its full path. + * + * @param string $xslt Filename + * + * @return string + * @throws \Exception + */ + protected static function findXslt($xslt) + { + $paths = [ + LOCAL_OVERRIDE_DIR . '/xsl/', + APPLICATION_PATH . '/module/VuFind/xsl/', + APPLICATION_PATH . '/xsl/', + ]; + foreach ($paths as $path) { + if (file_exists($path . $xslt)) { + return $path . $xslt; + } + } + throw new \Exception('Cannot locate ' . $xslt); + } + /** * Perform an XSLT transformation and return the results. * @@ -53,8 +76,7 @@ class Processor public static function process($xslt, $xml, $params = []) { $style = new DOMDocument(); - // TODO: support local overrides - $style->load(APPLICATION_PATH . '/module/VuFind/xsl/' . $xslt); + $style->load(static::findXslt($xslt)); $xsl = new XSLTProcessor(); $xsl->importStyleSheet($style); $doc = new DOMDocument(); -- GitLab