From 300b5fe7dc69a49f54d295e77dbc3f8a9830b106 Mon Sep 17 00:00:00 2001 From: Annhe Date: Mon, 24 Dec 2018 17:27:25 +0800 Subject: [PATCH] add a method setPatchType in Client to support different patch type --- src/Client.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 3d42750..2eef351 100644 --- a/src/Client.php +++ b/src/Client.php @@ -175,6 +175,13 @@ class Client */ protected $classInstances = []; + /** + * header for patch. + * + * @var array + */ + protected $patchHeader = ['Content-Type' => 'application/strategic-merge-patch+json']; + /** * The constructor. * @@ -235,6 +242,21 @@ public function setNamespace($namespace) $this->namespace = $namespace; } + /** + * Set patch header + * + * @param patch type + */ + public function setPatchType($patchType = "strategic") { + if ($patchType == "merge") { + $this->patchHeader = ['Content-Type' => 'application/merge-patch+json']; + } elseif ($patchType == "json") { + $this->patchHeader = ['Content-Type' => 'application/json-patch+json']; + } else { + $this->patchHeader = ['Content-Type' => 'application/strategic-merge-patch+json']; + } + } + /** * Check if we're using guzzle 6. * @@ -335,7 +357,7 @@ public function sendRequest($method, $uri, $query = [], $body = [], $namespace = } if ($method === 'PATCH') { - $requestOptions['headers'] = ['Content-Type' => 'application/strategic-merge-patch+json']; + $requestOptions['headers'] = $this->patchHeader; } if (!$this->isUsingGuzzle6()) {