Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
addStamp example
return
new
Envelope
(
$message
,
$stamps
)
;
}
}
;
$stamp
=
$this
->
createMock
(
StampInterface::
class
)
;
$dispatcher
=
$this
->
createMock
(
EventDispatcherInterface::
class
)
;
$dispatcher
->
expects
(
$this
->
once
(
)
)
->
method
(
'dispatch'
)
->
with
(
self::
callback
(
static
function
DMessageEvent
$event
)
use
(
$stamp
)
{
$event
->
addStamp
(
$stamp
)
;
return
'Time for Symfony Mailer!' ===
$event
->
getMessage
(
)
->
getSubject
(
)
;
}
)
)
->
willReturnArgument
(
0
)
;
$mailer
=
new
Mailer
(
new
NullTransport
(
$dispatcher
)
,
$bus
,
$dispatcher
)
;
$email
=
(
new
Email
(
)
)
->
from
(
'hello@example.com'
)
->
to
(
'you@example.com'
)
if
(
!
$event
->
isQueued
(
)
)
{
return
;
}
$message
=
$event
->
getMessage
(
)
;
if
(
!
$message
instanceof Message || !
$message
->
getHeaders
(
)
->
has
(
'X-Bus-Transport'
)
)
{
return
;
}
$names
=
$message
->
getHeaders
(
)
->
get
(
'X-Bus-Transport'
)
->
getBody
(
)
;
$names
=
array_map
(
'trim',
explode
(
',',
$names
)
)
;
$event
->
addStamp
(
new
TransportNamesStamp
(
$names
)
)
;
$message
->
getHeaders
(
)
->
remove
(
'X-Bus-Transport'
)
;
}
public
static
function
getSubscribedEvents
(
)
: array
{
return
[
MessageEvent::
class
=>
'onMessage',
]
;
}
}