From a4ba298e979473ef72a05c1e1bae9e78453104d2 Mon Sep 17 00:00:00 2001 From: James Moss Date: Fri, 24 Jan 2014 19:55:49 +0000 Subject: [PATCH] Updating CachedQuery so that it works with NestedRepository correctly. --- src/JamesMoss/Flywheel/CachedQuery.php | 9 ++----- src/JamesMoss/Flywheel/NestedRepository.php | 30 ++++++++++----------- src/JamesMoss/Flywheel/Repository.php | 26 +++++++++--------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/JamesMoss/Flywheel/CachedQuery.php b/src/JamesMoss/Flywheel/CachedQuery.php index 9e7c57e..fb97da8 100644 --- a/src/JamesMoss/Flywheel/CachedQuery.php +++ b/src/JamesMoss/Flywheel/CachedQuery.php @@ -53,17 +53,12 @@ public function execute() */ protected function getFileHash() { - $path = $this->repo->getPath(); - $files = scandir($path); + $files = $this->repo->getAllFiles(); $hash = ''; foreach ($files as $file) { - if ($file == '..' || $file == '.') { - continue; - } - $hash.= $file . '|'; - $hash.= (string) filemtime($path . '/' . $file) . '|'; + $hash.= (string) filemtime($file) . '|'; } $hash = md5($hash); diff --git a/src/JamesMoss/Flywheel/NestedRepository.php b/src/JamesMoss/Flywheel/NestedRepository.php index 2ed2dc3..413eb9b 100644 --- a/src/JamesMoss/Flywheel/NestedRepository.php +++ b/src/JamesMoss/Flywheel/NestedRepository.php @@ -51,26 +51,12 @@ public function getFilename($id) return basename($id) . '.' . $this->formatter->getFileExtension(); } - /** - * Checks to see if a document ID is valid - * - * @param string $id The ID to check - * - * @return bool True if valid, otherwise false - */ - protected function validateId($id) - { - // Similar regex to the one in the parent method, this allows forward slashes - // in the key name, except for at the start or end. - return (boolean)preg_match('/^[^\\/]?[^\\?\\*:;{}\\\\\\n]+[^\\/]$/us', $id); - } - /** * Get an array containing the path of all files in this repository * * @return array An array, item is a file path. */ - protected function getAllFiles() + public function getAllFiles() { $ext = $this->formatter->getFileExtension(); @@ -80,6 +66,20 @@ protected function getAllFiles() return $files; } + /** + * Checks to see if a document ID is valid + * + * @param string $id The ID to check + * + * @return bool True if valid, otherwise false + */ + protected function validateId($id) + { + // Similar regex to the one in the parent method, this allows forward slashes + // in the key name, except for at the start or end. + return (boolean)preg_match('/^[^\\/]?[^\\?\\*:;{}\\\\\\n]+[^\\/]$/us', $id); + } + protected function getFilesRecursive($dir, array &$result, $ext) { $extensionLength = strlen($ext) + 1; // one is for the dot! diff --git a/src/JamesMoss/Flywheel/Repository.php b/src/JamesMoss/Flywheel/Repository.php index dc1d560..eac5485 100644 --- a/src/JamesMoss/Flywheel/Repository.php +++ b/src/JamesMoss/Flywheel/Repository.php @@ -243,6 +243,19 @@ public function getFilename($id) return $id . '.' . $this->formatter->getFileExtension(); } + /** + * Get an array containing the path of all files in this repository + * + * @return array An array, item is a file + */ + public function getAllFiles() + { + $ext = $this->formatter->getFileExtension(); + $files = glob($this->path . DIRECTORY_SEPARATOR . '*.' . $ext); + + return $files; + } + /** * Validates the name of the repo to ensure it can be stored in the * filesystem. @@ -272,19 +285,6 @@ protected function validateId($id) return (boolean)preg_match('/^[^\\/\\?\\*:;{}\\\\\\n]+$/us', $id); } - /** - * Get an array containing the path of all files in this repository - * - * @return array An array, item is a file - */ - protected function getAllFiles() - { - $ext = $this->formatter->getFileExtension(); - $files = glob($this->path . DIRECTORY_SEPARATOR . '*.' . $ext); - - return $files; - } - /** * Generates a random, unique ID for a document. The result is returned in * base62. This keeps it shorted but still human readable if shared in URLs.