Skip to content

Commit e959b01

Browse files
committed
Allow using PUT (default) or PATCH as update method depending on property.
1 parent 5228802 commit e959b01

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/OpenCloud/Common/Resource/PersistentResource.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
abstract class PersistentResource extends BaseResource
3030
{
31+
const UPDATE_METHOD = 'PUT';
32+
3133
/**
3234
* Create a new resource
3335
*
@@ -79,7 +81,16 @@ public function update($params = array())
7981
$this->checkJsonError();
8082

8183
// send the request
82-
return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send();
84+
return $this->makeUpdateRequest($json);
85+
}
86+
87+
protected function makeUpdateRequest($json)
88+
{
89+
if ('PATCH' === static::UPDATE_METHOD) {
90+
return $this->getClient()->patch($this->getUrl(), self::getJsonHeader(), $json)->send();
91+
} else {
92+
return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send();
93+
}
8394
}
8495

8596
/**

0 commit comments

Comments
 (0)