Crc32Exception.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace PhpZip\Exception;
  3. /**
  4. * Thrown to indicate a CRC32 mismatch between the declared value in the
  5. * Central File Header and the Data Descriptor or between the declared value
  6. * and the computed value from the decompressed data.
  7. *
  8. * The exception detail message is the name of the ZIP entry.
  9. *
  10. * @author Ne-Lexa alexey@nelexa.ru
  11. * @license MIT
  12. */
  13. class Crc32Exception extends ZipException
  14. {
  15. /**
  16. * Expected crc.
  17. *
  18. * @var int
  19. */
  20. private $expectedCrc;
  21. /**
  22. * Actual crc.
  23. *
  24. * @var int
  25. */
  26. private $actualCrc;
  27. /**
  28. * Crc32Exception constructor.
  29. *
  30. * @param string $name
  31. * @param int $expected
  32. * @param int $actual
  33. */
  34. public function __construct($name, $expected, $actual)
  35. {
  36. parent::__construct(
  37. sprintf(
  38. "%s (expected CRC32 value 0x%x, but is actually 0x%x)",
  39. $name,
  40. $expected,
  41. $actual
  42. )
  43. );
  44. assert($expected != $actual);
  45. $this->expectedCrc = $expected;
  46. $this->actualCrc = $actual;
  47. }
  48. /**
  49. * Returns expected crc.
  50. *
  51. * @return int
  52. */
  53. public function getExpectedCrc()
  54. {
  55. return $this->expectedCrc;
  56. }
  57. /**
  58. * Returns actual crc.
  59. *
  60. * @return int
  61. */
  62. public function getActualCrc()
  63. {
  64. return $this->actualCrc;
  65. }
  66. }