Skip to content

Commit 1033431

Browse files
authored
Merge pull request #208 from php-opencloud/fix-objstore-containername
Fixed containerName was not set
2 parents 55889bc + 8c1fe4c commit 1033431

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/ObjectStore/v1/Models/Container.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ public function populateFromResponse(ResponseInterface $response): self
6161
public function listObjects(array $options = [], callable $mapFn = null): \Generator
6262
{
6363
$options = array_merge($options, ['name' => $this->name, 'format' => 'json']);
64-
return $this->model(StorageObject::class)->enumerate($this->api->getContainer(), $options, $mapFn);
64+
65+
$appendContainerNameFn = function (StorageObject $resource) use ($mapFn) {
66+
$resource->containerName = $this->name;
67+
if ($mapFn) {
68+
call_user_func_array($mapFn, [&$resource]);
69+
}
70+
};
71+
72+
return $this->model(StorageObject::class)->enumerate($this->api->getContainer(), $options, $appendContainerNameFn);
6573
}
6674

6775
/**

src/ObjectStore/v1/Models/StorageObject.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OpenStack\ObjectStore\v1\Models;
44

55
use GuzzleHttp\Psr7\Uri;
6+
use OpenStack\Common\Resource\Alias;
67
use OpenStack\Common\Transport\Utils;
78
use Psr\Http\Message\ResponseInterface;
89
use Psr\Http\Message\StreamInterface;
@@ -32,7 +33,7 @@ class StorageObject extends OperatorResource implements Creatable, Deletable, Ha
3233
/** @var string */
3334
public $contentType;
3435

35-
/** @var int */
36+
/** @var \DateTimeImmutable */
3637
public $contentLength;
3738

3839
/** @var string */
@@ -42,7 +43,21 @@ class StorageObject extends OperatorResource implements Creatable, Deletable, Ha
4243
public $metadata;
4344

4445
protected $markerKey = 'name';
45-
protected $aliases = ['bytes' => 'contentLength'];
46+
47+
protected $aliases = [
48+
'bytes' => 'contentLength',
49+
'content_type' => 'contentType',
50+
];
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function getAliases(): array
56+
{
57+
return parent::getAliases() + [
58+
'last_modified' => new Alias('lastModified', \DateTimeImmutable::class),
59+
];
60+
}
4661

4762
/**
4863
* {@inheritdoc}

0 commit comments

Comments
 (0)