Skip to content

Commit

Permalink
Updating CachedQuery so that it works with NestedRepository correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Moss committed Jan 24, 2014
1 parent 44b7c36 commit a4ba298
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
9 changes: 2 additions & 7 deletions src/JamesMoss/Flywheel/CachedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions src/JamesMoss/Flywheel/NestedRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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!
Expand Down
26 changes: 13 additions & 13 deletions src/JamesMoss/Flywheel/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a4ba298

Please sign in to comment.