UnrecognizedExtraField.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace PhpZip\Model\Extra\Fields;
  3. use PhpZip\Model\Extra\ZipExtraField;
  4. use PhpZip\Model\ZipEntry;
  5. /**
  6. * Simple placeholder for all those extra fields we don't want to deal with.
  7. */
  8. class UnrecognizedExtraField implements ZipExtraField
  9. {
  10. /** @var int */
  11. private $headerId;
  12. /** @var string extra field data without Header-ID or length specifier */
  13. private $data;
  14. /**
  15. * UnrecognizedExtraField constructor.
  16. *
  17. * @param int $headerId
  18. * @param string $data
  19. */
  20. public function __construct($headerId, $data)
  21. {
  22. $this->headerId = (int) $headerId;
  23. $this->data = (string) $data;
  24. }
  25. /**
  26. * @param int $headerId
  27. */
  28. public function setHeaderId($headerId)
  29. {
  30. $this->headerId = $headerId;
  31. }
  32. /**
  33. * Returns the Header ID (type) of this Extra Field.
  34. * The Header ID is an unsigned short integer (two bytes)
  35. * which must be constant during the life cycle of this object.
  36. *
  37. * @return int
  38. */
  39. public function getHeaderId()
  40. {
  41. return $this->headerId;
  42. }
  43. /**
  44. * Populate data from this array as if it was in local file data.
  45. *
  46. * @param string $buffer the buffer to read data from
  47. * @param ZipEntry|null $entry
  48. */
  49. public static function unpackLocalFileData($buffer, ZipEntry $entry = null)
  50. {
  51. throw new \RuntimeException('Unsupport parse');
  52. }
  53. /**
  54. * Populate data from this array as if it was in central directory data.
  55. *
  56. * @param string $buffer the buffer to read data from
  57. * @param ZipEntry|null $entry
  58. */
  59. public static function unpackCentralDirData($buffer, ZipEntry $entry = null)
  60. {
  61. throw new \RuntimeException('Unsupport parse');
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function packLocalFileData()
  67. {
  68. return $this->data;
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function packCentralDirData()
  74. {
  75. return $this->data;
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function getData()
  81. {
  82. return $this->data;
  83. }
  84. /**
  85. * @param string $data
  86. */
  87. public function setData($data)
  88. {
  89. $this->data = (string) $data;
  90. }
  91. /**
  92. * @return string
  93. */
  94. public function __toString()
  95. {
  96. $args = [$this->headerId, $this->data];
  97. $format = '0x%04x Unrecognized Extra Field: "%s"';
  98. return vsprintf($format, $args);
  99. }
  100. }