Skip to content

Commit b00be1a

Browse files
authored
Merge pull request FriendsOfSymfony#454 from FriendsOfSymfony/support-autowiring
support symfony 4 autowiring and adjust doc to autowiring
2 parents ebbcaf6 + a7a2c0d commit b00be1a

File tree

17 files changed

+127
-85
lines changed

17 files changed

+127
-85
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
Changelog
22
=========
3+
4+
2.4.0 (unreleased)
5+
------------------
6+
7+
### Added
8+
9+
* Autowiring support for the services in this bundle:
10+
11+
- fos_http_cache.cache_manager => FOS\HttpCacheBundle\CacheManager
12+
- fos_http_cache.http.symfony_response_tagger => FOS\HttpCacheBundle\Http\SymfonyResponseTagger
13+
- fos_http_cache.event_listener.cache_control => FOS\HttpCacheBundle\EventListener\CacheControlListener
14+
- fos_http_cache.proxy_client.default => FOS\HttpCache\ProxyClient\ProxyClient
15+
16+
The old service names are still available, but using them directly is deprecated.
17+
318
2.3.1
419
-----
520

Resources/doc/features/helpers/flash-message.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ to only show the flash message once. Something along these lines:
5353
5454
function showFlash()
5555
{
56-
var cookie = getCookie("flashes"); // fos_http_cache.flash_message.name
56+
var cookie = getCookie("flashes"); // you can change the cookie name in fos_http_cache.flash_message.name configuration option
5757
5858
if (!cookie) {
5959
return;
@@ -73,7 +73,7 @@ to only show the flash message once. Something along these lines:
7373
// YOUR WORK: show flashes in your DOM...
7474
7575
// remove the cookie to not show flashes again
76-
// path is the fos_http_cache.flash_message.path value
76+
// the cookie path is controlled by the fos_http_cache.flash_message.path configuration option
7777
document.cookie = "flashes=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
7878
}
7979

Resources/doc/features/invalidation.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ To invalidate single paths, URLs and routes manually, use the
3535
``invalidatePath($path, $headers)`` and ``invalidateRoute($route, $params, $headers)`` methods on
3636
the cache manager::
3737

38-
$cacheManager = $container->get('fos_http_cache.cache_manager');
38+
use FOS\HttpCacheBundle\CacheManager;
39+
40+
$cacheManager = $container->get(CacheManager::class);
3941

4042
// Invalidate a path
4143
$cacheManager->invalidatePath('/users')->flush();

Resources/doc/features/symfony-http-cache.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The :ref:`FOSHttpCache Symfony Proxy Client documentation section <foshttpcache:
6969
explains how to adjust your bootstrap - you will need to do this in both
7070
``public/index.php`` and ``bin/console``.
7171

72-
Once your bootstrapping is adjusted, set ``fos_http_cache.proxy_client.symfony.use_kernel_dispatcher: true``.
72+
Once your bootstrapping is adjusted, set the configuration option
73+
``fos_http_cache.proxy_client.symfony.use_kernel_dispatcher: true``.
7374

7475
.. _Symfony HttpCache documentation: http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy

Resources/doc/features/tagging.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,26 @@ invalidation requests are flushed to the caching proxy
5252
Tagging and Invalidating from PHP Code
5353
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5454

55-
To add tags to responses, inject the ``ResponseTagger`` (service
56-
``fos_http_cache.http.symfony_response_tagger``) and use ``addTags($tags)`` to
57-
add tags that will be set on the response::
55+
To add tags to responses, use the ``ResponseTagger::addTags`` method::
5856

5957
use FOS\HttpCacheBundle\Http\SymfonyResponseTagger;
6058

6159
class NewsController
6260
{
63-
/**
64-
* @var SymfonyResponseTagger
65-
*/
66-
private $responseTagger;
67-
68-
public function articleAction($id)
61+
public function articleAction(string $id, SymfonyResponseTagger $responseTagger)
6962
{
70-
$this->responseTagger->addTags(array('news', 'news-' . $id));
63+
$responseTagger->addTags(array('news', 'news-' . $id));
7164

7265
// ...
7366
}
7467
}
7568

76-
To invalidate tags, inject the ``CacheManager`` (service ``fos_http_cache.cache_manager``)
77-
and call ``invalidateTags($tags)`` on it::
69+
.. versionadded:: 2.3.2
70+
Autowiring support has been added in version 2.3.2. In older versions of
71+
the bundle, you need to inject the service
72+
``fos_http_cache.http.symfony_response_tagger`` into your controller.
73+
74+
To invalidate tags, use the ``CacheManager::invalidateTags($tags)`` method::
7875

7976
use FOS\HttpCacheBundle\CacheManager;
8077

@@ -85,16 +82,21 @@ and call ``invalidateTags($tags)`` on it::
8582
*/
8683
private $cacheManager;
8784

88-
public function editAction($id)
85+
public function editAction(string $id, CacheManager $cacheManager)
8986
{
9087
// ...
9188

92-
$this->cacheManager->invalidateTags(array('news-' . $id));
89+
$cacheManager->invalidateTags(array('news-' . $id));
9390

9491
// ...
9592
}
9693
}
9794

95+
.. versionadded:: 2.3.2
96+
Autowiring support has been added in version 2.3.2. In older versions of
97+
the bundle, you need to inject the service ``fos_http_cache.cache_manager``
98+
in your controller.
99+
98100
Tagging from Twig Templates
99101
~~~~~~~~~~~~~~~~~~~~~~~~~~~
100102

Resources/doc/reference/cache-manager.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ By *refreshing* a piece of content, a fresh copy will be fetched right away.
1515
These terms are explained in more detail in
1616
:ref:`An Introduction to Cache Invalidation <foshttpcache:invalidation introduction>`.
1717

18+
The cache manager is available in the Symfony DI container using autowiring
19+
with the ``FOS\HttpCacheBundle\CacheManager`` class.
20+
21+
.. versionadded:: 2.3.2
22+
Autowiring support has been added in version 2.3.2. In older versions of
23+
the bundle, you need to explicitly use the service name
24+
``fos_http_cache.cache_manager``.
25+
1826
.. _cache manager invalidation:
1927

2028
``invalidatePath()``
@@ -38,12 +46,10 @@ Invalidate a URL::
3846

3947
Invalidate a route::
4048

41-
$cacheManager = $container->get('fos_http_cache.cache_manager');
4249
$cacheManager->invalidateRoute('user_details', array('id' => 123));
4350

4451
Invalidate a :ref:`regular expression <foshttpcache:invalidate regex>`::
4552

46-
$cacheManager = $container->get('fos_http_cache.cache_manager');
4753
$cacheManager->invalidateRegex('.*', 'image/png', array('example.com'));
4854

4955
The cache manager offers a fluent interface::
@@ -67,17 +73,14 @@ The cache manager offers a fluent interface::
6773

6874
Refresh a path::
6975

70-
$cacheManager = $container->get('fos_http_cache.cache_manager');
7176
$cacheManager->refreshPath('/users');
7277

7378
Refresh a URL::
7479

75-
$cacheManager = $container->get('fos_http_cache.cache_manager');
7680
$cacheManager->refreshPath('http://www.example.com/users');
7781

7882
Refresh a Route::
7983

80-
$cacheManager = $container->get('fos_http_cache.cache_manager');
8184
$cacheManager->refreshRoute('user_details', array('id' => 123));
8285

8386
.. _cache_manager_tags:

Resources/doc/reference/configuration/headers.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ directive. This is the default value for the cache control and there is no
134134
way to determine if it was manually set. If the full header is only
135135
``no-cache``, the whole cache control is overwritten.
136136

137-
You can prevent the cache control on specific requests by injecting the
138-
service ``fos_http_cache.event_listener.cache_control`` and calling
139-
``setSkip()`` on it. If this method is called, no cache rules are applied.
137+
You can prevent the cache control on specific controller actions by calling
138+
``FOS\HttpCacheBundle\EventListener\CacheControlListener::setSkip()``. When
139+
skip is set to ``true``, no cache rules are applied. This service can be
140+
autowired - in older versions of the bundle, use the service
141+
``fos_http_cache.event_listener.cache_control``.
140142

141143
``cache_control``
142144
"""""""""""""""""

Resources/doc/reference/configuration/proxy-client.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ the usual entry point for application interaction with the caching proxy.
88
You need to configure a client or define your own service for the cache manager
99
to work.
1010

11-
The proxy client is also directly available as a service
12-
(``fos_http_cache.proxy_client.default`` and ``fos_http_cache.proxy_client.varnish``
13-
, ``fos_http_cache.proxy_client.nginx`` or ``fos_http_cache.proxy_client.symfony``)
14-
that you can use directly.
11+
The proxy client is also directly available as a service. The default client
12+
can be autowired with the ``FOS\HttpCache\ProxyClient\ProxyClient`` type
13+
declaration or the service ``fos_http_cache.default_proxy_client``. Specific
14+
clients, if configured, are available as ``fos_http_cache.proxy_client.varnish``
15+
, ``fos_http_cache.proxy_client.nginx`` or ``fos_http_cache.proxy_client.symfony``).
1516

1617
If you need to adjust the proxy client, you can also configure the ``CacheManager``
1718
with a :ref:`custom proxy client <custom_proxy_client>` that you defined as a

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
},
6969
"extra": {
7070
"branch-alias": {
71-
"dev-master": "2.3.x-dev"
71+
"dev-master": "2.4.x-dev"
7272
}
7373
}
7474
}

0 commit comments

Comments
 (0)