PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Chord/Component/DataShot/Filter/Md5.php

https://github.com/chord/chord
PHP | 39 lines | 16 code | 5 blank | 18 comment | 2 complexity | 0bbf19fb32cb22e6757ba043e3861935 MD5 | raw file
  1. <?php
  2. namespace Chord\Component\DataShot\Filter;
  3. /*
  4. * This file is part of the Chord component library.
  5. *
  6. * (c) Matthias Nothhaft <matthias.nothhaft@googlemail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. use Chord\Component\DataShot\FilterInterface;
  12. class Md5 implements FilterInterface
  13. {
  14. /**
  15. * Filters data after serialization.
  16. *
  17. * @param array Entry instance with serialized data
  18. */
  19. public function apply(Entry $entry)
  20. {
  21. $entry->setHeader('md5', md5($entry->getData()));
  22. }
  23. /**
  24. * Filters data before unserialization.
  25. *
  26. * @param Entry Entry instance with serialized data
  27. */
  28. public function remove(Entry $entry)
  29. {
  30. if ($entry->getHeader('md5') != md5($entry->getData())) {
  31. throw new InvalidArgumentException('Data is corrupt');
  32. }
  33. }
  34. }