@@ -1805,7 +1805,6 @@ private function getOptions(): array
1805
1805
$ options = array (
1806
1806
\PDO ::ATTR_ERRMODE => \PDO ::ERRMODE_EXCEPTION ,
1807
1807
\PDO ::ATTR_DEFAULT_FETCH_MODE => \PDO ::FETCH_ASSOC ,
1808
- \PDO ::ATTR_STRINGIFY_FETCHES => false ,
1809
1808
);
1810
1809
switch ($ this ->driver ) {
1811
1810
case 'mysql ' :return $ options + [
@@ -3694,9 +3693,22 @@ public function __construct(ReflectionService $reflection, $base)
3694
3693
$ this ->openapi = new OpenApiDefinition ($ base );
3695
3694
}
3696
3695
3696
+ private function getServerUrl (): String
3697
+ {
3698
+ $ protocol = @$ _SERVER ['HTTP_X_FORWARDED_PROTO ' ] ?: @$ _SERVER ['REQUEST_SCHEME ' ] ?: ((isset ($ _SERVER ["HTTPS " ]) && $ _SERVER ["HTTPS " ] == "on " ) ? "https " : "http " );
3699
+ $ port = @intval ($ _SERVER ['HTTP_X_FORWARDED_PORT ' ]) ?: @intval ($ _SERVER ["SERVER_PORT " ]) ?: (($ protocol === 'https ' ) ? 443 : 80 );
3700
+ $ host = @explode (": " , $ _SERVER ['HTTP_HOST ' ])[0 ] ?: @$ _SERVER ['SERVER_NAME ' ] ?: @$ _SERVER ['SERVER_ADDR ' ];
3701
+ $ port = ($ protocol === 'https ' && $ port === 443 ) || ($ protocol === 'http ' && $ port === 80 ) ? '' : ': ' . $ port ;
3702
+ $ path = @trim (substr ($ _SERVER ['REQUEST_URI ' ], 0 , strpos ($ _SERVER ['REQUEST_URI ' ], '/openapi ' )), '/ ' );
3703
+ return sprintf ('%s://%s%s/%s ' , $ protocol , $ host , $ port , $ path );
3704
+ }
3705
+
3697
3706
public function build (): OpenApiDefinition
3698
3707
{
3699
3708
$ this ->openapi ->set ("openapi " , "3.0.0 " );
3709
+ if (!$ this ->openapi ->has ("servers " ) && isset ($ _SERVER ['REQUEST_URI ' ])) {
3710
+ $ this ->openapi ->set ("servers|0|url " , $ this ->getServerUrl ());
3711
+ }
3700
3712
$ tableNames = $ this ->reflection ->getTableNames ();
3701
3713
foreach ($ tableNames as $ tableName ) {
3702
3714
$ this ->setPath ($ tableName );
@@ -3915,6 +3927,20 @@ public function set(String $path, $value) /*: void*/
3915
3927
$ current = $ value ;
3916
3928
}
3917
3929
3930
+ public function has (String $ path ): bool
3931
+ {
3932
+ $ parts = explode ('| ' , trim ($ path , '| ' ));
3933
+ $ current = &$ this ->root ;
3934
+ while (count ($ parts ) > 0 ) {
3935
+ $ part = array_shift ($ parts );
3936
+ if (!isset ($ current [$ part ])) {
3937
+ return false ;
3938
+ }
3939
+ $ current = &$ current [$ part ];
3940
+ }
3941
+ return true ;
3942
+ }
3943
+
3918
3944
public function jsonSerialize ()
3919
3945
{
3920
3946
return $ this ->root ;
0 commit comments