@@ -73,22 +73,26 @@ public function generateConfig(HeaderInterface $header): void
7373 $ this ->makePathForFiles ([$ this ->pidFile , $ this ->configFile ]);
7474 $ this ->touchFile ($ this ->pidFile );
7575
76- $ data = $ this ->templates ->render ('nginx_default.conf ' , [
77- 'serverRoot ' => realpath ($ this ->getServerRoot ()),
78- 'serverIndex ' => $ this ->configuration ->get ('server.index ' ),
79- 'serverPort ' => $ this ->configuration ->get ('server.port ' ),
80- 'serverHost ' => $ this ->configuration ->get ('server.host ' ),
81- 'prerenderEnabled ' => $ this ->configuration ->get ('server.prerender.enabled ' ),
82- 'prerenderUrl ' => $ this ->getHostWithoutTrailingSlash ('server.prerender.url ' ),
83- 'prerenderHeaders ' => $ this ->configuration ->get ('server.prerender.headers ' , []),
84- 'prerenderResolver ' => $ this ->configuration ->get ('server.prerender.resolver ' , false ),
85- 'prerenderHost ' => $ this ->getHostWithoutTrailingSlash ('server.prerender.host ' ),
86- 'headers ' => $ header ->convert ($ this ->configuration ),
87- 'connProcMethod ' => $ this ->getConnectionProcessingMethod (),
88- 'pidLocation ' => $ this ->pidFile ,
89- 'moduleBrotliInstalled ' => $ this ->moduleBrotliInstalled ,
90- 'platformSupportsAsyncIo ' => $ this ->platformSupportsAsyncIo ,
91- ]);
76+ $ data = $ this ->templates ->render (
77+ 'nginx_default.conf ' ,
78+ [
79+ 'serverRoot ' => realpath ($ this ->getServerRoot ()),
80+ 'serverIndex ' => $ this ->configuration ->get ('server.index ' ),
81+ 'serverPort ' => $ this ->configuration ->get ('server.port ' ),
82+ 'serverHost ' => $ this ->configuration ->get ('server.host ' ),
83+ 'prerenderEnabled ' => $ this ->configuration ->get ('server.prerender.enabled ' ),
84+ 'prerenderCacheTTL ' => $ this ->configuration ->get ('server.prerender.cache_ttl ' ),
85+ 'CDNUrl ' => $ this ->getHostWithoutTrailingSlash ('server.prerender.cdn_url ' ),
86+ 'CDNPath ' => $ this ->configuration ->get ('server.prerender.cdn_path ' ),
87+ 'prerenderHeaders ' => $ this ->configuration ->get ('server.prerender.headers ' , []),
88+ 'prerenderResolver ' => $ this ->configuration ->get ('server.prerender.resolver ' , false ),
89+ 'headers ' => $ header ->convert ($ this ->configuration ),
90+ 'connProcMethod ' => $ this ->getConnectionProcessingMethod (),
91+ 'pidLocation ' => $ this ->pidFile ,
92+ 'moduleBrotliInstalled ' => $ this ->moduleBrotliInstalled ,
93+ 'platformSupportsAsyncIo ' => $ this ->platformSupportsAsyncIo ,
94+ ]
95+ );
9296
9397 file_put_contents ($ this ->configFile , $ data );
9498 }
@@ -103,18 +107,23 @@ public function checkConfig(): void
103107 */
104108 public function start (): void
105109 {
106- $ this ->runProcess (['nginx ' , '-c ' , $ this ->configFile ], function () {
107- $ this ->logger ->info (sprintf (
108- 'Server started at: %s:%d ' ,
109- $ this ->configuration ->get ('server.host ' ),
110- $ this ->configuration ->get ('server.port ' )
111- ));
112- });
110+ $ this ->runProcess (
111+ ['nginx ' , '-c ' , $ this ->configFile ],
112+ function () {
113+ $ this ->logger ->info (
114+ sprintf (
115+ 'Server started at: %s:%d ' ,
116+ $ this ->configuration ->get ('server.host ' ),
117+ $ this ->configuration ->get ('server.port ' )
118+ )
119+ );
120+ }
121+ );
113122 }
114123
115124 public function reload (): void
116125 {
117- if (! file_exists ($ this ->pidFile )) {
126+ if ( ! file_exists ($ this ->pidFile )) {
118127 throw new LogicException ('Can \'t reload server. Pid file not found. ' );
119128 }
120129
@@ -136,6 +145,7 @@ public function stop(): void
136145
137146 /**
138147 * @param string $key
148+ *
139149 * @return bool|string
140150 */
141151 private function getHostWithoutTrailingSlash (string $ key )
@@ -155,10 +165,10 @@ private function getConnectionProcessingMethod(): string
155165 {
156166 switch (PHP_OS_FAMILY ) {
157167 case 'Linux ' :
158- return 'epoll ' ;
168+ return 'epoll ' ;
159169 case 'Darwin ' :
160170 case 'BSD ' :
161- return 'kqueue ' ;
171+ return 'kqueue ' ;
162172 default :
163173 return 'poll ' ;
164174 }
@@ -169,39 +179,43 @@ private function getConnectionProcessingMethod(): string
169179 */
170180 private function checkIfPrerenderUrlIsAvailable (): void
171181 {
172- if (! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
182+ if ( ! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
173183 $ this ->logger ->info ('Prerender is not enabled, skip check. ' );
184+
174185 return ;
175186 }
176187
177- $ url = $ this ->configuration ->get ('server.prerender.url ' , false );
188+ $ url = $ this ->configuration ->get ('server.prerender.cdn_url ' , false );
178189
179- if (! $ url ) {
180- throw new InvalidArgumentException ('Prerender URL not set. Check server.prerender.url config key. ' );
190+ if ( ! $ url ) {
191+ throw new InvalidArgumentException ('Prerender CDN URL not set. Check server.prerender.cdn_url config key. ' );
181192 }
182193
183194 $ url = (string ) parse_url ($ url , PHP_URL_HOST );
184195
185196 if (strlen ($ url ) < 1 ) {
186- throw new InvalidArgumentException ('Prerender URL is invalid. Check server.prerender.url config key. ' );
197+ throw new InvalidArgumentException (
198+ 'Prerender CDN URL is invalid. Check server.prerender.cdn_url config key. '
199+ );
187200 }
188201
189- $ this ->logger ->info ('Ping prerender url... ' );
202+ $ this ->logger ->info ('Ping prerender cdn url... ' );
190203
191- $ ping = new Ping ($ url );
204+ $ ping = new Ping ($ url );
192205 $ latency = $ ping ->ping ('fsockopen ' );
193206
194207 if ($ latency !== false ) {
195- $ this ->logger ->info ('Prerender url is available. ' );
208+ $ this ->logger ->info ('Prerender cdn url is available. ' );
209+
196210 return ;
197211 }
198212
199- $ this ->logger ->warning ('Prerender url could not be reached: ' . $ url );
213+ $ this ->logger ->warning ('Prerender cdn url could not be reached: ' . $ url );
200214 }
201215
202216 private function checkIfPrerenderHostIsNotEmpty (): void
203217 {
204- if (! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
218+ if ( ! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
205219 return ;
206220 }
207221
@@ -215,8 +229,10 @@ private function checkIfPrerenderHostIsNotEmpty(): void
215229
216230 $ valid = (bool ) parse_url ($ host );
217231
218- if (!$ valid ) {
219- throw new InvalidArgumentException ('Prerender host is invalid (can \'t parse a url). Check server.prerender.host config key. ' );
232+ if ( ! $ valid ) {
233+ throw new InvalidArgumentException (
234+ 'Prerender host is invalid (can \'t parse a url). Check server.prerender.host config key. '
235+ );
220236 }
221237 }
222238
0 commit comments