OffsetPositionMapper.php 712 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace PhpZip\Mapper;
  3. /**
  4. * Adds a offset value to the given position.
  5. *
  6. * @author Ne-Lexa alexey@nelexa.ru
  7. * @license MIT
  8. */
  9. class OffsetPositionMapper extends PositionMapper
  10. {
  11. /**
  12. * @var int
  13. */
  14. private $offset;
  15. /**
  16. * @param int $offset
  17. */
  18. public function __construct($offset)
  19. {
  20. $this->offset = $offset;
  21. }
  22. /**
  23. * @param int $position
  24. * @return int
  25. */
  26. public function map($position)
  27. {
  28. return parent::map($position) + $this->offset;
  29. }
  30. /**
  31. * @param int $position
  32. * @return int
  33. */
  34. public function unmap($position)
  35. {
  36. return parent::unmap($position) - $this->offset;
  37. }
  38. }