Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of cache in XmlFileInterpreter #438

Open
wants to merge 2 commits into
base: 1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/DataSource/Interpreter/XmlFileInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -53,15 +64,8 @@ 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;
});
if ($this->cachedFilePath !== $path || !empty($this->cachedContent)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these predicates were changed

$dom = $this->loadDataRaw($path);
} else {
$dom = $this->cachedContent;
}
Expand Down Expand Up @@ -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, [
Expand Down
Loading