- private static function fromBase64(Body $base64) : string {
- if (false === ($decoded = base64_decode($base64))) {
- throw new \UnexpectedValueExcpeption("Could not decode BASE64");
+ /**
+ * @param Header $contentType
+ */
+ function setContentTypeHeader(Header $contentType) {
+ $this->type = $this->extractTypeFromHeader($contentType);
+ }
+
+ /**
+ * @param string $contentType
+ */
+ function setContentType(string $contentType) {
+ $this->type = $this->extractType($contentType);
+ }
+
+ /**
+ * @return int
+ */
+ function getVersion() : int {
+ return $this->version;
+ }
+
+ /**
+ * Get the (abbreviated) content type name
+ * @return string
+ */
+ function getType() : string {
+ return $this->type;
+ }
+
+ /**
+ * Get the (full) content type
+ * @return string
+ */
+ function getContentType() : string {
+ return $this->composeType($this->type);
+ }
+
+ /**
+ * @param API $api
+ * @return API clone
+ */
+ function apply(API $api) : API {
+ return $api->withHeader("Accept", $this->getContentType());
+ }
+
+ /**
+ * Decode a response message's body according to its content type
+ * @param Body $data
+ * @return mixed
+ * @throws UnexpectedValueException
+ */
+ function decode(Body $data) {
+ $type = $this->getType();
+ if (static::registered($type)) {
+ return self::$types[$type]->decode($data);