-
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 #541 from FriendsOfSymfony/header-parser
add tag header parser to cleanly respect custom glue
- Loading branch information
Showing
8 changed files
with
107 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* | ||
* @author Yanick Witschi <[email protected]> | ||
*/ | ||
class CommaSeparatedTagHeaderFormatter implements TagHeaderFormatter | ||
class CommaSeparatedTagHeaderFormatter implements TagHeaderFormatter, TagHeaderParser | ||
{ | ||
/** | ||
* @var string | ||
|
@@ -53,4 +53,15 @@ public function getTagsHeaderValue(array $tags) | |
{ | ||
return implode($this->glue, $tags); | ||
} | ||
|
||
public function parseTagsHeaderValue($tags): array | ||
{ | ||
if (is_string($tags)) { | ||
$tags = [$tags]; | ||
} | ||
|
||
return array_merge(...array_map(function ($tagsFragment) { | ||
return explode($this->glue, $tagsFragment); | ||
}, $tags)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
* | ||
* @author Yanick Witschi <[email protected]> | ||
*/ | ||
class MaxHeaderValueLengthFormatter implements TagHeaderFormatter | ||
class MaxHeaderValueLengthFormatter implements TagHeaderFormatter, TagHeaderParser | ||
{ | ||
/** | ||
* @var TagHeaderFormatter | ||
|
@@ -83,6 +83,15 @@ public function getTagsHeaderValue(array $tags) | |
return $newValues; | ||
} | ||
|
||
public function parseTagsHeaderValue($tags): array | ||
{ | ||
if ($this->inner instanceof TagHeaderParser) { | ||
return $this->inner->parseTagsHeaderValue($tags); | ||
} | ||
|
||
throw new \BadMethodCallException('The inner formatter does not implement '.TagHeaderParser::class); | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* | ||
|
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,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSHttpCache package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\HttpCache\TagHeaderFormatter; | ||
|
||
/** | ||
* The TagHeaderParser can convert the tag header into an array of tags. | ||
* | ||
* @author David Buchmann <[email protected]> | ||
*/ | ||
interface TagHeaderParser | ||
{ | ||
/** | ||
* Split the tag header into a list of tags. | ||
* | ||
* @param string|string[] $tags | ||
* | ||
* @return string[] | ||
*/ | ||
public function parseTagsHeaderValue($tags): array; | ||
} |
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