Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setHttpsPort example
$this
->
assertEquals
(
'',
$requestContext
->
getBaseUrl
(
)
)
;
$this
->
assertEquals
(
'GET',
$requestContext
->
getMethod
(
)
)
;
$this
->
assertEquals
(
'test.com',
$requestContext
->
getHost
(
)
)
;
$this
->
assertEquals
(
'https',
$requestContext
->
getScheme
(
)
)
;
$this
->
assertEquals
(
'/foo',
$requestContext
->
getPathInfo
(
)
)
;
$this
->
assertEquals
(
'bar=baz',
$requestContext
->
getQueryString
(
)
)
;
$this
->
assertSame
(
123,
$requestContext
->
getHttpPort
(
)
)
;
$this
->
assertSame
(
444,
$requestContext
->
getHttpsPort
(
)
)
;
$request
= Request::
create
(
'http://test.com:8080/foo?bar=baz'
)
;
$requestContext
=
new
RequestContext
(
)
;
$requestContext
->
setHttpsPort
(
567
)
;
$requestContext
->
fromRequest
(
$request
)
;
$this
->
assertSame
(
8080,
$requestContext
->
getHttpPort
(
)
)
;
$this
->
assertSame
(
567,
$requestContext
->
getHttpsPort
(
)
)
;
}
public
function
testGetParameters
(
)
{
$requestContext
=
new
RequestContext
(
)
;
$this
->
assertEquals
(
[
]
,
$requestContext
->
getParameters
(
)
)
;
private
int
$httpsPort
;
private
string
$queryString
;
private
array
$parameters
=
[
]
;
public
function
__construct
(
string
$baseUrl
= '', string
$method
= 'GET', string
$host
= 'localhost', string
$scheme
= 'http', int
$httpPort
= 80, int
$httpsPort
= 443, string
$path
= '/', string
$queryString
= ''
)
{
$this
->
setBaseUrl
(
$baseUrl
)
;
$this
->
setMethod
(
$method
)
;
$this
->
setHost
(
$host
)
;
$this
->
setScheme
(
$scheme
)
;
$this
->
setHttpPort
(
$httpPort
)
;
$this
->
setHttpsPort
(
$httpsPort
)
;
$this
->
setPathInfo
(
$path
)
;
$this
->
setQueryString
(
$queryString
)
;
}
public
static
function
fromUri
(
string
$uri
, string
$host
= 'localhost', string
$scheme
= 'http', int
$httpPort
= 80, int
$httpsPort
= 443
)
: self
{
$uri
=
parse_url
(
$uri
)
;
$scheme
=
$uri
[
'scheme'
]
??
$scheme
;
$host
=
$uri
[
'host'
]
??
$host
;
if
(
isset
(
$uri
[
'port'
]
)
)
{
$currentHttpsPort
=
$context
->
getHttpsPort
(
)
;
$currentPathInfo
=
$context
->
getPathInfo
(
)
;
$currentQueryString
=
$context
->
getQueryString
(
)
;
/* @var RouterContextStamp $contextStamp */
$context
->
setBaseUrl
(
$contextStamp
->
getBaseUrl
(
)
)
->
setMethod
(
$contextStamp
->
getMethod
(
)
)
->
setHost
(
$contextStamp
->
getHost
(
)
)
->
setScheme
(
$contextStamp
->
getScheme
(
)
)
->
setHttpPort
(
$contextStamp
->
getHttpPort
(
)
)
->
setHttpsPort
(
$contextStamp
->
getHttpsPort
(
)
)
->
setPathInfo
(
$contextStamp
->
getPathInfo
(
)
)
->
setQueryString
(
$contextStamp
->
getQueryString
(
)
)
;
try
{
return
$stack
->
next
(
)
->
handle
(
$envelope
,
$stack
)
;
}
finally
{
$context
->
setBaseUrl
(
$currentBaseUrl
)
->
setMethod
(
$currentMethod
)
->
setHost
(
$currentHost
)
private
int
$httpsPort
;
private
string
$queryString
;
private
array
$parameters
=
[
]
;
public
function
__construct
(
string
$baseUrl
= '', string
$method
= 'GET', string
$host
= 'localhost', string
$scheme
= 'http', int
$httpPort
= 80, int
$httpsPort
= 443, string
$path
= '/', string
$queryString
= ''
)
{
$this
->
setBaseUrl
(
$baseUrl
)
;
$this
->
setMethod
(
$method
)
;
$this
->
setHost
(
$host
)
;
$this
->
setScheme
(
$scheme
)
;
$this
->
setHttpPort
(
$httpPort
)
;
$this
->
setHttpsPort
(
$httpsPort
)
;
$this
->
setPathInfo
(
$path
)
;
$this
->
setQueryString
(
$queryString
)
;
}
public
static
function
fromUri
(
string
$uri
, string
$host
= 'localhost', string
$scheme
= 'http', int
$httpPort
= 80, int
$httpsPort
= 443
)
: self
{
$uri
=
parse_url
(
$uri
)
;
$scheme
=
$uri
[
'scheme'
]
??
$scheme
;
$host
=
$uri
[
'host'
]
??
$host
;
if
(
isset
(
$uri
[
'port'
]
)
)
{
/** * @dataProvider getPortData */
public
function
testPort
(
$defaultHttpPort
,
$defaultHttpsPort
,
$uri
,
$expectedHttpPort
,
$expectedHttpsPort
)
{
$urlMatcher
=
$this
->
createMock
(
UrlMatcherInterface::
class
)
;
$context
=
new
RequestContext
(
)
;
$context
->
setHttpPort
(
$defaultHttpPort
)
;
$context
->
setHttpsPort
(
$defaultHttpsPort
)
;
$urlMatcher
->
expects
(
$this
->
any
(
)
)
->
method
(
'getContext'
)
->
willReturn
(
$context
)
;
$listener
=
new
RouterListener
(
$urlMatcher
,
$this
->requestStack
)
;
$event
=
$this
->
createRequestEventForUri
(
$uri
)
;
$listener
->
onKernelRequest
(
$event
)
;
$this
->
assertEquals
(
$expectedHttpPort
,
$context
->
getHttpPort
(
)
)
;
$this
->
assertEquals
(
$expectedHttpsPort
,
$context
->
getHttpsPort
(
)
)
;
$this
->
assertEquals
(
str_starts_with
(
$uri
, 'https'
)
? 'https' : 'http',
$context
->
getScheme
(
)
)
;
}