From 97ad2cf72d6250a1ecaa06c76177c698221ea66d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 31 Mar 2010 14:25:21 -0500 Subject: [PATCH] CompressedDataPacket implements ArrayAccess --- lib/openpgp.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/openpgp.php b/lib/openpgp.php index c903bae..ab67b71 100644 --- a/lib/openpgp.php +++ b/lib/openpgp.php @@ -706,7 +706,7 @@ class OpenPGP_SecretSubkeyPacket extends OpenPGP_SecretKeyPacket { * * @see http://tools.ietf.org/html/rfc4880#section-5.6 */ -class OpenPGP_CompressedDataPacket extends OpenPGP_Packet { +class OpenPGP_CompressedDataPacket extends OpenPGP_Packet implements IteratorAggregate, ArrayAccess { public $algorithm; /* see http://tools.ietf.org/html/rfc4880#section-9.3 */ static $algorithms = array(0 => 'Uncompressed', 1 => 'ZIP', 2 => 'ZLIB', 3 => 'BZip2'); @@ -733,6 +733,31 @@ class OpenPGP_CompressedDataPacket extends OpenPGP_Packet { $this->data = $this->data->packets; } } + + // IteratorAggregate interface + + function getIterator() { + return new ArrayIterator($this->data); + } + + // ArrayAccess interface + + function offsetExists($offset) { + return isset($this->data[$offset]); + } + + function offsetGet($offset) { + return $this->data[$offset]; + } + + function offsetSet($offset, $value) { + return is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value; + } + + function offsetUnset($offset) { + unset($this->data[$offset]); + } + } /**