From b31cc55c3640d4cbecc4e3cde1bfbddc07e0cf60 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Thu, 21 Nov 2024 19:54:07 -0500 Subject: [PATCH 1/2] Fix usage of cache in XmlFileInterpreter --- src/DataSource/Interpreter/XmlFileInterpreter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataSource/Interpreter/XmlFileInterpreter.php b/src/DataSource/Interpreter/XmlFileInterpreter.php index a3e1a0db..6af30f0e 100644 --- a/src/DataSource/Interpreter/XmlFileInterpreter.php +++ b/src/DataSource/Interpreter/XmlFileInterpreter.php @@ -53,7 +53,7 @@ class XmlFileInterpreter extends AbstractInterpreter */ protected function loadData(string $path) { - if ($this->cachedFilePath === $path && !empty($this->cachedContent)) { + if ($this->cachedFilePath !== $path || !empty($this->cachedContent)) { $schema = $this->schema; $dom = XmlUtils::loadFile($path, function ($dom) use ($schema) { if (!empty($schema)) { From 3ca3670af8fb1b6f270aff22dc2262e2379b8a31 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Thu, 21 Nov 2024 19:59:22 -0500 Subject: [PATCH 2/2] remove dupe code --- .../Interpreter/XmlFileInterpreter.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/DataSource/Interpreter/XmlFileInterpreter.php b/src/DataSource/Interpreter/XmlFileInterpreter.php index 6af30f0e..67b77ea9 100644 --- a/src/DataSource/Interpreter/XmlFileInterpreter.php +++ b/src/DataSource/Interpreter/XmlFileInterpreter.php @@ -44,6 +44,17 @@ class XmlFileInterpreter extends AbstractInterpreter */ protected $cachedFilePath = null; + protected function loadDataRaw(string $path){ + $schema = $this->schema; + return XmlUtils::loadFile($path, function ($dom) use ($schema) { + if (!empty($schema)) { + return @$dom->schemaValidateSource($schema); + } + + return true; + }); + } + /** * @param string $path * @@ -54,14 +65,7 @@ class XmlFileInterpreter extends AbstractInterpreter protected function loadData(string $path) { if ($this->cachedFilePath !== $path || !empty($this->cachedContent)) { - $schema = $this->schema; - $dom = XmlUtils::loadFile($path, function ($dom) use ($schema) { - if (!empty($schema)) { - return @$dom->schemaValidateSource($schema); - } - - return true; - }); + $dom = $this->loadDataRaw($path); } else { $dom = $this->cachedContent; } @@ -100,14 +104,7 @@ public function fileValid(string $path, bool $originalFilename = false): bool } try { - $schema = $this->schema; - $dom = XmlUtils::loadFile($path, function ($dom) use ($schema) { - if (!empty($schema)) { - return @$dom->schemaValidateSource($schema); - } - - return true; - }); + $dom = $this->loadDataRaw($path); } catch (XmlParsingException $exception) { $message = 'Error validating XML: ' . $exception->getMessage(); $this->applicationLogger->info($message, [