From b05579ed0144f9042f72c15e636b45b9fb04f467 Mon Sep 17 00:00:00 2001 From: Zoilo Mora Date: Mon, 14 Aug 2023 11:53:42 +0200 Subject: [PATCH 1/2] feat: Cache external reference files --- src/Behat/ValidatorApiContext.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Behat/ValidatorApiContext.php b/src/Behat/ValidatorApiContext.php index 8a79d85..213dc69 100644 --- a/src/Behat/ValidatorApiContext.php +++ b/src/Behat/ValidatorApiContext.php @@ -7,7 +7,9 @@ abstract class ValidatorApiContext { - protected function checkSchemaFile($filename): void + private array $dataExternalReferences = []; + + protected function checkSchemaFile(string $filename): void { if (false === \is_file($filename)) { throw new \RuntimeException( @@ -25,15 +27,21 @@ protected function getDataExternalReferences(array $allSpec, string $originalPat foreach ($externalReferences as $externalReference) { [$pathExternalReference] = \explode('#', $externalReference); $newPath = \realpath(\dirname($originalPath) . '/' . $pathExternalReference); + $dataExternalReferences[$pathExternalReference] = $this->getDataExternalReferencesCached($newPath); + } + + return \array_merge($allSpec, $dataExternalReferences); + } + private function getDataExternalReferencesCached(string $newPath): array + { + if (false === \array_key_exists($newPath, $this->dataExternalReferences)) { $this->checkSchemaFile($newPath); $data = Yaml::parse(\file_get_contents($newPath)); - $data = $this->getDataExternalReferences($data, $newPath); - - $dataExternalReferences[$pathExternalReference] = $data; + $this->dataExternalReferences[$newPath] = $this->getDataExternalReferences($data, $newPath); } - return \array_merge($allSpec, $dataExternalReferences); + return $this->dataExternalReferences[$newPath]; } private function externalReferencesExtractor(array $array): array From 869a4b4be848acdfec9d9b25742a5f01503f7141 Mon Sep 17 00:00:00 2001 From: Zoilo Mora Date: Mon, 14 Aug 2023 12:05:24 +0200 Subject: [PATCH 2/2] feat: Cache external reference files --- src/Behat/ValidatorApiContext.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Behat/ValidatorApiContext.php b/src/Behat/ValidatorApiContext.php index 213dc69..8e09049 100644 --- a/src/Behat/ValidatorApiContext.php +++ b/src/Behat/ValidatorApiContext.php @@ -33,15 +33,15 @@ protected function getDataExternalReferences(array $allSpec, string $originalPat return \array_merge($allSpec, $dataExternalReferences); } - private function getDataExternalReferencesCached(string $newPath): array + private function getDataExternalReferencesCached(string $path): array { - if (false === \array_key_exists($newPath, $this->dataExternalReferences)) { - $this->checkSchemaFile($newPath); - $data = Yaml::parse(\file_get_contents($newPath)); - $this->dataExternalReferences[$newPath] = $this->getDataExternalReferences($data, $newPath); + if (false === \array_key_exists($path, $this->dataExternalReferences)) { + $this->checkSchemaFile($path); + $data = Yaml::parse(\file_get_contents($path)); + $this->dataExternalReferences[$path] = $this->getDataExternalReferences($data, $path); } - return $this->dataExternalReferences[$newPath]; + return $this->dataExternalReferences[$path]; } private function externalReferencesExtractor(array $array): array