File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1111
1212namespace Symfony \Bundle \FrameworkBundle \CacheWarmer ;
1313
14+ use Symfony \Component \DependencyInjection \ContainerInterface ;
1415use Symfony \Component \HttpKernel \CacheWarmer \CacheWarmerInterface ;
1516use Symfony \Component \HttpKernel \CacheWarmer \WarmableInterface ;
1617use Symfony \Component \Translation \TranslatorInterface ;
2223 */
2324class TranslationsCacheWarmer implements CacheWarmerInterface
2425{
26+ private $ container ;
2527 private $ translator ;
2628
27- public function __construct (TranslatorInterface $ translator )
29+ /**
30+ * TranslationsCacheWarmer constructor.
31+ *
32+ * @param ContainerInterface|TranslatorInterface $container
33+ */
34+ public function __construct ($ container )
2835 {
29- $ this ->translator = $ translator ;
36+ // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
37+ if ($ container instanceof ContainerInterface) {
38+ $ this ->container = $ container ;
39+ } elseif ($ container instanceof TranslatorInterface) {
40+ $ this ->translator = $ container ;
41+ } else {
42+ throw new \InvalidArgumentException (sprintf ('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Translation\TranslatorInterface as first argument. ' , __CLASS__ ));
43+ }
3044 }
3145
3246 /**
3347 * {@inheritdoc}
3448 */
3549 public function warmUp ($ cacheDir )
3650 {
51+ if (null === $ this ->translator ) {
52+ $ this ->translator = $ this ->container ->get ('translator ' );
53+ }
54+
3755 if ($ this ->translator instanceof WarmableInterface) {
3856 $ this ->translator ->warmUp ($ cacheDir );
3957 }
Original file line number Diff line number Diff line change 159159 <service id =" translation.writer" class =" %translation.writer.class%" />
160160
161161 <service id =" translation.warmer" class =" Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer" public =" false" >
162- <argument type =" service" id =" translator " />
162+ <argument type =" service" id =" service_container " />
163163 <tag name =" kernel.cache_warmer" />
164164 </service >
165165 </services >
You can’t perform that action at this time.
0 commit comments