|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSHttpCacheBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace FOS\HttpCacheBundle; |
|
13
|
|
|
|
|
14
|
|
|
use FOS\HttpCache\CacheInvalidator; |
|
15
|
|
|
use FOS\HttpCache\ProxyClient\ProxyClientInterface; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
17
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The CacheManager is a CacheInvalidator but adds symfony Route support and |
|
21
|
|
|
* response tagging to the framework agnostic FOS\HttpCache\CacheInvalidator. |
|
22
|
|
|
* |
|
23
|
|
|
* @author David de Boer <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class CacheManager extends CacheInvalidator |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var UrlGeneratorInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $urlGenerator; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* What type of urls to generate. |
|
34
|
|
|
* |
|
35
|
|
|
* @var bool|string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $generateUrlType = UrlGeneratorInterface::ABSOLUTE_PATH; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param ProxyClientInterface $cache HTTP cache proxy client |
|
43
|
|
|
* @param UrlGeneratorInterface $urlGenerator Symfony route generator |
|
44
|
|
|
*/ |
|
45
|
7 |
|
public function __construct(ProxyClientInterface $cache, UrlGeneratorInterface $urlGenerator) |
|
46
|
|
|
{ |
|
47
|
7 |
|
parent::__construct($cache); |
|
48
|
7 |
|
$this->urlGenerator = $urlGenerator; |
|
49
|
7 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Set what type of URLs to generate. |
|
53
|
|
|
* |
|
54
|
|
|
* @param bool|string $generateUrlType One of the constants in UrlGeneratorInterface |
|
55
|
|
|
*/ |
|
56
|
7 |
|
public function setGenerateUrlType($generateUrlType) |
|
57
|
|
|
{ |
|
58
|
7 |
|
$this->generateUrlType = $generateUrlType; |
|
59
|
7 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Invalidate a route. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $name Route name |
|
65
|
|
|
* @param array $parameters Route parameters (optional) |
|
66
|
|
|
* @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
|
67
|
|
|
* |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
public function invalidateRoute($name, array $parameters = [], array $headers = []) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->invalidatePath($this->urlGenerator->generate($name, $parameters, $this->generateUrlType), $headers); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Refresh a route. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $route Route name |
|
81
|
|
|
* @param array $parameters Route parameters (optional) |
|
82
|
|
|
* @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
|
83
|
|
|
* |
|
84
|
|
|
* @return $this |
|
85
|
|
|
*/ |
|
86
|
|
|
public function refreshRoute($route, array $parameters = [], array $headers = []) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->refreshPath($this->urlGenerator->generate($route, $parameters, $this->generateUrlType), $headers); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: