Lines Matching refs:message

32      * Gets an array of header line values from a message for a specific header
34 * This method searches through the "headers" key of a message for a header
37 * @param array $message Request or response hash.
42 public static function headerLines($message, $header)
46 if (!empty($message['headers'])) {
47 foreach ($message['headers'] as $name => $value) {
58 * Gets a header value from a message as a string or null
60 * This method searches through the "headers" key of a message for a header
64 * @param array $message Request or response hash.
69 public static function header($message, $header)
71 $match = self::headerLines($message, $header);
76 * Returns the first header value from a message as a string or null. If
80 * @param array $message Request or response hash.
85 public static function firstHeader($message, $header)
87 if (!empty($message['headers'])) {
88 foreach ($message['headers'] as $name => $value) {
101 * Returns true if a message has the provided case-insensitive header.
103 * @param array $message Request or response hash.
108 public static function hasHeader($message, $header)
110 if (!empty($message['headers'])) {
111 foreach ($message['headers'] as $name => $value) {
143 * Removes a header from a message using a case-insensitive comparison.
145 * @param array $message Message that contains 'headers'
150 public static function removeHeader(array $message, $header)
152 if (isset($message['headers'])) {
153 foreach (array_keys($message['headers']) as $key) {
155 unset($message['headers'][$key]);
160 return $message;
166 * @param array $message Message that contains 'headers'
172 public static function setHeader(array $message, $header, array $value)
174 $message = self::removeHeader($message, $header);
175 $message['headers'][$header] = $value;
177 return $message;
219 * Reads the body of a message into a string.
221 * @param array|FutureArrayInterface $message Array containing a "body" key
226 public static function body($message)
228 if (!isset($message['body'])) {
232 if ($message['body'] instanceof StreamInterface) {
233 return (string) $message['body'];
236 switch (gettype($message['body'])) {
238 return $message['body'];
240 return stream_get_contents($message['body']);
242 if ($message['body'] instanceof \Iterator) {
243 return implode('', iterator_to_array($message['body']));
244 } elseif (method_exists($message['body'], '__toString')) {
245 return (string) $message['body'];
249 . self::describeType($message['body']));
254 * Rewind the body of the provided message if possible.
256 * @param array $message Message that contains a 'body' field.
260 public static function rewindBody($message)
262 if ($message['body'] instanceof StreamInterface) {
263 return $message['body']->seek(0);
266 if ($message['body'] instanceof \Generator) {
270 if ($message['body'] instanceof \Iterator) {
271 $message['body']->rewind();
275 if (is_resource($message['body'])) {
276 return rewind($message['body']);
279 return is_string($message['body'])
280 || (is_object($message['body'])
281 && method_exists($message['body'], '__toString'));