DefaultExtraField.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace PhpZip\Extra\Fields;
  3. use PhpZip\Exception\ZipException;
  4. use PhpZip\Extra\ExtraField;
  5. /**
  6. * Default implementation for an Extra Field in a Local or Central Header of a
  7. * ZIP file.
  8. *
  9. * @author Ne-Lexa alexey@nelexa.ru
  10. * @license MIT
  11. */
  12. class DefaultExtraField implements ExtraField
  13. {
  14. /**
  15. * @var int
  16. */
  17. private static $headerId;
  18. /**
  19. * @var string
  20. */
  21. protected $data;
  22. /**
  23. * Constructs a new Extra Field.
  24. *
  25. * @param int $headerId an unsigned short integer (two bytes) indicating the
  26. * type of the Extra Field.
  27. * @throws ZipException
  28. */
  29. public function __construct($headerId)
  30. {
  31. if (0x0000 > $headerId || $headerId > 0xffff) {
  32. throw new ZipException('headerId out of range');
  33. }
  34. self::$headerId = $headerId;
  35. }
  36. /**
  37. * Returns the Header ID (type) of this Extra Field.
  38. * The Header ID is an unsigned short integer (two bytes)
  39. * which must be constant during the life cycle of this object.
  40. *
  41. * @return int
  42. */
  43. public static function getHeaderId()
  44. {
  45. return self::$headerId & 0xffff;
  46. }
  47. /**
  48. * Serializes a Data Block.
  49. * @return string
  50. */
  51. public function serialize()
  52. {
  53. return $this->data;
  54. }
  55. /**
  56. * Initializes this Extra Field by deserializing a Data Block.
  57. * @param string $data
  58. */
  59. public function deserialize($data)
  60. {
  61. $this->data = $data;
  62. }
  63. }