@@ -1805,7 +1805,6 @@ private function getOptions(): array
18051805 $ options = array (
18061806 \PDO ::ATTR_ERRMODE => \PDO ::ERRMODE_EXCEPTION ,
18071807 \PDO ::ATTR_DEFAULT_FETCH_MODE => \PDO ::FETCH_ASSOC ,
1808- \PDO ::ATTR_STRINGIFY_FETCHES => false ,
18091808 );
18101809 switch ($ this ->driver ) {
18111810 case 'mysql ' :return $ options + [
@@ -3694,9 +3693,22 @@ public function __construct(ReflectionService $reflection, $base)
36943693 $ this ->openapi = new OpenApiDefinition ($ base );
36953694 }
36963695
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+
36973706 public function build (): OpenApiDefinition
36983707 {
36993708 $ 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+ }
37003712 $ tableNames = $ this ->reflection ->getTableNames ();
37013713 foreach ($ tableNames as $ tableName ) {
37023714 $ this ->setPath ($ tableName );
@@ -3915,6 +3927,20 @@ public function set(String $path, $value) /*: void*/
39153927 $ current = $ value ;
39163928 }
39173929
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+
39183944 public function jsonSerialize ()
39193945 {
39203946 return $ this ->root ;
0 commit comments