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

Filter prefix in keys #51

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter.php
Expand Up @@ -45,7 +45,7 @@ function exists($key);
*
* @return array
*/
function keys();
function keys($prefix = null);

/**
* Returns the last modified time
Expand Down
4 changes: 2 additions & 2 deletions src/Gaufrette/Adapter/AclAwareAmazonS3.php
Expand Up @@ -131,9 +131,9 @@ public function checksum($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
return $this->delegate->keys();
return $this->delegate->keys($prefix);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Gaufrette/Adapter/AmazonS3.php
Expand Up @@ -189,11 +189,15 @@ protected function getHeaders($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
$this->ensureBucketExists();

$response = $this->service->list_objects($this->bucket);
$options = array();
if (null !== $prefix) {
$options['prefix'] = $prefix;
}
$response = $this->service->list_objects($this->bucket, $options);
if (!$response->isOK()) {
throw new \RuntimeException('Could not get the keys.');
}
Expand Down
9 changes: 7 additions & 2 deletions src/Gaufrette/Adapter/Apc.php
Expand Up @@ -71,9 +71,14 @@ public function exists($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
$pattern = sprintf('/^%s/', preg_quote($this->prefix));
if (null !== $prefix) {
$prefix = $this->computePath($prefix);
} else {
$prefix = $this->prefix;
}
$pattern = sprintf('/^%s/', preg_quote($prefix));
$cachedKeys = new \APCIterator('user', $pattern, APC_ITER_NONE);

if (null === $cachedKeys) {
Expand Down
5 changes: 4 additions & 1 deletion src/Gaufrette/Adapter/Cache.php
Expand Up @@ -132,8 +132,11 @@ public function checksum($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
if (null !== $prefix) {
throw new \BadMethodCallException("Usage of prefix filter not implemented yet.");
}
$cacheFile = 'keys.cache';
if ($this->needsRebuild($cacheFile)) {
$keys = $this->source->keys();
Expand Down
5 changes: 4 additions & 1 deletion src/Gaufrette/Adapter/Ftp.php
Expand Up @@ -134,8 +134,11 @@ public function exists($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
if (null !== $prefix) {
return $this->fetchKeys($prefix);
}
return $this->fetchKeys();
}

Expand Down
14 changes: 9 additions & 5 deletions src/Gaufrette/Adapter/GridFS.php
Expand Up @@ -166,12 +166,16 @@ public function query($keyFragment, $filesystem, $sortKey = 'name', $sortDirecti
/**
* {@InheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
/**
* This seems to work but performance is a big question...
*/
$cursor = $this->gridfsInstance->find(array(), array('key'));
if (null !== $prefix) {
$cursor = $this->gridfsInstance->find(array('key' => sprintf('/^%s/', preg_quote($prefix)) ), array('key'));
} else {
/**
* This seems to work but performance is a big question...
*/
$cursor = $this->gridfsInstance->find(array(), array('key'));
}
$temp = array();
foreach($cursor as $f) {
$temp[] = $f->file['key'];
Expand Down
5 changes: 4 additions & 1 deletion src/Gaufrette/Adapter/InMemory.php
Expand Up @@ -113,8 +113,11 @@ public function exists($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
if (null !== $prefix) {
throw new \BadMethodCallException("Usage of prefix filter not implemented yet.");
}
return array_keys($this->files);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Gaufrette/Adapter/Local.php
Expand Up @@ -90,8 +90,11 @@ public function exists($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
if (null !== $prefix) {
throw new \BadMethodCallException("Usage of prefix filter not implemented yet.");
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
$this->directory,
Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/MogileFS.php
Expand Up @@ -129,7 +129,7 @@ public function exists($key)
/**
* {@InheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
throw new \BadMethodCallException("Method not implemented yet.");
}
Expand Down
5 changes: 4 additions & 1 deletion src/Gaufrette/Adapter/RackspaceCloudfiles.php
Expand Up @@ -80,8 +80,11 @@ public function exists($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
if (null !== $prefix) {
throw new \BadMethodCallException("Usage of prefix filter not implemented yet.");
}
return $this->container->list_objects(0, null, null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/Sftp.php
Expand Up @@ -88,7 +88,7 @@ public function exists($key)
/**
* {@inheritDoc}
*/
public function keys()
public function keys($prefix = null)
{
$this->initialize();

Expand Down
6 changes: 3 additions & 3 deletions src/Gaufrette/Filesystem.php
Expand Up @@ -128,9 +128,9 @@ public function delete($key)
*
* @return array
*/
public function keys()
public function keys($prefix = null)
{
return $this->adapter->keys();
return $this->adapter->keys($prefix);
}

/**
Expand All @@ -149,7 +149,7 @@ public function listDirectory($directory = '')
// Cache adapter returns null if source-Adapter does not provide the listDirectory method
if (!$listing) {
$listing = array(
'keys' => $this->keys(),
'keys' => $this->keys((empty($directory))?null:$directory),
'dirs' => array()
);
}
Expand Down