Skip to content

Commit

Permalink
Merge pull request #23 from zf-fr/do-not-escape-slashs
Browse files Browse the repository at this point in the history
Do not escape slashes
  • Loading branch information
bakura10 committed Mar 25, 2016
2 parents 0a88751 + 6cd0a5c commit 1bf5410
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.0.1

* Message body is now encoded in RFC4627-compliant JSON by using some encoding flags.

# 4.0.0

* `QueuePublisherInterface` has been removed and replaced by a single `MessageQueueInterface`, tied to a single queue.
Expand Down
13 changes: 12 additions & 1 deletion src/MessageQueue/MessageQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
*/
class MessageQueue implements MessageQueueInterface
{
/**
* Default flags for json_encode; value of:
*
* <code>
* JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES
* </code>
*
* @const int
*/
const DEFAULT_JSON_FLAGS = 79;

/**
* @var array[]
*/
Expand Down Expand Up @@ -98,7 +109,7 @@ private function doFlush(bool $async)
foreach ($messagesToPush as $key => $message) {
$messageParameters = [
'Id' => $key, // Identifier of the message in the batch
'MessageBody' => json_encode($message['body']),
'MessageBody' => json_encode($message['body'], self::DEFAULT_JSON_FLAGS),
'DelaySeconds' => $message['options']['delay_seconds'] ?? null
];

Expand Down
16 changes: 3 additions & 13 deletions test/MessageQueue/MessageQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ public function testCanPushToQueue(bool $async)
[
'Id' => 0,
'DelaySeconds' => 0,
'MessageBody' => json_encode([
'name' => 'message-name',
'payload' => [
'id' => 123
]
]),
'MessageBody' => '{"name":"message-name","payload":{"id":123,"url":"https://www.test.com"}}'
]
]
];
Expand All @@ -74,7 +69,7 @@ public function testCanPushToQueue(bool $async)
}

$queue = new MessageQueue('https://queue-url.aws.com', $this->sqsClient->reveal());
$queue->push(new Message('message-name', ['id' => 123]));
$queue->push(new Message('message-name', ['id' => 123, 'url' => 'https://www.test.com']));
$queue->flush($async);
}

Expand All @@ -86,12 +81,7 @@ public function testCanPushDelayedMessage()
[
'Id' => 0,
'DelaySeconds' => 30,
'MessageBody' => json_encode([
'name' => 'message-name',
'payload' => [
'id' => 123
]
]),
'MessageBody' => '{"name":"message-name","payload":{"id":123}}'
]
]
];
Expand Down

0 comments on commit 1bf5410

Please sign in to comment.