Skip to content

Commit fd18875

Browse files
authored
Merge pull request #95 from jderusse/parse_url
Add parse_url method
2 parents 5015fb0 + 0ca738b commit fd18875

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

generated/functionsList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@
10271027
'uopz_implement',
10281028
'base64_decode',
10291029
'get_headers',
1030+
'parse_url',
10301031
'settype',
10311032
'xdiff_file_bdiff',
10321033
'xdiff_file_bpatch',

generated/ibmDb2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @return mixed When db2_autocommit receives only the
3636
* connection parameter, it returns the current state
3737
* of AUTOCOMMIT for the requested connection as an integer value. A value of
38-
* 0 indicates that AUTOCOMMIT is off, while a value of 1 indicates that
38+
* DB2_AUTOCOMMIT_OFF indicates that AUTOCOMMIT is off, while a value of DB2_AUTOCOMMIT_ON indicates that
3939
* AUTOCOMMIT is on.
4040
*
4141
* When db2_autocommit receives both the

generated/url.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,90 @@ function get_headers(string $url, int $format = 0, $context = null): array
5555
}
5656
return $result;
5757
}
58+
59+
60+
/**
61+
* This function parses a URL and returns an associative array containing any
62+
* of the various components of the URL that are present.
63+
* The values of the array elements are not URL decoded.
64+
*
65+
* This function is not meant to validate
66+
* the given URL, it only breaks it up into the above listed parts. Partial
67+
* URLs are also accepted, parse_url tries its best to
68+
* parse them correctly.
69+
*
70+
* @param string $url The URL to parse. Invalid characters are replaced by
71+
* _.
72+
* @param int $component Specify one of PHP_URL_SCHEME,
73+
* PHP_URL_HOST, PHP_URL_PORT,
74+
* PHP_URL_USER, PHP_URL_PASS,
75+
* PHP_URL_PATH, PHP_URL_QUERY
76+
* or PHP_URL_FRAGMENT to retrieve just a specific
77+
* URL component as a string (except when
78+
* PHP_URL_PORT is given, in which case the return
79+
* value will be an integer).
80+
* @return mixed On seriously malformed URLs, parse_url.
81+
*
82+
* If the component parameter is omitted, an
83+
* associative array is returned. At least one element will be
84+
* present within the array. Potential keys within this array are:
85+
*
86+
*
87+
*
88+
* scheme - e.g. http
89+
*
90+
*
91+
*
92+
*
93+
* host
94+
*
95+
*
96+
*
97+
*
98+
* port
99+
*
100+
*
101+
*
102+
*
103+
* user
104+
*
105+
*
106+
*
107+
*
108+
* pass
109+
*
110+
*
111+
*
112+
*
113+
* path
114+
*
115+
*
116+
*
117+
*
118+
* query - after the question mark ?
119+
*
120+
*
121+
*
122+
*
123+
* fragment - after the hashmark #
124+
*
125+
*
126+
*
127+
*
128+
* If the component parameter is specified,
129+
* parse_url returns a string (or an
130+
* integer, in the case of PHP_URL_PORT)
131+
* instead of an array. If the requested component doesn't exist
132+
* within the given URL, NULL will be returned.
133+
* @throws UrlException
134+
*
135+
*/
136+
function parse_url(string $url, int $component = -1)
137+
{
138+
error_clear_last();
139+
$result = \parse_url($url, $component);
140+
if ($result === false) {
141+
throw UrlException::createFromPhpError();
142+
}
143+
return $result;
144+
}

generator/src/DocPage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function detectFalsyFunction(): bool
5656
if (preg_match('/&false;\s+otherwise/m', $file) && !preg_match('/(returns\s+&true;|&true;\s+on\s+success|&true;\s+if)/im', $file)) {
5757
return true;
5858
}
59+
if (preg_match('/may\s+return\s+&false;/m', $file) && !preg_match('/(returns\s+&true;|&true;\s+on\s+success|&true;\s+if)/im', $file)) {
60+
return true;
61+
}
5962
if (preg_match('/&false;\s+if\s+an\s+error\s+occurred/m', $file)) {
6063
return true;
6164
}

generator/src/Method.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ private function stripReturnFalseText(string $string): string
132132
{
133133
$string = \strip_tags($string);
134134
$string = $this->removeString($string, 'or FALSE on failure');
135+
$string = $this->removeString($string, 'may return FALSE');
135136
$string = $this->removeString($string, 'and FALSE on failure');
136137
$string = $this->removeString($string, 'on success, or FALSE otherwise');
137138
$string = $this->removeString($string, 'or FALSE on error');

rector-migrate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ services:
10281028
uopz_implement: 'Safe\uopz_implement'
10291029
base64_decode: 'Safe\base64_decode'
10301030
get_headers: 'Safe\get_headers'
1031+
parse_url: 'Safe\parse_url'
10311032
settype: 'Safe\settype'
10321033
xdiff_file_bdiff: 'Safe\xdiff_file_bdiff'
10331034
xdiff_file_bpatch: 'Safe\xdiff_file_bpatch'

0 commit comments

Comments
 (0)