Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Stdlib / Message.php
blob3e3f1f5be51114276357493a2795993a4b395d50
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Stdlib;
12 use Traversable;
14 class Message implements MessageInterface
16 /**
17 * @var array
19 protected $metadata = array();
21 /**
22 * @var string
24 protected $content = '';
26 /**
27 * Set message metadata
29 * Non-destructive setting of message metadata; always adds to the metadata, never overwrites
30 * the entire metadata container.
32 * @param string|int|array|Traversable $spec
33 * @param mixed $value
34 * @throws Exception\InvalidArgumentException
35 * @return Message
37 public function setMetadata($spec, $value = null)
39 if (is_scalar($spec)) {
40 $this->metadata[$spec] = $value;
41 return $this;
43 if (!is_array($spec) && !$spec instanceof Traversable) {
44 throw new Exception\InvalidArgumentException(sprintf(
45 'Expected a string, array, or Traversable argument in first position; received "%s"',
46 (is_object($spec) ? get_class($spec) : gettype($spec))
47 ));
49 foreach ($spec as $key => $value) {
50 $this->metadata[$key] = $value;
52 return $this;
55 /**
56 * Retrieve all metadata or a single metadatum as specified by key
58 * @param null|string|int $key
59 * @param null|mixed $default
60 * @throws Exception\InvalidArgumentException
61 * @return mixed
63 public function getMetadata($key = null, $default = null)
65 if (null === $key) {
66 return $this->metadata;
69 if (!is_scalar($key)) {
70 throw new Exception\InvalidArgumentException('Non-scalar argument provided for key');
73 if (array_key_exists($key, $this->metadata)) {
74 return $this->metadata[$key];
77 return $default;
80 /**
81 * Set message content
83 * @param mixed $value
84 * @return Message
86 public function setContent($value)
88 $this->content = $value;
89 return $this;
92 /**
93 * Get message content
95 * @return mixed
97 public function getContent()
99 return $this->content;
103 * @return string
105 public function toString()
107 $request = '';
108 foreach ($this->getMetadata() as $key => $value) {
109 $request .= sprintf(
110 "%s: %s\r\n",
111 (string) $key,
112 (string) $value
115 $request .= "\r\n" . $this->getContent();
116 return $request;