diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/minishlink/web-push/src/MessageSentReport.php | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to '')
-rw-r--r-- | vendor/minishlink/web-push/src/MessageSentReport.php | 362 |
1 files changed, 181 insertions, 181 deletions
diff --git a/vendor/minishlink/web-push/src/MessageSentReport.php b/vendor/minishlink/web-push/src/MessageSentReport.php index c569952..a6945e6 100644 --- a/vendor/minishlink/web-push/src/MessageSentReport.php +++ b/vendor/minishlink/web-push/src/MessageSentReport.php @@ -1,181 +1,181 @@ -<?php -/** - * @author Igor Timoshenkov [it@campoint.net] - * @started: 03.09.2018 9:21 - */ - -namespace Minishlink\WebPush; - -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; - -/** - * Standardized response from sending a message - */ -class MessageSentReport implements \JsonSerializable -{ - - /** - * @var boolean - */ - protected $success; - - /** - * @var RequestInterface - */ - protected $request; - - /** - * @var ResponseInterface | null - */ - protected $response; - - /** - * @var string - */ - protected $reason; - - /** - * @param RequestInterface $request - * @param ResponseInterface $response - * @param bool $success - * @param string $reason - */ - public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK') - { - $this->request = $request; - $this->response = $response; - $this->success = $success; - $this->reason = $reason; - } - - /** - * @return bool - */ - public function isSuccess(): bool - { - return $this->success; - } - - /** - * @param bool $success - * - * @return MessageSentReport - */ - public function setSuccess(bool $success): MessageSentReport - { - $this->success = $success; - return $this; - } - - /** - * @return RequestInterface - */ - public function getRequest(): RequestInterface - { - return $this->request; - } - - /** - * @param RequestInterface $request - * - * @return MessageSentReport - */ - public function setRequest(RequestInterface $request): MessageSentReport - { - $this->request = $request; - return $this; - } - - /** - * @return ResponseInterface | null - */ - public function getResponse(): ?ResponseInterface - { - return $this->response; - } - - /** - * @param ResponseInterface $response - * - * @return MessageSentReport - */ - public function setResponse(ResponseInterface $response): MessageSentReport - { - $this->response = $response; - return $this; - } - - /** - * @return string - */ - public function getEndpoint(): string - { - return $this->request->getUri()->__toString(); - } - - /** - * @return bool - */ - public function isSubscriptionExpired(): bool - { - if (!$this->response) { - return false; - } - - return \in_array($this->response->getStatusCode(), [404, 410], true); - } - - /** - * @return string - */ - public function getReason(): string - { - return $this->reason; - } - - /** - * @param string $reason - * - * @return MessageSentReport - */ - public function setReason(string $reason): MessageSentReport - { - $this->reason = $reason; - return $this; - } - - /** - * @return string - */ - public function getRequestPayload(): string - { - return $this->request->getBody()->getContents(); - } - - /** - * @return string | null - */ - public function getResponseContent(): ?string - { - if (!$this->response) { - return null; - } - - return $this->response->getBody()->getContents(); - } - - /** - * @return array|mixed - */ - public function jsonSerialize() - { - return [ - 'success' => $this->isSuccess(), - 'expired' => $this->isSubscriptionExpired(), - 'reason' => $this->reason, - 'endpoint' => $this->getEndpoint(), - 'payload' => $this->request->getBody()->getContents(), - ]; - } -} +<?php
+/**
+ * @author Igor Timoshenkov [it@campoint.net]
+ * @started: 03.09.2018 9:21
+ */
+
+namespace Minishlink\WebPush;
+
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+
+/**
+ * Standardized response from sending a message
+ */
+class MessageSentReport implements \JsonSerializable
+{
+
+ /**
+ * @var boolean
+ */
+ protected $success;
+
+ /**
+ * @var RequestInterface
+ */
+ protected $request;
+
+ /**
+ * @var ResponseInterface | null
+ */
+ protected $response;
+
+ /**
+ * @var string
+ */
+ protected $reason;
+
+ /**
+ * @param RequestInterface $request
+ * @param ResponseInterface $response
+ * @param bool $success
+ * @param string $reason
+ */
+ public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK')
+ {
+ $this->request = $request;
+ $this->response = $response;
+ $this->success = $success;
+ $this->reason = $reason;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isSuccess(): bool
+ {
+ return $this->success;
+ }
+
+ /**
+ * @param bool $success
+ *
+ * @return MessageSentReport
+ */
+ public function setSuccess(bool $success): MessageSentReport
+ {
+ $this->success = $success;
+ return $this;
+ }
+
+ /**
+ * @return RequestInterface
+ */
+ public function getRequest(): RequestInterface
+ {
+ return $this->request;
+ }
+
+ /**
+ * @param RequestInterface $request
+ *
+ * @return MessageSentReport
+ */
+ public function setRequest(RequestInterface $request): MessageSentReport
+ {
+ $this->request = $request;
+ return $this;
+ }
+
+ /**
+ * @return ResponseInterface | null
+ */
+ public function getResponse(): ?ResponseInterface
+ {
+ return $this->response;
+ }
+
+ /**
+ * @param ResponseInterface $response
+ *
+ * @return MessageSentReport
+ */
+ public function setResponse(ResponseInterface $response): MessageSentReport
+ {
+ $this->response = $response;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getEndpoint(): string
+ {
+ return $this->request->getUri()->__toString();
+ }
+
+ /**
+ * @return bool
+ */
+ public function isSubscriptionExpired(): bool
+ {
+ if (!$this->response) {
+ return false;
+ }
+
+ return \in_array($this->response->getStatusCode(), [404, 410], true);
+ }
+
+ /**
+ * @return string
+ */
+ public function getReason(): string
+ {
+ return $this->reason;
+ }
+
+ /**
+ * @param string $reason
+ *
+ * @return MessageSentReport
+ */
+ public function setReason(string $reason): MessageSentReport
+ {
+ $this->reason = $reason;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRequestPayload(): string
+ {
+ return $this->request->getBody()->getContents();
+ }
+
+ /**
+ * @return string | null
+ */
+ public function getResponseContent(): ?string
+ {
+ if (!$this->response) {
+ return null;
+ }
+
+ return $this->response->getBody()->getContents();
+ }
+
+ /**
+ * @return array|mixed
+ */
+ public function jsonSerialize()
+ {
+ return [
+ 'success' => $this->isSuccess(),
+ 'expired' => $this->isSubscriptionExpired(),
+ 'reason' => $this->reason,
+ 'endpoint' => $this->getEndpoint(),
+ 'payload' => $this->request->getBody()->getContents(),
+ ];
+ }
+}
|