Skip to content

Commit 7394591

Browse files
XWBdbu
authored andcommitted
Autoconfigure custom context providers (#462)
1 parent 8f17953 commit 7394591

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Changelog
66

77
### Added
88

9+
* Autoconfigure support for custom context providers.
10+
911
* Autowiring support for the services in this bundle:
1012

1113
- fos_http_cache.cache_manager => FOS\HttpCacheBundle\CacheManager

Resources/doc/reference/configuration/user-context.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ Custom providers need to:
231231
* implement the ``FOS\HttpCache\UserContext\ContextProvider`` interface
232232
* be tagged with ``fos_http_cache.user_context_provider``.
233233

234+
.. versionadded:: 2.4.0
235+
Autoconfigure support has been added in version 2.4.0 and works from
236+
Symfony 3.3 and above. If autoconfigure is enabled, your custom provider
237+
will be tagged automatically, with a default priority of 0. For older
238+
versions, or if autoconfigure is disabled, or you want to override the
239+
priority, check out the section below.
240+
234241
If you need context providers to run in a specific order, you can specify the
235242
optional ``priority`` parameter for the tag. The higher the priority, the
236243
earlier a context provider is executed. The build-in provider has a priority

src/FOSHttpCacheBundle.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FOS\HttpCacheBundle;
1313

14+
use FOS\HttpCache\UserContext\ContextProvider;
1415
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
1516
use FOS\HttpCacheBundle\DependencyInjection\Compiler\LoggerPass;
1617
use FOS\HttpCacheBundle\DependencyInjection\Compiler\SessionListenerRemovePass;
@@ -35,6 +36,13 @@ public function build(ContainerBuilder $container)
3536
) {
3637
$container->addCompilerPass(new SessionListenerRemovePass());
3738
}
39+
40+
// Symfony 3.3 and higher
41+
if (method_exists($container, 'registerForAutoconfiguration')) {
42+
$container
43+
->registerForAutoconfiguration(ContextProvider::class)
44+
->addTag('fos_http_cache.user_context_provider');
45+
}
3846
}
3947

4048
public function registerCommands(Application $application)

0 commit comments

Comments
 (0)