Skip to content

Commit

Permalink
Consistency improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
l3l0 committed Nov 9, 2012
1 parent 599b594 commit 614eac1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 28 deletions.
4 changes: 2 additions & 2 deletions spec/Gaufrette/Adapter/RackspaceCloudfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ function it_should_get_keys($container)

function it_should_not_support_mtime()
{
$this->mtime('filename')->shouldBe(null);
$this->mtime('filename2')->shouldBe(null);
$this->mtime('filename')->shouldBe(false);
$this->mtime('filename2')->shouldBe(false);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Gaufrette/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Adapter
*
* @param string $key
*
* @return string or false if cannot read content
* @return string|boolean if cannot read content
*/
public function read($key);

Expand All @@ -25,7 +25,7 @@ public function read($key);
* @param string $key
* @param string $content
*
* @return integer The number of bytes that were written into the file
* @return integer|boolean The number of bytes that were written into the file
*/
public function write($key, $content);

Expand All @@ -34,7 +34,7 @@ public function write($key, $content);
*
* @param string $key
*
* @return Boolean
* @return boolean
*/
public function exists($key);

Expand All @@ -50,7 +50,7 @@ public function keys();
*
* @param string $key
*
* @return integer An UNIX like timestamp or false
* @return integer|boolean An UNIX like timestamp or false
*/
public function mtime($key);

Expand Down
5 changes: 3 additions & 2 deletions src/Gaufrette/Adapter/AclAwareAmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gaufrette\Adapter;

use \AmazonS3;
use Gaufrette\Adapter;

/**
Expand All @@ -16,10 +17,10 @@ class AclAwareAmazonS3 implements Adapter,
protected $delegate;
protected $s3;
protected $bucketName;
protected $aclConstant = \AmazonS3::ACL_PRIVATE;
protected $aclConstant = AmazonS3::ACL_PRIVATE;
protected $users = array();

public function __construct(Adapter $delegate, \AmazonS3 $s3, $bucketName)
public function __construct(Adapter $delegate, AmazonS3 $s3, $bucketName)
{
$this->delegate = $delegate;
$this->s3 = $s3;
Expand Down
7 changes: 4 additions & 3 deletions src/Gaufrette/Adapter/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gaufrette\Adapter;

use \AmazonS3 as AmazonClient;
use Gaufrette\Adapter;

/**
Expand All @@ -20,12 +21,12 @@ class AmazonS3 implements Adapter,
protected $metadata;
protected $options;

public function __construct(\AmazonS3 $service, $bucket, $options = array())
public function __construct(AmazonClient $service, $bucket, $options = array())
{
$this->service = $service;
$this->bucket = $bucket;
$this->options = array_replace_recursive(
array('directory' => '', 'create' => false, 'region' => \AmazonS3::REGION_US_E1),
array('directory' => '', 'create' => false, 'region' => AmazonClient::REGION_US_E1),
$options
);
}
Expand Down Expand Up @@ -120,7 +121,7 @@ public function write($key, $content)
$this->ensureBucketExists();

$opt = array_replace_recursive(
array('acl' => \AmazonS3::ACL_PUBLIC),
array('acl' => AmazonClient::ACL_PUBLIC),
$this->getMetadata($key),
array('content' => $content)
);
Expand Down
20 changes: 12 additions & 8 deletions src/Gaufrette/Adapter/Dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Gaufrette\Adapter;
use Gaufrette\Util;
use Gaufrette\Exception;
use \Dropbox_API as DropboxApi;
use \Dropbox_Exception_NotFound as DropboxNotFoundException;

/**
* Dropbox adapter
Expand All @@ -22,7 +24,7 @@ class Dropbox implements Adapter
*
* @param \Dropbox_API $client The Dropbox API client
*/
public function __construct(\Dropbox_API $client)
public function __construct(DropboxApi $client)
{
$this->client = $client;
}
Expand All @@ -44,7 +46,7 @@ public function read($key)
*/
public function isDirectory($key)
{
$metadata = $this->getMetadata($key);
$metadata = $this->getDropboxMetadata($key);

return (boolean) isset($metadata['is_dir']) ? $metadata['is_dir'] : false;
}
Expand Down Expand Up @@ -104,7 +106,7 @@ public function rename($sourceKey, $targetKey)
*/
public function mtime($key)
{
$metadata = $this->getMetadata($key);
$metadata = $this->getDropboxMetadata($key);

return strtotime($metadata['modified']);
}
Expand All @@ -115,10 +117,12 @@ public function mtime($key)
public function keys()
{
$metadata = $this->client->getMetaData('/', true);
$contents = isset($metadata['contents']) ? $metadata['contents'] : array();
if (! isset($metadata['contents'])) {
return array();
}

$keys = array();
foreach ($contents as $value) {
foreach ($metadata['contents'] as $value) {
$file = ltrim($value['path'], '/');
$keys[] = $file;
if ('.' !== dirname($file)) {
Expand All @@ -136,19 +140,19 @@ public function keys()
public function exists($key)
{
try {
$this->getMetadata($key);
$this->getDropboxMetadata($key);

return true;
} catch (Exception\FileNotFound $e) {
return false;
}
}

private function getMetadata($key)
private function getDropboxMetadata($key)
{
try {
$metadata = $this->client->getMetaData($key, false);
} catch (\Dropbox_Exception_NotFound $e) {
} catch (DropboxNotFoundException $e) {
throw new Exception\FileNotFound($key, 0, $e);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gaufrette/Adapter/GridFS.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Gaufrette\Adapter;

use Gaufrette\Adapter;
use \MongoGridFS as MongoGridFs;
use \MongoDate;

/**
* Adapter for the GridFS filesystem on MongoDB database
Expand All @@ -23,7 +25,7 @@ class GridFS implements Adapter,
*
* @param \MongoGridFS $gridFS
*/
public function __construct(\MongoGridFS $gridFS)
public function __construct(MongoGridFs $gridFS)
{
$this->gridFS = $gridFS;
}
Expand All @@ -47,7 +49,7 @@ public function write($key, $content)
$this->delete($key);
}

$metadata = array_replace_recursive(array('date' => new \MongoDate()), $this->getMetadata($key), array('filename' => $key));
$metadata = array_replace_recursive(array('date' => new MongoDate()), $this->getMetadata($key), array('filename' => $key));
$id = $this->gridFS->storeBytes($content, $metadata);
$file = $this->gridFS->findOne(array('_id' => $id));

Expand Down
5 changes: 2 additions & 3 deletions src/Gaufrette/Adapter/MetadataSupporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
interface MetadataSupporter
{
/**
* @param string $key
* @param array $metadata
* @return null
* @param string $key
* @param array $metadata
*/
public function setMetadata($key, $content);

Expand Down
5 changes: 3 additions & 2 deletions src/Gaufrette/Adapter/RackspaceCloudfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gaufrette\Adapter;
use Gaufrette\Util;
use \CF_Container as RackspaceContainer;

/**
* Rackspace cloudfiles adapter
Expand All @@ -21,7 +22,7 @@ class RackspaceCloudfiles implements Adapter,
*
* @param CF_Container $container A CF_Container instance
*/
public function __construct(\CF_Container $container)
public function __construct(RackspaceContainer $container)
{
$this->container = $container;
}
Expand Down Expand Up @@ -98,7 +99,7 @@ public function keys()
*/
public function mtime($key)
{
return;
return false;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Gaufrette/Adapter/Sftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gaufrette\Adapter;

use Gaufrette\Adapter;
use Ssh\Sftp as SftpClient;

class Sftp implements Adapter,
ChecksumCalculator
Expand All @@ -20,7 +21,7 @@ class Sftp implements Adapter,
* @param boolean $create Whether to create the remote directory if it
* does not exist
*/
public function __construct(\Ssh\Sftp $sftp, $directory = null, $create = false)
public function __construct(SftpClient $sftp, $directory = null, $create = false)
{
$this->sftp = $sftp;
$this->directory = $directory;
Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function write($key, $content)
*/
public function exists($key)
{
return (bool) $this->getStat($key);
return (boolean) $this->getStat($key);
}

/**
Expand Down

0 comments on commit 614eac1

Please sign in to comment.