Skip to content

Commit a047729

Browse files
Add support for restrictions parameter in MetadataField
1 parent e4b9582 commit a047729

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

src/Api/Metadata/Metadata.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Cloudinary\Api\Metadata;
1212

13+
use Cloudinary\ArrayUtils;
1314
use Cloudinary\StringUtils;
1415
use JsonSerializable;
1516

@@ -48,7 +49,7 @@ public function jsonSerialize()
4849
if (method_exists($value, 'jsonSerialize')) {
4950
$snakeCaseProperties[StringUtils::camelCaseToSnakeCase($key)] = $value->jsonSerialize();
5051
}
51-
} elseif (is_array($value)) {
52+
} elseif (is_array($value) && !ArrayUtils::isAssoc($value)) {
5253
$subArray = [];
5354
foreach ($value as $subArrayValue) {
5455
if (method_exists($subArrayValue, 'jsonSerialize')) {

src/Api/Metadata/MetadataField.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ abstract class MetadataField extends Metadata
4949
*/
5050
protected $validation;
5151

52+
/**
53+
* @var array
54+
*/
55+
protected $restrictions;
56+
5257
/**
5358
* The MetadataField constructor.
5459
*
@@ -66,7 +71,7 @@ public function __construct($label)
6671
*/
6772
public function getPropertyKeys()
6873
{
69-
return ['externalId', 'label', 'mandatory', 'defaultValue', 'type', 'validation'];
74+
return ['externalId', 'label', 'mandatory', 'defaultValue', 'type', 'validation', 'restrictions'];
7075
}
7176

7277
/**
@@ -178,4 +183,24 @@ public function setValidation(MetadataValidation $validation)
178183
{
179184
$this->validation = $validation;
180185
}
186+
187+
/**
188+
* Gets the restrictions of this field.
189+
*
190+
* @return array
191+
*/
192+
public function getRestrictions()
193+
{
194+
return $this->restrictions;
195+
}
196+
197+
/**
198+
* Sets the restrictions of this field.
199+
*
200+
* @param array $restrictions
201+
*/
202+
public function setRestrictions($restrictions)
203+
{
204+
$this->restrictions = $restrictions;
205+
}
181206
}

tests/Integration/Admin/MetadataFieldsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public function testCreateDateMetadataField()
220220
{
221221
$dateMetadataField = new DateMetadataField(self::$EXTERNAL_ID_DATE);
222222
$dateMetadataField->setExternalId(self::$EXTERNAL_ID_DATE);
223+
$dateMetadataField->setRestrictions(["readonly_ui" => true]);
223224

224225
$result = self::$adminApi->addMetadataField($dateMetadataField);
225226

@@ -229,7 +230,8 @@ public function testCreateDateMetadataField()
229230
[
230231
'label' => self::$EXTERNAL_ID_DATE,
231232
'external_id' => self::$EXTERNAL_ID_DATE,
232-
'mandatory' => false
233+
'mandatory' => false,
234+
'restrictions' => ["readonly_ui" => true],
233235
]
234236
);
235237
}

tests/Unit/Admin/MetadataFieldsTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testCreateStringMetadataField()
6565

6666
$stringMetadataField = new StringMetadataField(self::EXTERNAL_ID_STRING);
6767
$stringMetadataField->setExternalId(self::EXTERNAL_ID_STRING);
68+
$stringMetadataField->setRestrictions(["readonly_ui" => true]);
6869

6970
$mockAdminApi->addMetadataField($stringMetadataField);
7071
$lastRequest = $mockAdminApi->getMockHandler()->getLastRequest();
@@ -74,9 +75,10 @@ public function testCreateStringMetadataField()
7475
self::assertRequestFields(
7576
$lastRequest,
7677
[
77-
'type' => MetadataFieldType::STRING,
78-
'external_id' => self::EXTERNAL_ID_STRING,
79-
'label' => self::EXTERNAL_ID_STRING
78+
'type' => MetadataFieldType::STRING,
79+
'external_id' => self::EXTERNAL_ID_STRING,
80+
'label' => self::EXTERNAL_ID_STRING,
81+
'restrictions' => ["readonly_ui" => true],
8082
]
8183
);
8284
}

0 commit comments

Comments
 (0)