-
Notifications
You must be signed in to change notification settings - Fork 16
Adding response mutator. #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a0192c0
Adding response mutator.
iainconnor 8abb28a
Fixing style.
iainconnor 63f438f
Adding default value to header.
iainconnor 465c0e4
Adding request to callback.
iainconnor f62329e
Moving directory
iainconnor a968e8f
Renaming default header and values.
iainconnor 884c87c
Pass through cache item as well.
iainconnor 0e5159f
Adding support for multiple listeners and renaming.
iainconnor fef55cf
Whoops wrong class.
iainconnor e1e4bec
Whoops wrong class.
iainconnor c29b205
Finishing rename.
iainconnor 3edb6df
Respecting code style.
iainconnor ce5224d
bad docblock
iainconnor 27e053b
Must be nullable.
iainconnor c5e2ac2
Bad return type.
iainconnor d0f2494
Wrong var name.
iainconnor 699d45e
Adding changelog and updating version in composer.
iainconnor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,37 @@ | ||
<?php | ||
|
||
namespace Http\Client\Common\Plugin\Cache\Mutator; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Adds a header if the response came from cache. | ||
* | ||
* @author Iain Connor <[email protected]> | ||
*/ | ||
class AddHeaderResponseMutator implements ResponseMutator | ||
{ | ||
/** @var string */ | ||
private $headerName; | ||
|
||
/** | ||
* @param string $headerName | ||
*/ | ||
public function __construct($headerName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding a default value here? I guess most people will be happy with any default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'll update with a sane default. |
||
{ | ||
$this->headerName = $headerName; | ||
} | ||
|
||
/** | ||
* Mutate the response depending on the cache status. | ||
* | ||
* @param ResponseInterface $response | ||
* @param bool $cacheHit | ||
* | ||
* @return string | ||
*/ | ||
public function mutate(ResponseInterface $response, $cacheHit) | ||
{ | ||
return $response->withHeader($this->headerName, $cacheHit); | ||
} | ||
} |
This file contains hidden or 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,23 @@ | ||
<?php | ||
|
||
namespace Http\Client\Common\Plugin\Cache\Mutator; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* An interface for a mutator of a possibly cached response. | ||
* | ||
* @author Iain Connor <[email protected]> | ||
*/ | ||
interface ResponseMutator | ||
{ | ||
/** | ||
* Mutate the response depending on the cache status. | ||
* | ||
* @param ResponseInterface $response | ||
* @param bool $cacheHit | ||
* | ||
* @return string | ||
*/ | ||
public function mutate(ResponseInterface $response, $cacheHit); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the
::class
constantThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I was following the style of the other lines in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use it here and we fix it elsewhere.
(but as saying below, i think this should be an array, while we are at it.