Skip to content

Commit e228e2c

Browse files
committed
Storage object exist implementation
1 parent d2b2f3c commit e228e2c

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

Storage/src/Connection/ConnectionInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public function composeObject(array $args = []);
130130
*/
131131
public function getObject(array $args = []);
132132

133+
/**
134+
* @param array $args
135+
*/
136+
public function headObject(array $args = []);
137+
133138
/**
134139
* @param array $args
135140
*/

Storage/src/Connection/Rest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,31 @@ public function getObject(array $args = [])
306306
return $this->send('objects', 'get', $args);
307307
}
308308

309+
/**
310+
* @param array $args
311+
*/
312+
public function headObject(array $args = [])
313+
{
314+
$args += [
315+
'prettyPrint' => false,
316+
];
317+
$requestOptions = $this->pluckArray([
318+
'restOptions',
319+
'retries',
320+
'retryHeaders',
321+
'requestTimeout',
322+
'restRetryFunction',
323+
'restRetryListener',
324+
'restDelayFunction',
325+
'restCalcDelayFunction',
326+
], $args);
327+
328+
$request = $this->requestBuilder->build('objects', 'get', $args);
329+
$request = $request->withMethod('HEAD');
330+
331+
return $this->requestWrapper->send($request, $requestOptions);
332+
}
333+
309334
/**
310335
* @param array $args
311336
*/

Storage/src/StorageObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function acl()
146146
public function exists(array $options = [])
147147
{
148148
try {
149-
$this->connection->getObject($this->identity + $options + ['fields' => 'name']);
149+
$this->connection->headObject($this->identity + $options);
150150
} catch (NotFoundException $ex) {
151151
return false;
152152
}

Storage/tests/Snippet/StorageObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testExists()
8181
$snippet = $this->snippetFromMethod(StorageObject::class, 'exists');
8282
$snippet->addLocal('object', $this->object);
8383

84-
$this->connection->getObject(Argument::any())
84+
$this->connection->headObject(Argument::any())
8585
->shouldBeCalled()
8686
->willReturn([]);
8787

Storage/tests/Unit/StorageObjectTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public function testGetAcl()
8282

8383
public function testDoesExistTrue()
8484
{
85-
$this->connection->getObject(Argument::any())->willReturn(['name' => self::OBJECT]);
85+
$this->connection->headObject(Argument::any())->willReturn([]);
8686
$object = new StorageObject($this->connection->reveal(), self::OBJECT, self::BUCKET);
8787

8888
$this->assertTrue($object->exists());
8989
}
9090

9191
public function testDoesExistFalse()
9292
{
93-
$this->connection->getObject(Argument::any())->willThrow(new NotFoundException(null));
93+
$this->connection->headObject(Argument::any())->willThrow(new NotFoundException(null));
9494
$object = new StorageObject($this->connection->reveal(), self::OBJECT, self::BUCKET);
9595

9696
$this->assertFalse($object->exists());

0 commit comments

Comments
 (0)