* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Mime
*/
-class Horde_Mime_Part implements Countable
+class Horde_Mime_Part implements ArrayAccess, Countable
{
/* The character(s) used internally for EOLs. */
const EOL = "\n";
return $out;
}
+ /* ArrayAccess methods. */
+
+ public function offsetExists($offset)
+ {
+ return ($this->getPart($offset) !== null);
+ }
+
+ public function offsetGet($offset)
+ {
+ return $this->getPart($offset);
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ $this->alterPart($offset, $value);
+ }
+
+ public function offsetUnset($offset)
+ {
+ $this->removePart($offset);
+ }
+
/* Countable methods. */
/**
);
}
+ public function testArrayAccessImplementation()
+ {
+ $part = $this->_getTestPart();
+
+ $this->assertEquals(
+ true,
+ isset($part['1'])
+ );
+ $this->assertEquals(
+ false,
+ isset($part['4'])
+ );
+
+ $this->assertSame(
+ $part->getPart('1'),
+ $part['1']
+ );
+ $this->assertSame(
+ $part->getPart('3.1'),
+ $part['3.1']
+ );
+
+ $part2 = new Horde_Mime_Part();
+ $part2->setType('text/plain');
+
+ $part['2'] = $part2;
+ $this->assertSame(
+ $part2,
+ $part->getPart('2')
+ );
+
+ unset($part['3']);
+ $this->assertEquals(
+ null,
+ $part->getPart('3')
+ );
+ }
+
public function testCountableImplementation()
{
$part = $this->_getTestPart();