summaryrefslogtreecommitdiff
path: root/inc/mailgun/php-http/message/src/Decorator
diff options
context:
space:
mode:
Diffstat (limited to 'inc/mailgun/php-http/message/src/Decorator')
-rw-r--r--inc/mailgun/php-http/message/src/Decorator/MessageDecorator.php133
-rw-r--r--inc/mailgun/php-http/message/src/Decorator/RequestDecorator.php88
-rw-r--r--inc/mailgun/php-http/message/src/Decorator/ResponseDecorator.php57
-rw-r--r--inc/mailgun/php-http/message/src/Decorator/StreamDecorator.php138
4 files changed, 416 insertions, 0 deletions
diff --git a/inc/mailgun/php-http/message/src/Decorator/MessageDecorator.php b/inc/mailgun/php-http/message/src/Decorator/MessageDecorator.php
new file mode 100644
index 0000000..0ffc7ca
--- /dev/null
+++ b/inc/mailgun/php-http/message/src/Decorator/MessageDecorator.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Http\Message\Decorator;
+
+use Psr\Http\Message\MessageInterface;
+use Psr\Http\Message\StreamInterface;
+
+/**
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+trait MessageDecorator
+{
+ /**
+ * @var MessageInterface
+ */
+ private $message;
+
+ /**
+ * Returns the decorated message.
+ *
+ * Since the underlying Message is immutable as well
+ * exposing it is not an issue, because it's state cannot be altered
+ *
+ * @return MessageInterface
+ */
+ public function getMessage()
+ {
+ return $this->message;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getProtocolVersion()
+ {
+ return $this->message->getProtocolVersion();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withProtocolVersion($version)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withProtocolVersion($version);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getHeaders()
+ {
+ return $this->message->getHeaders();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasHeader($header)
+ {
+ return $this->message->hasHeader($header);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getHeader($header)
+ {
+ return $this->message->getHeader($header);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getHeaderLine($header)
+ {
+ return $this->message->getHeaderLine($header);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withHeader($header, $value)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withHeader($header, $value);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withAddedHeader($header, $value)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withAddedHeader($header, $value);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withoutHeader($header)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withoutHeader($header);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getBody()
+ {
+ return $this->message->getBody();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withBody(StreamInterface $body)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withBody($body);
+
+ return $new;
+ }
+}
diff --git a/inc/mailgun/php-http/message/src/Decorator/RequestDecorator.php b/inc/mailgun/php-http/message/src/Decorator/RequestDecorator.php
new file mode 100644
index 0000000..7c50e58
--- /dev/null
+++ b/inc/mailgun/php-http/message/src/Decorator/RequestDecorator.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Http\Message\Decorator;
+
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\UriInterface;
+
+/**
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+trait RequestDecorator
+{
+ use MessageDecorator {
+ getMessage as getRequest;
+ }
+
+ /**
+ * Exchanges the underlying request with another.
+ *
+ * @param RequestInterface $request
+ *
+ * @return self
+ */
+ public function withRequest(RequestInterface $request)
+ {
+ $new = clone $this;
+ $new->message = $request;
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRequestTarget()
+ {
+ return $this->message->getRequestTarget();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withRequestTarget($requestTarget)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withRequestTarget($requestTarget);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMethod()
+ {
+ return $this->message->getMethod();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withMethod($method)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withMethod($method);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getUri()
+ {
+ return $this->message->getUri();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withUri(UriInterface $uri, $preserveHost = false)
+ {
+ $new = clone $this;
+ $new->message = $this->message->withUri($uri, $preserveHost);
+
+ return $new;
+ }
+}
diff --git a/inc/mailgun/php-http/message/src/Decorator/ResponseDecorator.php b/inc/mailgun/php-http/message/src/Decorator/ResponseDecorator.php
new file mode 100644
index 0000000..82d9ae0
--- /dev/null
+++ b/inc/mailgun/php-http/message/src/Decorator/ResponseDecorator.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace Http\Message\Decorator;
+
+use Psr\Http\Message\ResponseInterface;
+
+/**
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+trait ResponseDecorator
+{
+ use MessageDecorator {
+ getMessage as getResponse;
+ }
+
+ /**
+ * Exchanges the underlying response with another.
+ *
+ * @param ResponseInterface $response
+ *
+ * @return self
+ */
+ public function withResponse(ResponseInterface $response)
+ {
+ $new = clone $this;
+ $new->message = $response;
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getStatusCode()
+ {
+ return $this->message->getStatusCode();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function withStatus($code, $reasonPhrase = '')
+ {
+ $new = clone $this;
+ $new->message = $this->message->withStatus($code, $reasonPhrase);
+
+ return $new;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getReasonPhrase()
+ {
+ return $this->message->getReasonPhrase();
+ }
+}
diff --git a/inc/mailgun/php-http/message/src/Decorator/StreamDecorator.php b/inc/mailgun/php-http/message/src/Decorator/StreamDecorator.php
new file mode 100644
index 0000000..f405c7a
--- /dev/null
+++ b/inc/mailgun/php-http/message/src/Decorator/StreamDecorator.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Http\Message\Decorator;
+
+use Psr\Http\Message\StreamInterface;
+
+/**
+ * Decorates a stream.
+ *
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+trait StreamDecorator
+{
+ /**
+ * @var StreamInterface
+ */
+ protected $stream;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __toString()
+ {
+ return $this->stream->__toString();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function close()
+ {
+ $this->stream->close();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function detach()
+ {
+ return $this->stream->detach();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSize()
+ {
+ return $this->stream->getSize();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function tell()
+ {
+ return $this->stream->tell();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function eof()
+ {
+ return $this->stream->eof();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isSeekable()
+ {
+ return $this->stream->isSeekable();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function seek($offset, $whence = SEEK_SET)
+ {
+ $this->stream->seek($offset, $whence);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function rewind()
+ {
+ $this->stream->rewind();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isWritable()
+ {
+ return $this->stream->isWritable();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function write($string)
+ {
+ return $this->stream->write($string);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isReadable()
+ {
+ return $this->stream->isReadable();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function read($length)
+ {
+ return $this->stream->read($length);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getContents()
+ {
+ return $this->stream->getContents();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMetadata($key = null)
+ {
+ return $this->stream->getMetadata($key);
+ }
+}