1 | <?php |
||
27 | class ResponseTagger |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $options; |
||
34 | |||
35 | /** |
||
36 | * @var TagsInterface |
||
37 | */ |
||
38 | private $client; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | private $tags = []; |
||
44 | |||
45 | /** |
||
46 | * Constructor |
||
47 | * |
||
48 | * @param TagsInterface $client |
||
49 | * @param array $options supported options: |
||
50 | * - strict (bool) Default: false. If set to true, throws exception when adding empty tags. |
||
51 | */ |
||
52 | 4 | public function __construct(TagsInterface $client, array $options = array()) |
|
65 | |||
66 | /** |
||
67 | * Get the HTTP header name that will hold cache tags. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 1 | public function getTagsHeaderName() |
|
75 | |||
76 | /** |
||
77 | * Get the value for the HTTP tag header. |
||
78 | * |
||
79 | * This concatenates all tags and ensures correct encoding. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | 3 | public function getTagsHeaderValue() |
|
87 | |||
88 | /** |
||
89 | * Check whether the tag handler has any tags to set on the response. |
||
90 | * |
||
91 | * @return bool True if this handler will set at least one tag. |
||
92 | */ |
||
93 | 2 | public function hasTags() |
|
97 | |||
98 | /** |
||
99 | * Add tags to be set on the response. |
||
100 | * |
||
101 | * This must be called before any HTTP response is sent to the client. |
||
102 | * |
||
103 | * @param array $tags List of tags to add. |
||
104 | * |
||
105 | * @throws InvalidTagException |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 4 | public function addTags(array $tags) |
|
121 | |||
122 | /** |
||
123 | * Set tags on a response |
||
124 | * |
||
125 | * @param ResponseInterface $response Original response |
||
126 | * @param bool $replace Whether to replace the current tags |
||
127 | * on the response |
||
128 | * |
||
129 | * @return ResponseInterface Tagged response |
||
130 | */ |
||
131 | 1 | public function tagResponse(ResponseInterface $response, $replace = false) |
|
139 | } |
||
140 |