collection); } /** * Returns the Extra Field with the given Header ID or null * if no such Extra Field exists. * * @param int $headerId The requested Header ID. * @return ExtraField The Extra Field with the given Header ID or * if no such Extra Field exists. * @throws ZipException If headerId is out of range. */ public function get($headerId) { if (0x0000 > $headerId || $headerId > 0xffff) { throw new ZipException('headerId out of range'); } if (isset($this->collection[$headerId])) { return $this->collection[$headerId]; } return null; } /** * Stores the given Extra Field in this collection. * * @param ExtraField $extraField The Extra Field to store in this collection. * @return ExtraField The Extra Field previously associated with the Header ID of * of the given Extra Field or null if no such Extra Field existed. * @throws ZipException If headerId is out of range. */ public function add(ExtraField $extraField) { $headerId = $extraField::getHeaderId(); if (0x0000 > $headerId || $headerId > 0xffff) { throw new ZipException('headerId out of range'); } $this->collection[$headerId] = $extraField; return $extraField; } /** * Returns Extra Field exists * * @param int $headerId The requested Header ID. * @return bool */ public function has($headerId) { return isset($this->collection[$headerId]); } /** * Removes the Extra Field with the given Header ID. * * @param int $headerId The requested Header ID. * @return ExtraField The Extra Field with the given Header ID or null * if no such Extra Field exists. * @throws ZipException If headerId is out of range or extra field not found. */ public function remove($headerId) { if (0x0000 > $headerId || $headerId > 0xffff) { throw new ZipException('headerId out of range'); } if (isset($this->collection[$headerId])) { $ef = $this->collection[$headerId]; unset($this->collection[$headerId]); return $ef; } throw new ZipException('ExtraField not found'); } /** * Whether a offset exists * @link http://php.net/manual/en/arrayaccess.offsetexists.php * @param mixed $offset
* An offset to check for. *
* @return boolean true on success or false on failure. * ** The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ public function offsetExists($offset) { return isset($this->collection[$offset]); } /** * Offset to retrieve * @link http://php.net/manual/en/arrayaccess.offsetget.php * @param mixed $offset
* The offset to retrieve. *
* @return mixed Can return all value types. * @since 5.0.0 */ public function offsetGet($offset) { return $this->get($offset); } /** * Offset to set * @link http://php.net/manual/en/arrayaccess.offsetset.php * @param mixed $offset* The offset to assign the value to. *
* @param mixed $value* The value to set. *
* @return void * @throws InvalidArgumentException * @since 5.0.0 */ public function offsetSet($offset, $value) { if ($value instanceof ExtraField) { assert($offset == $value::getHeaderId()); $this->add($value); } else { throw new InvalidArgumentException('value is not instanceof ' . ExtraField::class); } } /** * Offset to unset * @link http://php.net/manual/en/arrayaccess.offsetunset.php * @param mixed $offset* The offset to unset. *
* @return void * @since 5.0.0 */ public function offsetUnset($offset) { $this->remove($offset); } /** * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. * @since 5.0.0 */ public function current() { return current($this->collection); } /** * Move forward to next element * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. * @since 5.0.0 */ public function next() { next($this->collection); } /** * Return the key of the current element * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ public function key() { return key($this->collection); } /** * Checks if current position is valid * @link http://php.net/manual/en/iterator.valid.php * @return boolean The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. * @since 5.0.0 */ public function valid() { return $this->offsetExists($this->key()); } /** * Rewind the Iterator to the first element * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. * @since 5.0.0 */ public function rewind() { reset($this->collection); } /** * If clone extra fields. */ public function __clone() { foreach ($this->collection as $k => $v) { $this->collection[$k] = clone $v; } } }