8
8
9
9
class TmdbExtension extends \Twig_Extension
10
10
{
11
+ /**
12
+ * @var ImageHelper|null
13
+ */
11
14
private $ helper ;
12
15
16
+ /**
17
+ * @var Client
18
+ */
13
19
private $ client ;
14
20
15
- private $ configuration ;
16
-
17
21
public function __construct (Client $ client )
18
22
{
19
23
$ this ->client = $ client ;
20
-
21
- $ repository = new ConfigurationRepository ($ client );
22
- $ config = $ repository ->load ();
23
-
24
- $ this ->helper = new ImageHelper ($ config );
25
24
}
26
25
27
26
public function getFilters ()
@@ -34,12 +33,12 @@ public function getFilters()
34
33
35
34
public function getHtml ($ image , $ size = 'original ' , $ width = null , $ height = null )
36
35
{
37
- return $ this ->helper ->getHtml ($ image , $ size , $ width , $ height );
36
+ return $ this ->getHelper () ->getHtml ($ image , $ size , $ width , $ height );
38
37
}
39
38
40
39
public function getUrl ($ image )
41
40
{
42
- return $ this ->helper ->getUrl ($ image );
41
+ return $ this ->getHelper () ->getUrl ($ image );
43
42
}
44
43
45
44
public function getName ()
@@ -66,25 +65,6 @@ public function getClient()
66
65
return $ this ->client ;
67
66
}
68
67
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
-
88
68
/**
89
69
* @param ImageHelper $helper
90
70
* @return $this
@@ -101,6 +81,15 @@ public function setHelper($helper)
101
81
*/
102
82
public function getHelper ()
103
83
{
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
+
104
93
return $ this ->helper ;
105
94
}
106
95
}
0 commit comments