88
99class TmdbExtension extends \Twig_Extension
1010{
11+ /**
12+ * @var ImageHelper|null
13+ */
1114 private $ helper ;
1215
16+ /**
17+ * @var Client
18+ */
1319 private $ client ;
1420
15- private $ configuration ;
16-
1721 public function __construct (Client $ client )
1822 {
1923 $ this ->client = $ client ;
20-
21- $ repository = new ConfigurationRepository ($ client );
22- $ config = $ repository ->load ();
23-
24- $ this ->helper = new ImageHelper ($ config );
2524 }
2625
2726 public function getFilters ()
@@ -34,12 +33,12 @@ public function getFilters()
3433
3534 public function getHtml ($ image , $ size = 'original ' , $ width = null , $ height = null )
3635 {
37- return $ this ->helper ->getHtml ($ image , $ size , $ width , $ height );
36+ return $ this ->getHelper () ->getHtml ($ image , $ size , $ width , $ height );
3837 }
3938
4039 public function getUrl ($ image )
4140 {
42- return $ this ->helper ->getUrl ($ image );
41+ return $ this ->getHelper () ->getUrl ($ image );
4342 }
4443
4544 public function getName ()
@@ -66,25 +65,6 @@ public function getClient()
6665 return $ this ->client ;
6766 }
6867
69- /**
70- * @param mixed $configuration
71- * @return $this
72- */
73- public function setConfiguration ($ configuration )
74- {
75- $ this ->configuration = $ configuration ;
76-
77- return $ this ;
78- }
79-
80- /**
81- * @return mixed
82- */
83- public function getConfiguration ()
84- {
85- return $ this ->configuration ;
86- }
87-
8868 /**
8969 * @param ImageHelper $helper
9070 * @return $this
@@ -101,6 +81,15 @@ public function setHelper($helper)
10181 */
10282 public function getHelper ()
10383 {
84+ if ($ this ->helper ) {
85+ return $ this ->helper ;
86+ }
87+
88+ $ repository = new ConfigurationRepository ($ this ->client );
89+ $ config = $ repository ->load ();
90+
91+ $ this ->helper = new ImageHelper ($ config );
92+
10493 return $ this ->helper ;
10594 }
10695}
0 commit comments