44
55use  Jm \ABBundle \Entity \Template ;
66use  Jm \ABBundle \Entity \TemplateManager ;
7- use  Symfony \Component \HttpFoundation \ Request ;
7+ use  Symfony \Component \DependencyInjection \ ContainerInterface ;
88
99class  TemplateLoader implements  \Twig_LoaderInterface
1010{
11-  private  $ manager ;
12-  private  $ request ;
13-  private  $ variationParameter ;
14- 
15-  public  function  __construct (TemplateManager   $ manager , $ variationParameter )
11+  /** 
12+  * @var ContainerInterface 
13+  */ 
14+  private  $ container ; 
15+  
16+  public  function  __construct (ContainerInterface   $ container )
1617 {
17-  $ this  ->manager  = $ manager ;
18-  $ this  ->request  = Request::createFromGlobals ();
19-  $ this  ->variationParameter  = $ variationParameter ;
18+  $ this  ->container  = $ container ;
2019 }
2120
2221 /** 
@@ -54,7 +53,7 @@ public function getCacheKey($fullName)
5453 return 
5554 __CLASS__ 
5655 . '# '  . $ name
57-  . '# '  . $ this  ->request ->get ($ this  ->variationParameter ) === null  ? 'A '  : 'B ' 
56+  . '# '  . $ this  ->container -> get ( ' request ' ) ->get ($ this  ->container -> getParameter ( ' jm_ab.variation_parameter ' ) ) === null  ? 'A '  : 'B ' 
5857 // force reload even if Twig has autoReload to false 
5958 . '# '  . $ template ->getUpdatedAt ()->getTimestamp ()
6059 ;
@@ -96,7 +95,7 @@ private function parse($name)
9695
9796 private  function  getTemplate ($ name )
9897 {
99-  if  (!$ template  = $ this  ->manager ->getTemplate ($ name )) {
98+  if  (!$ template  = $ this  ->container -> get ( ' jm_ab.template_manager ' ) ->getTemplate ($ name )) {
10099 throw  new  \Twig_Error_Loader (sprintf ("Unable to find template %s " , $ name ));
101100 }
102101
@@ -106,7 +105,7 @@ private function getTemplate($name)
106105 private  function  getTemplateVariation (Template   $ template )
107106 {
108107 $ content  = $ template ->getBody ();
109-  if  (null  !== $ this  ->request ->get ($ this  ->variationParameter ) && $ this  ->isValidBody ($ template ->getVariationBody ())) {
108+  if  (null  !== $ this  ->container -> get ( ' request ' ) ->get ($ this  ->container -> getParameter ( ' jm_ab.variation_parameter ' ) ) && $ this  ->isValidBody ($ template ->getVariationBody ())) {
110109 $ content  = $ template ->getVariationBody ();
111110 }
112111
0 commit comments