diff options
author | purplecode <niespammnie@gmail.com> | 2013-12-11 16:16:14 +0100 |
---|---|---|
committer | purplecode <niespammnie@gmail.com> | 2013-12-11 16:16:14 +0100 |
commit | c1c61d71f03e4567e1323b50b87376ac50baa8b7 (patch) | |
tree | 41d774f4c98441570d9fb38dcd8ebe565ac4d5b1 /src/PurpleCode/PCurl/PObjectCurl.php | |
parent | df80c473ddea31add7731193175741c3d15ea494 (diff) | |
download | php.curl-c1c61d71f03e4567e1323b50b87376ac50baa8b7.zip php.curl-c1c61d71f03e4567e1323b50b87376ac50baa8b7.tar.gz php.curl-c1c61d71f03e4567e1323b50b87376ac50baa8b7.tar.bz2 |
PObjectCurl and PJsonCurl
Diffstat (limited to 'src/PurpleCode/PCurl/PObjectCurl.php')
-rw-r--r-- | src/PurpleCode/PCurl/PObjectCurl.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/PurpleCode/PCurl/PObjectCurl.php b/src/PurpleCode/PCurl/PObjectCurl.php new file mode 100644 index 0000000..d874486 --- /dev/null +++ b/src/PurpleCode/PCurl/PObjectCurl.php @@ -0,0 +1,40 @@ +<?php
+
+/**
+ * PCurl is a REST client libary for PHP.
+ *
+ * See http://github.com/purplecode/php.curl for details.
+ *
+ * This code is licensed for use, modification, and distribution
+ * under the terms of the MIT License (see http://en.wikipedia.org/wiki/MIT_License)
+ */
+
+namespace PurpleCode\PCurl;
+
+use JMS\Serializer\SerializerInterface;
+
+class PObjectCurl extends PCurl {
+
+ /**
+ * @var SerializerInterface
+ */
+ private $serializer;
+ private $responseClass;
+
+ public function __construct($host, SerializerInterface $serializer) {
+ parent::__construct($host);
+ $this->serializer = $serializer;
+
+ $this->contentTypeJson();
+ }
+
+ public function responseClass($class) {
+ $this->responseClass = $class;
+ }
+
+ public function call($method, $url, $payload = '') {
+ $response = parent::call($method, $url, empty($payload) ? $payload : $this->serializer->serialize($payload, 'json'));
+ return $this->responseClass ? $this->serializer->deserialize($response, $this->responseClass, 'json') : $response;
+ }
+
+}
|