-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from FriendsOfSymfony/rework-response-tagger
Rework response tagger
- Loading branch information
Showing
18 changed files
with
239 additions
and
191 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
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
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
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 |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
namespace FOS\HttpCache; | ||
|
||
use FOS\HttpCache\Exception\InvalidTagException; | ||
use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; | ||
use FOS\HttpCache\TagHeaderFormatter\CommaSeparatedTagHeaderFormatter; | ||
use FOS\HttpCache\TagHeaderFormatter\TagHeaderFormatter; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
|
@@ -23,6 +25,7 @@ | |
* @author David Buchmann <[email protected]> | ||
* @author André Rømcke <[email protected]> | ||
* @author Wicliff Wolda <[email protected]> | ||
* @author Yanick Witschi <[email protected]> | ||
*/ | ||
class ResponseTagger | ||
{ | ||
|
@@ -32,37 +35,41 @@ class ResponseTagger | |
private $options; | ||
|
||
/** | ||
* @var TagCapable | ||
* @var TagHeaderFormatter | ||
*/ | ||
private $proxyClient; | ||
private $headerFormatter; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $tags = []; | ||
|
||
/** | ||
* Create the response tagger with a tag capable proxy client and options. | ||
* Create the response tagger with a tag header formatter and options. | ||
* | ||
* Supported options are: | ||
* | ||
* - header_formatter (TagHeaderFormatter) Default: CommaSeparatedTagHeaderFormatter with default header name | ||
* - strict (bool) Default: false. If set to true, throws exception when adding empty tags | ||
* | ||
* @param TagCapable $proxyClient | ||
* @param array $options | ||
* @param array $options | ||
*/ | ||
public function __construct(TagCapable $proxyClient, array $options = []) | ||
public function __construct(array $options = []) | ||
{ | ||
$this->proxyClient = $proxyClient; | ||
|
||
$resolver = new OptionsResolver(); | ||
$resolver->setDefaults([ | ||
// callback to avoid instantiating the formatter when its not needed | ||
'header_formatter' => function (Options $options) { | ||
return new CommaSeparatedTagHeaderFormatter(); | ||
}, | ||
'strict' => false, | ||
]); | ||
|
||
$resolver->setAllowedTypes('header_formatter', TagHeaderFormatter::class); | ||
$resolver->setAllowedTypes('strict', 'bool'); | ||
|
||
$this->options = $resolver->resolve($options); | ||
$this->headerFormatter = $this->options['header_formatter']; | ||
} | ||
|
||
/** | ||
|
@@ -72,7 +79,7 @@ public function __construct(TagCapable $proxyClient, array $options = []) | |
*/ | ||
public function getTagsHeaderName() | ||
{ | ||
return $this->proxyClient->getTagsHeaderName(); | ||
return $this->headerFormatter->getTagsHeaderName(); | ||
} | ||
|
||
/** | ||
|
@@ -84,7 +91,7 @@ public function getTagsHeaderName() | |
*/ | ||
public function getTagsHeaderValue() | ||
{ | ||
return $this->proxyClient->getTagsHeaderValue($this->tags); | ||
return $this->headerFormatter->getTagsHeaderValue($this->tags); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.