-
Couldn't load subscription status.
- Fork 1
PSR 7: Uri Example
Terry L edited this page Jun 20, 2020
·
3 revisions
Namespace
Shieldon\Psr7\Uri- __construct
- getScheme
- getAuthority
- getUserInfo
- getHost
- getPort
- getPath
- getQuery
- getFragment
- withScheme
- withUserInfo
- withHost
- withPort
- withPath
- withQuery
- withFragment
- __toString
-
param
stringuri= ""The URI.
Example:
$uri = new \Shieldon\Psr7\Uri('https://www.example.com');-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://www.example.com'
);
echo $uri->getScheme();
// Outputs: https-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:[email protected]:8888/phpMyAdmin/'
);
echo $uri->getAuthority();
// Outputs: terry:[email protected]:8888-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:[email protected]:8888/phpMyAdmin/'
);
echo $uri->getUserInfo();
// Outputs: terry:1234-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:[email protected]:8888/phpMyAdmin/'
);
echo $uri->getHost();
// Outputs: example.com-
return
int|null
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:[email protected]:8888/phpMyAdmin/'
);
echo $uri->getPort();
// Outputs: 8888-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://example.com/post/?p=113&foo=bar#yes-i-do'
);
echo $uri->getPath();
// Outputs: /post/-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://example.com/post/?p=113&foo=bar#yes-i-do'
);
echo $uri->getQuery();
// Outputs: p=113&foo=bar-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://example.com/post/?p=113&foo=bar#yes-i-do'
);
echo $uri->getFragment();
// Outputs: yes-i-do-
param
stringscheme*The scheme to use with the new instance. -
return
static
Example:
echo $uri->getScheme();
// Outputs: https
$url = $uri->withScheme('http');
echo $uri->getScheme();
// Outputs: http-
param
stringuser*The user name to use for authority. -
param
string|nullpassword= nullThe password associated with $user. -
return
static
Example:
echo $uri->getUserInfo();
// Outputs: terry:1234
$url = $uri->withUserInfo('jack', '5678');
echo $uri->getUserInfo();
// Outputs: jack:5678-
param
stringhost*The hostname to use with the new instance. -
return
static
Example:
echo $uri->getHost();
// Outputs: example.com
$url = $uri->withHost('terryl.in');
echo $uri->getHost();
// Outputs: terryl.in-
param
int|nullport*The port to use with the new instance; a null value removes the port information. -
return
static
Example:
echo $uri->getPort();
// Outputs: 8888
$uri = $uri->withPort(443);
echo $uri->getPort();
// Outputs: 443
$uri = $uri->withPort(null);
echo $uri->getPort();
// Outputs:-
param
stringpath*The path to use with the new instance. -
return
static
Example:
echo $uri->getPath();
// Outputs: /post/
$uri = $uri->withPath('/new-path');
echo $uri->getPath();
// Outputs: /new-path-
param
stringquery*The query string to use with the new instance. -
return
static
Example:
echo $uri->getQuery();
// Outputs: p=113&foo=bar
$uri = $uri->witQuery('p=120&foo=baz');
echo $uri->getQuery();
// Outputs: p=120&foo=baz-
param
stringfragment*The fragment to use with the new instance. -
return
static
Example:
echo $uri->getFragment();
// Outputs: yes-i-do
$uri = $uri->withFragment('no-i-cant');
echo $uri->getFragment();
// Outputs: no-i-cant-
return
string
Example:
$uri = new Uri('http://example.com:8888/demo/#section-1');
echo $uri;
// Outputs: http://example.com:8888/demo/#section-1composer require shieldon/psr-httpShieldon PSR HTTP implementation written by Terry L. from Taiwan.
