File tree Expand file tree Collapse file tree 8 files changed +70
-4
lines changed Expand file tree Collapse file tree 8 files changed +70
-4
lines changed Original file line number Diff line number Diff line change 721
721
'pg_field_table ' ,
722
722
'pg_flush ' ,
723
723
'pg_free_result ' ,
724
+ 'pg_host ' ,
724
725
'pg_insert ' ,
725
726
'pg_last_oid ' ,
726
727
'pg_lo_close ' ,
Original file line number Diff line number Diff line change @@ -384,6 +384,35 @@ function pg_free_result($result): void
384
384
}
385
385
386
386
387
+ /**
388
+ * pg_host returns the host name of the given
389
+ * PostgreSQL connection instance is
390
+ * connected to.
391
+ *
392
+ * @param resource $connection An PgSql\Connection instance.
393
+ * When connection is NULL, the default connection is used.
394
+ * The default connection is the last connection made by pg_connect
395
+ * or pg_pconnect.
396
+ * @return string A string containing the name of the host the
397
+ * connection is to.
398
+ * @throws PgsqlException
399
+ *
400
+ */
401
+ function pg_host ($ connection = null ): string
402
+ {
403
+ error_clear_last ();
404
+ if ($ connection !== null ) {
405
+ $ result = \pg_host ($ connection );
406
+ } else {
407
+ $ result = \pg_host ();
408
+ }
409
+ if ($ result === '' ) {
410
+ throw PgsqlException::createFromPhpError ();
411
+ }
412
+ return $ result ;
413
+ }
414
+
415
+
387
416
/**
388
417
* pg_insert inserts the values
389
418
* of values into the table specified
Original file line number Diff line number Diff line change @@ -160,6 +160,26 @@ public function detectNullsyFunction(): bool
160
160
return false ;
161
161
}
162
162
163
+ /*
164
+ * Detect function which return an empty string on error.
165
+ */
166
+ public function detectEmptyFunction (): bool
167
+ {
168
+ $ file = file_get_contents ($ this ->path );
169
+ if ($ file === false ) {
170
+ throw new \RuntimeException ('An error occured while reading ' .$ this ->path );
171
+ }
172
+ if ($ this ->getIsDeprecated ($ file )) {
173
+ return false ;
174
+ }
175
+
176
+ if (preg_match ('/an\s+empty\s+string\s+on\s+error/ ' , $ file )) {
177
+ return true ;
178
+ }
179
+
180
+ return false ;
181
+ }
182
+
163
183
164
184
/**
165
185
* @return \SimpleXMLElement[]
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Method
10
10
{
11
11
const FALSY_TYPE = 1 ;
12
12
const NULLSY_TYPE = 2 ;
13
+ const EMPTY_TYPE = 3 ;
13
14
/**
14
15
* @var \SimpleXMLElement
15
16
*/
@@ -162,7 +163,11 @@ private function stripReturnFalseText(string $string): string
162
163
$ string = $ this ->removeString ($ string , ' and FALSE if an error occurred ' );
163
164
$ string = $ this ->removeString ($ string , 'the function will return TRUE, or FALSE otherwise ' );
164
165
break ;
165
-
166
+
167
+ case self ::EMPTY_TYPE :
168
+ $ string = $ this ->removeString ($ string , ' or an empty string on error ' );
169
+ break ;
170
+
166
171
default :
167
172
throw new \RuntimeException ('Incorrect error type. ' );
168
173
}
Original file line number Diff line number Diff line change @@ -102,8 +102,9 @@ public function getMethods(array $paths): array
102
102
$ docPage = new DocPage ($ path );
103
103
$ isFalsy = $ docPage ->detectFalsyFunction ();
104
104
$ isNullsy = $ docPage ->detectNullsyFunction ();
105
- if ($ isFalsy || $ isNullsy ) {
106
- $ errorType = $ isFalsy ? Method::FALSY_TYPE : Method::NULLSY_TYPE ;
105
+ $ isEmpty = $ docPage ->detectEmptyFunction ();
106
+ if ($ isFalsy || $ isNullsy || $ isEmpty ) {
107
+ $ errorType = $ isFalsy ? Method::FALSY_TYPE : ($ isNullsy ? Method::NULLSY_TYPE : Method::EMPTY_TYPE );
107
108
108
109
$ functionObjects = $ docPage ->getMethodSynopsis ();
109
110
if (count ($ functionObjects ) > 1 ) {
Original file line number Diff line number Diff line change @@ -97,14 +97,16 @@ private function writePhpFunction(): string
97
97
98
98
private function generateExceptionCode (string $ moduleName , Method $ method ) : string
99
99
{
100
- $ errorValue = null ;
101
100
switch ($ method ->getErrorType ()) {
102
101
case Method::FALSY_TYPE :
103
102
$ errorValue = 'false ' ;
104
103
break ;
105
104
case Method::NULLSY_TYPE :
106
105
$ errorValue = 'null ' ;
107
106
break ;
107
+ case Method::EMPTY_TYPE :
108
+ $ errorValue = "'' " ;
109
+ break ;
108
110
default :
109
111
throw new \LogicException ("Method doesn't have an error type " );
110
112
}
Original file line number Diff line number Diff line change @@ -47,4 +47,11 @@ public function testDetectNullsyFunction()
47
47
$ this ->assertFalse ($ implode ->detectNullsyFunction ());
48
48
$ this ->assertTrue ($ arrayReplace ->detectNullsyFunction ());
49
49
}
50
+
51
+ public function testDetectEmptyFunction ()
52
+ {
53
+ $ pgHost = new DocPage (__DIR__ . '/../doc/doc-en/en/reference/pgsql/functions/pg-host.xml ' );
54
+
55
+ $ this ->assertTrue ($ pgHost ->detectEmptyFunction ());
56
+ }
50
57
}
Original file line number Diff line number Diff line change 731
731
'pg_field_table ' => 'Safe\pg_field_table ' ,
732
732
'pg_flush ' => 'Safe\pg_flush ' ,
733
733
'pg_free_result ' => 'Safe\pg_free_result ' ,
734
+ 'pg_host ' => 'Safe\pg_host ' ,
734
735
'pg_insert ' => 'Safe\pg_insert ' ,
735
736
'pg_last_oid ' => 'Safe\pg_last_oid ' ,
736
737
'pg_lo_close ' => 'Safe\pg_lo_close ' ,
You can’t perform that action at this time.
0 commit comments