-
Notifications
You must be signed in to change notification settings - Fork 2
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
string
uri= ""
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:1234@example.com:8888/phpMyAdmin/'
);
echo $uri->getAuthority();
// Outputs: terry:1234@example.com:8888
-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:1234@example.com:8888/phpMyAdmin/'
);
echo $uri->getUserInfo();
// Outputs: terry:1234
-
return
string
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:1234@example.com:8888/phpMyAdmin/'
);
echo $uri->getHost();
// Outputs: example.com
-
return
int|null
Example:
$uri = new \Shieldon\Psr7\Uri(
'https://terry:1234@example.com: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
string
scheme*
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
string
user*
The user name to use for authority. -
param
string|null
password= null
The 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
string
host*
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|null
port*
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
string
path*
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
string
query*
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
string
fragment*
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-1
composer require shieldon/psr-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.