Skip to content

Commit

Permalink
Add parse-url method
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Feb 27, 2019
1 parent 4a8c8e5 commit 8edb2d8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@
'uopz_implement',
'base64_decode',
'get_headers',
'parse_url',
'settype',
'xdiff_file_bdiff',
'xdiff_file_bpatch',
Expand Down
88 changes: 88 additions & 0 deletions generated/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,91 @@ function get_headers(string $url, int $format = 0, $context = null): array
}
return $result;
}


/**
* This function parses a URL and returns an associative array containing any
* of the various components of the URL that are present.
* The values of the array elements are not URL decoded.
*
* This function is not meant to validate
* the given URL, it only breaks it up into the above listed parts. Partial
* URLs are also accepted, parse_url tries its best to
* parse them correctly.
*
* @param string $url The URL to parse. Invalid characters are replaced by
* _.
* @param int $component Specify one of PHP_URL_SCHEME,
* PHP_URL_HOST, PHP_URL_PORT,
* PHP_URL_USER, PHP_URL_PASS,
* PHP_URL_PATH, PHP_URL_QUERY
* or PHP_URL_FRAGMENT to retrieve just a specific
* URL component as a string (except when
* PHP_URL_PORT is given, in which case the return
* value will be an integer).
* @return mixed On seriously malformed URLs, parse_url may return
* FALSE.
*
* If the component parameter is omitted, an
* associative array is returned. At least one element will be
* present within the array. Potential keys within this array are:
*
*
*
* scheme - e.g. http
*
*
*
*
* host
*
*
*
*
* port
*
*
*
*
* user
*
*
*
*
* pass
*
*
*
*
* path
*
*
*
*
* query - after the question mark ?
*
*
*
*
* fragment - after the hashmark #
*
*
*
*
* If the component parameter is specified,
* parse_url returns a string (or an
* integer, in the case of PHP_URL_PORT)
* instead of an array. If the requested component doesn't exist
* within the given URL, NULL will be returned.
* @throws UrlException
*
*/
function parse_url(string $url, int $component = -1)
{
error_clear_last();
$result = \parse_url($url, $component);
if ($result === false) {
throw UrlException::createFromPhpError();
}
return $result;
}
3 changes: 3 additions & 0 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function detectFalsyFunction(): bool
if (preg_match('/&false;\s+otherwise/m', $file) && !preg_match('/(returns\s+&true;|&true;\s+on\s+success|&true;\s+if)/im', $file)) {
return true;
}
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)) {
return true;
}
if (preg_match('/&false;\s+if\s+an\s+error\s+occurred/m', $file)) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions rector-migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ services:
uopz_implement: 'Safe\uopz_implement'
base64_decode: 'Safe\base64_decode'
get_headers: 'Safe\get_headers'
parse_url: 'Safe\parse_url'
settype: 'Safe\settype'
xdiff_file_bdiff: 'Safe\xdiff_file_bdiff'
xdiff_file_bpatch: 'Safe\xdiff_file_bpatch'
Expand Down

0 comments on commit 8edb2d8

Please sign in to comment.