Crc32Exception.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $this->expectedCrc = $expected;
  45. $this->actualCrc = $actual;
  46. }
  47. /**
  48. * Returns expected crc.
  49. *
  50. * @return int
  51. */
  52. public function getExpectedCrc()
  53. {
  54. return $this->expectedCrc;
  55. }
  56. /**
  57. * Returns actual crc.
  58. *
  59. * @return int
  60. */
  61. public function getActualCrc()
  62. {
  63. return $this->actualCrc;
  64. }
  65. }