PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/aws/aws-sdk-php/src/Aws/Sqs/Md5ValidatorListener.php

https://github.com/lslucas/105fm
PHP | 54 lines | 26 code | 5 blank | 23 comment | 5 complexity | 314b5f6805e9f74ff79307f58e5625f8 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Aws\Sqs;
  17. use Aws\Sqs\Exception\SqsException;
  18. use Guzzle\Common\Event;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. /**
  21. * Listener used to validate the MD5 of the ReceiveMessage body
  22. */
  23. class Md5ValidatorListener implements EventSubscriberInterface
  24. {
  25. public static function getSubscribedEvents()
  26. {
  27. return array('command.after_send' => array('onCommandBeforeSend', -255));
  28. }
  29. /**
  30. * Validates the MD5OfBody attribute against the body
  31. *
  32. * @param Event $event Event emitted
  33. * @throws SqsException when an MD5 mismatch occurs
  34. */
  35. public function onCommandBeforeSend(Event $event)
  36. {
  37. if ($event['command']->getName() != 'ReceiveMessage') {
  38. return;
  39. }
  40. $result = $event['command']->getResult();
  41. if (isset($result['Messages'])) {
  42. foreach ($result['Messages'] as $message) {
  43. if ($message['MD5OfBody'] != md5($message['Body'])) {
  44. throw new SqsException('Body MD5 mismatch for ' . var_export($message, true));
  45. }
  46. }
  47. }
  48. }
  49. }