Crc32Exception.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Exception;
  10. /**
  11. * Thrown to indicate a CRC32 mismatch between the declared value in the
  12. * Central File Header and the Data Descriptor or between the declared value
  13. * and the computed value from the decompressed data.
  14. *
  15. * The exception detail message is the name of the ZIP entry.
  16. */
  17. class Crc32Exception extends ZipException
  18. {
  19. /** Expected crc. */
  20. private int $expectedCrc;
  21. /** Actual crc. */
  22. private int $actualCrc;
  23. public function __construct(string $name, int $expected, int $actual)
  24. {
  25. parent::__construct(
  26. sprintf(
  27. '%s (expected CRC32 value 0x%x, but is actually 0x%x)',
  28. $name,
  29. $expected,
  30. $actual
  31. )
  32. );
  33. $this->expectedCrc = $expected;
  34. $this->actualCrc = $actual;
  35. }
  36. /**
  37. * Returns expected crc.
  38. */
  39. public function getExpectedCrc(): int
  40. {
  41. return $this->expectedCrc;
  42. }
  43. /**
  44. * Returns actual crc.
  45. */
  46. public function getActualCrc(): int
  47. {
  48. return $this->actualCrc;
  49. }
  50. }