11<?php
22namespace Slim \HttpCache ;
33
4+ use InvalidArgumentException ;
45use Pimple \Container ;
56use Pimple \ServiceProviderInterface ;
67use Psr \Http \Message \ResponseInterface ;
@@ -25,11 +26,12 @@ public function register(Container $container)
2526 * @param null|int|string $maxAge Maximum cache age (integer timestamp or datetime string)
2627 *
2728 * @return ResponseInterface A new PSR7 response object with `Cache-Control` header
29+ * @throws InvalidArgumentException if the cache-control type is invalid
2830 */
2931 public function allowCache (ResponseInterface $ response , $ type = 'private ' , $ maxAge = null )
3032 {
3133 if (!in_array ($ type , ['private ' , 'public ' ])) {
32- throw new \ InvalidArgumentException ('Invalid Cache-Control type. Must be "public" or "private". ' );
34+ throw new InvalidArgumentException ('Invalid Cache-Control type. Must be "public" or "private". ' );
3335 }
3436 $ headerValue = $ type ;
3537 if ($ maxAge ) {
@@ -61,13 +63,14 @@ public function denyCache(ResponseInterface $response)
6163 * @param int|string $time A UNIX timestamp or a valid `strtotime()` string
6264 *
6365 * @return ResponseInterface A new PSR7 response object with `Expires` header
66+ * @throws InvalidArgumentException if the expiration date cannot be parsed
6467 */
6568 public function withExpires (ResponseInterface $ response , $ time )
6669 {
6770 if (!is_integer ($ time )) {
6871 $ time = strtotime ($ time );
6972 if ($ time === false ) {
70- throw new \ InvalidArgumentException ('Expiration value could not be parsed with `strtotime()`. ' );
73+ throw new InvalidArgumentException ('Expiration value could not be parsed with `strtotime()`. ' );
7174 }
7275 }
7376
@@ -82,11 +85,12 @@ public function withExpires(ResponseInterface $response, $time)
8285 * @param string $type ETag type: "strong" or "weak"
8386 *
8487 * @return ResponseInterface A new PSR7 response object with `ETag` header
88+ * @throws InvalidArgumentException if the etag type is invalid
8589 */
8690 public function withEtag (ResponseInterface $ response , $ value , $ type = 'strong ' )
8791 {
8892 if (!in_array ($ type , ['strong ' , 'weak ' ])) {
89- throw new \ InvalidArgumentException ('Invalid etag type. Must be "strong" or "weak". ' );
93+ throw new InvalidArgumentException ('Invalid etag type. Must be "strong" or "weak". ' );
9094 }
9195 $ value = '" ' . $ value . '" ' ;
9296 if ($ type === 'weak ' ) {
@@ -103,13 +107,14 @@ public function withEtag(ResponseInterface $response, $value, $type = 'strong')
103107 * @param int|string $time A UNIX timestamp or a valid `strtotime()` string
104108 *
105109 * @return ResponseInterface A new PSR7 response object with `Last-Modified` header
110+ * @throws InvalidArgumentException if the last modified date cannot be parsed
106111 */
107112 public function withLastModified (ResponseInterface $ response , $ time )
108113 {
109114 if (!is_integer ($ time )) {
110115 $ time = strtotime ($ time );
111116 if ($ time === false ) {
112- throw new \ InvalidArgumentException ('Last Modified value could not be parsed with `strtotime()`. ' );
117+ throw new InvalidArgumentException ('Last Modified value could not be parsed with `strtotime()`. ' );
113118 }
114119 }
115120
0 commit comments