Lines Matching defs:body
219 * Reads the body of a message into a string.
221 * @param array|FutureArrayInterface $message Array containing a "body" key
223 * @return null|string Returns the body as a string or null if not set.
224 * @throws \InvalidArgumentException if a request body is invalid.
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'];
248 throw new \InvalidArgumentException('Invalid request 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.
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'));