Chris@0: metadata[$spec] = $value; Chris@0: return $this; Chris@0: } Chris@12: if (! is_array($spec) && ! $spec instanceof Traversable) { Chris@0: throw new Exception\InvalidArgumentException(sprintf( Chris@0: 'Expected a string, array, or Traversable argument in first position; received "%s"', Chris@0: (is_object($spec) ? get_class($spec) : gettype($spec)) Chris@0: )); Chris@0: } Chris@0: foreach ($spec as $key => $value) { Chris@0: $this->metadata[$key] = $value; Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieve all metadata or a single metadatum as specified by key Chris@0: * Chris@0: * @param null|string|int $key Chris@0: * @param null|mixed $default Chris@0: * @throws Exception\InvalidArgumentException Chris@0: * @return mixed Chris@0: */ Chris@0: public function getMetadata($key = null, $default = null) Chris@0: { Chris@0: if (null === $key) { Chris@0: return $this->metadata; Chris@0: } Chris@0: Chris@12: if (! is_scalar($key)) { Chris@0: throw new Exception\InvalidArgumentException('Non-scalar argument provided for key'); Chris@0: } Chris@0: Chris@0: if (array_key_exists($key, $this->metadata)) { Chris@0: return $this->metadata[$key]; Chris@0: } Chris@0: Chris@0: return $default; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Set message content Chris@0: * Chris@0: * @param mixed $value Chris@0: * @return Message Chris@0: */ Chris@0: public function setContent($value) Chris@0: { Chris@0: $this->content = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get message content Chris@0: * Chris@0: * @return mixed Chris@0: */ Chris@0: public function getContent() Chris@0: { Chris@0: return $this->content; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function toString() Chris@0: { Chris@0: $request = ''; Chris@0: foreach ($this->getMetadata() as $key => $value) { Chris@0: $request .= sprintf( Chris@0: "%s: %s\r\n", Chris@0: (string) $key, Chris@0: (string) $value Chris@0: ); Chris@0: } Chris@0: $request .= "\r\n" . $this->getContent(); Chris@0: return $request; Chris@0: } Chris@0: }