@@ -222,24 +222,29 @@ public function set(String $key, String $value, int $ttl = 0): bool
222
222
}
223
223
}
224
224
$ string = $ ttl . '| ' . $ value ;
225
- return file_put_contents ($ filename , $ string, LOCK_EX ) !== false ;
225
+ return $ this -> filePutContents ($ filename , $ string ) !== false ;
226
226
}
227
227
228
- private function fileGetContents ( $ path )
228
+ private function filePutContents ( $ filename , $ string )
229
229
{
230
- $ f = fopen ($ path , 'r ' );
231
- if ($ f === false ) {
230
+ return file_put_contents ($ filename , $ string , LOCK_EX );
231
+ }
232
+
233
+ private function fileGetContents ($ filename )
234
+ {
235
+ $ file = fopen ($ filename , 'r ' );
236
+ if ($ file === false ) {
232
237
return false ;
233
238
}
234
- $ locked = flock ($ f , LOCK_SH );
235
- if (!$ locked ) {
236
- fclose ($ f );
239
+ $ lock = flock ($ file , LOCK_SH );
240
+ if (!$ lock ) {
241
+ fclose ($ file );
237
242
return false ;
238
243
}
239
- $ data = file_get_contents ($ path );
240
- flock ($ f , LOCK_UN );
241
- fclose ($ f );
242
- return $ data ;
244
+ $ string = file_get_contents ($ filename );
245
+ flock ($ file , LOCK_UN );
246
+ fclose ($ file );
247
+ return $ string ;
243
248
}
244
249
245
250
private function getString ($ filename ): String
@@ -4482,14 +4487,16 @@ class Request
4482
4487
private $ params ;
4483
4488
private $ body ;
4484
4489
private $ headers ;
4490
+ private $ highPerformance ;
4485
4491
4486
- public function __construct (String $ method = null , String $ path = null , String $ query = null , array $ headers = null , String $ body = null )
4492
+ public function __construct (String $ method = null , String $ path = null , String $ query = null , array $ headers = null , String $ body = null , bool $ highPerformance = true )
4487
4493
{
4488
4494
$ this ->parseMethod ($ method );
4489
4495
$ this ->parsePath ($ path );
4490
4496
$ this ->parseParams ($ query );
4491
4497
$ this ->parseHeaders ($ headers );
4492
4498
$ this ->parseBody ($ body );
4499
+ $ this ->highPerformance = $ highPerformance ;
4493
4500
}
4494
4501
4495
4502
private function parseMethod (String $ method = null )
@@ -4534,10 +4541,12 @@ private function parseHeaders(array $headers = null)
4534
4541
{
4535
4542
if (!$ headers ) {
4536
4543
$ headers = array ();
4537
- foreach ($ _SERVER as $ name => $ value ) {
4538
- if (substr ($ name , 0 , 5 ) == 'HTTP_ ' ) {
4539
- $ key = str_replace (' ' , '- ' , ucwords (strtolower (str_replace ('_ ' , ' ' , substr ($ name , 5 )))));
4540
- $ headers [$ key ] = $ value ;
4544
+ if (!$ this ->highPerformance ) {
4545
+ foreach ($ _SERVER as $ name => $ value ) {
4546
+ if (substr ($ name , 0 , 5 ) == 'HTTP_ ' ) {
4547
+ $ key = str_replace (' ' , '- ' , ucwords (strtolower (str_replace ('_ ' , ' ' , substr ($ name , 5 )))));
4548
+ $ headers [$ key ] = $ value ;
4549
+ }
4541
4550
}
4542
4551
}
4543
4552
}
@@ -4608,6 +4617,12 @@ public function getHeader(String $key): String
4608
4617
if (isset ($ this ->headers [$ key ])) {
4609
4618
return $ this ->headers [$ key ];
4610
4619
}
4620
+ if ($ this ->highPerformance ) {
4621
+ $ serverKey = 'HTTP_ ' . strtoupper (str_replace ('_ ' , '- ' , $ key ));
4622
+ if (isset ($ _SERVER [$ serverKey ])) {
4623
+ return $ _SERVER [$ serverKey ];
4624
+ }
4625
+ }
4611
4626
return '' ;
4612
4627
}
4613
4628
0 commit comments