Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
createSession example
public
function
testHandleWhenUsernameLength
(
$username
,
$ok
)
{
if
(
$ok
)
{
$this
->
expectNotToPerformAssertions
(
)
;
}
else
{
$this
->
expectException
(
BadCredentialsException::
class
)
;
$this
->
expectExceptionMessage
(
'Username too long.'
)
;
}
$request
= Request::
create
(
'/login_check', 'POST',
[
'_username' =>
$username
, '_password' => 's$cr$t'
]
)
;
$request
->
setSession
(
$this
->
createSession
(
)
)
;
$this
->
setUpAuthenticator
(
)
;
$this
->authenticator->
authenticate
(
$request
)
;
}
public
static
function
provideUsernamesForLength
(
)
{
yield
[
str_repeat
(
'x', UserBadge::MAX_USERNAME_LENGTH + 1
)
, false
]
;
yield
[
str_repeat
(
'x', UserBadge::MAX_USERNAME_LENGTH - 1
)
, true
]
;
}
class
SessionListener
extends
AbstractSessionListener
{
protected
function
getSession
(
)
: ?SessionInterface
{
if
(
$this
->container->
has
(
'session_factory'
)
)
{
return
$this
->container->
get
(
'session_factory'
)
->
createSession
(
)
;
}
return
null;
}
}
if
(
$session
instanceof FlashBagAwareSessionInterface
)
{
$session
->
getFlashBag
(
)
->
clear
(
)
;
}
}
public
function
getSession
(
)
: SessionInterface
{
/** @var SessionFactoryInterface $factory */
$factory
=
$this
->
getContainer
(
)
->
get
(
'session.factory'
)
;
return
$factory
->
createSession
(
)
;
}
}
if
(
method_exists
(
$token
, 'isAuthenticated'
)
)
{
$token
->
setAuthenticated
(
true, false
)
;
}
$container
=
$this
->
getContainer
(
)
;
$container
->
get
(
'security.untracked_token_storage'
)
->
setToken
(
$token
)
;
if
(
!
$container
->
has
(
'session.factory'
)
)
{
return
$this
;
}
$session
=
$container
->
get
(
'session.factory'
)
->
createSession
(
)
;
$session
->
set
(
'_security_'.
$firewallContext
,
serialize
(
$token
)
)
;
$session
->
save
(
)
;
$domains
=
array_unique
(
array_map
(
fn
(
Cookie
$cookie
)
=>
$cookie
->
getName
(
)
===
$session
->
getName
(
)
?
$cookie
->
getDomain
(
)
: '',
$this
->
getCookieJar
(
)
->
all
(
)
)
)
?:
[
''
]
;
foreach
(
$domains
as
$domain
)
{
$cookie
=
new
Cookie
(
$session
->
getName
(
)
,
$session
->
getId
(
)
, null, null,
$domain
)
;
$this
->
getCookieJar
(
)
->
set
(
$cookie
)
;
}
return
$this
;
}
class
SessionListener
extends
AbstractSessionListener
{
protected
function
getSession
(
)
: ?SessionInterface
{
if
(
$this
->container->
has
(
'session_factory'
)
)
{
return
$this
->container->
get
(
'session_factory'
)
->
createSession
(
)
;
}
return
null;
}
}