-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return results as a \Generator (#185)
* WIP: initial concept of returning report objects * WIP: add a test * Docs update Change results handling example * Attempt to fix tests #1 * Change flush() signature for easier mocking * Unqualify iterable * Remove ignored vagrant file
- Loading branch information
1 parent
3727db3
commit eac6697
Showing
8 changed files
with
248 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ | |
composer.lock | ||
phpunit.xml | ||
|
||
# web-push-testing-service logs | ||
cli.log | ||
module.log | ||
.vagrant | ||
Vagrantfile # temp, may be? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
/** | ||
* @author Igor Timoshenkov [[email protected]] | ||
* @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 { | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
protected $success; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var ResponseInterface | ||
*/ | ||
protected $response; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $reason; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param ResponseInterface $response | ||
* @param bool $success | ||
* @param string $reason | ||
*/ | ||
public function __construct(?RequestInterface $request = null, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK') { | ||
$this->success = $success; | ||
$this->request = $request; | ||
$this->response = $response; | ||
$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 | ||
*/ | ||
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 { | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.