22
33namespace Padam87 \RasterizeBundle ;
44
5+ use Symfony \Component \Process \InputStream ;
56use Symfony \Component \Process \Process ;
67use Symfony \Component \Process \ProcessBuilder ;
7- use Symfony \Component \Routing \RequestContext ;
88
99class ConfigHelper
1010{
@@ -14,195 +14,37 @@ class ConfigHelper
1414 protected $ config ;
1515
1616 /**
17- * @var string
17+ * @param array $config
1818 */
19- protected $ rootDir ;
20-
21- /**
22- * @var RequestContext
23- */
24- protected $ context ;
25-
26- /**
27- * @var string
28- */
29- protected $ contextBaseUrl ;
30-
31- /**
32- * @param array $config
33- * @param string $rootDir
34- * @param RequestContext $context
35- * @param string $contextBaseUrl
36- */
37- public function __construct (array $ config , $ rootDir , RequestContext $ context , $ contextBaseUrl = "" )
19+ public function __construct (array $ config )
3820 {
3921 $ this ->config = $ config ;
40- $ this ->rootDir = $ rootDir ;
41- $ this ->context = $ context ;
42- $ this ->contextBaseUrl = $ contextBaseUrl ;
4322 }
4423
4524 /**
46- * @return array
47- */
48- public function getConfig ()
49- {
50- return $ this ->config ;
51- }
52-
53- /**
54- * @param array $config
55- *
56- * @return $this
57- */
58- public function setConfig ($ config )
59- {
60- $ this ->config = $ config ;
61-
62- return $ this ;
63- }
64-
65- /**
66- * @return string
67- */
68- public function getRootDir ()
69- {
70- return $ this ->rootDir ;
71- }
72-
73- /**
74- * @param string $rootDir
75- *
76- * @return $this
77- */
78- public function setRootDir ($ rootDir )
79- {
80- $ this ->rootDir = $ rootDir ;
81-
82- return $ this ;
83- }
84-
85- /**
86- * @return RequestContext
87- */
88- public function getContext ()
89- {
90- return $ this ->context ;
91- }
92-
93- /**
94- * @param RequestContext $context
95- *
96- * @return $this
97- */
98- public function setContext (RequestContext $ context )
99- {
100- $ this ->context = $ context ;
101-
102- return $ this ;
103- }
104-
105- /**
106- * @return string
107- */
108- public function getContextBaseUrl ()
109- {
110- return $ this ->contextBaseUrl ;
111- }
112-
113- /**
114- * @param string $contextBaseUrl
115- *
116- * @return $this
117- */
118- public function setContextBaseUrl ($ contextBaseUrl )
119- {
120- $ this ->contextBaseUrl = $ contextBaseUrl ;
121-
122- return $ this ;
123- }
124-
125- /**
126- * @param string $url
127- * @param string $uniqueId
128- * @param array $arguments
25+ * @param InputStream $input
26+ * @param array $arguments
12927 *
13028 * @return Process
13129 */
132- public function buildProcess ($ url , $ uniqueId , $ arguments = array ())
30+ public function buildProcess ($ input , $ arguments = array ())
13331 {
134- $ script = $ this ->getWebDir () . DIRECTORY_SEPARATOR . $ this ->config ['script ' ];
135- $ output = $ this ->getOutputFilePath ($ uniqueId );
136-
13732 $ builder = new ProcessBuilder ();
138-
13933 $ builder
14034 ->setPrefix ($ this ->config ['phantomjs ' ]['callable ' ])
14135 ->setArguments (
14236 array_merge (
14337 $ this ->processPhantomjsOptions (),
144- array ( $ script, $ url , $ output ) ,
38+ [ $ this -> config [ ' script ' ]] ,
14539 array_values (array_merge ($ this ->config ['arguments ' ], $ arguments ))
14640 )
14741 )
42+ ->setInput ($ input )
14843 ;
14944
15045 return $ builder ->getProcess ();
15146 }
15247
153- /**
154- * @param string $uniqueId
155- *
156- * @return string
157- */
158- public function getInputFilePath ($ uniqueId )
159- {
160- return $ this ->getTempDir () . DIRECTORY_SEPARATOR . $ uniqueId . '.html ' ;
161- }
162-
163- /**
164- * @param string $uniqueId
165- *
166- * @return string
167- */
168- public function getOutputFilePath ($ uniqueId )
169- {
170- return $ this ->getTempDir () . DIRECTORY_SEPARATOR . $ uniqueId . '. ' . $ this ->config ['arguments ' ]['format ' ];
171- }
172-
173- /**
174- * @param $uniqueId
175- *
176- * @return string
177- */
178- public function getOutputFileUrl ($ uniqueId )
179- {
180- return sprintf (
181- "%s://%s%s%s/%s.html " ,
182- $ this ->context ->getScheme (),
183- $ this ->context ->getHost (),
184- $ this ->contextBaseUrl === "" ? $ this ->context ->getBaseUrl () : $ this ->contextBaseUrl ,
185- $ this ->config ['temp_dir ' ],
186- $ uniqueId
187- );
188- }
189-
190- /**
191- * @return string
192- */
193- protected function getTempDir ()
194- {
195- return $ this ->getWebDir () . $ this ->config ['temp_dir ' ];
196- }
197-
198- /**
199- * @return string
200- */
201- protected function getWebDir ()
202- {
203- return $ this ->rootDir . $ this ->config ['web_dir ' ];
204- }
205-
20648 /**
20749 * @return array
20850 */
0 commit comments