Overview
  • Namespace
  • Class

Namespaces

  • Slack
    • Message

Classes

  • Slack\ApiClient
  • Slack\Bot
  • Slack\Channel
  • Slack\ClientObject
  • Slack\DataObject
  • Slack\DirectMessageChannel
  • Slack\Group
  • Slack\Message\Attachment
  • Slack\Message\AttachmentBuilder
  • Slack\Message\AttachmentField
  • Slack\Message\Message
  • Slack\Message\MessageBuilder
  • Slack\Payload
  • Slack\RealTimeClient
  • Slack\Team
  • Slack\User

Interfaces

  • Slack\ChannelInterface
  • Slack\Exception

Exceptions

  • Slack\ApiException
  • Slack\ConnectionException
  • Slack\UserNotFoundException
  1 <?php
  2 namespace Slack;
  3 
  4 /**
  5  * Stores incoming or outgoing message data for a Slack API call.
  6  */
  7 class Payload implements \ArrayAccess, \JsonSerializable
  8 {
  9     /**
 10      * @var array The response data.
 11      */
 12     protected $data;
 13 
 14     /**
 15      * Creates a response object from a JSON message.
 16      *
 17      * @param string $json A JSON string.
 18      *
 19      * @return Response The parsed response.
 20      */
 21     public static function fromJson($json)
 22     {
 23         $data = json_decode((string)$json, true);
 24 
 25         if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) {
 26             throw new \UnexpectedValueException('Invalid JSON message.');
 27         }
 28 
 29         return new static($data);
 30     }
 31 
 32     /**
 33      * Creates a new payload object.
 34      *
 35      * @param array $data The payload data.
 36      */
 37     public function __construct($data)
 38     {
 39         $this->data = $data;
 40     }
 41 
 42     /**
 43      * Gets the payload data.
 44      *
 45      * @return array The payload data.
 46      */
 47     public function getData()
 48     {
 49         return $this->data;
 50     }
 51 
 52     /**
 53      * Serializes the payload to a JSON message.
 54      *
 55      * @return string A JSON message.
 56      */
 57     public function toJson()
 58     {
 59         return json_encode($this->data, true);
 60     }
 61 
 62     /**
 63      * @param mixed $offset
 64      * @param mixed $value
 65      */
 66     public function offsetSet($offset, $value)
 67     {
 68         if (is_null($offset)) {
 69             $this->data[] = $value;
 70         } else {
 71             $this->data[$offset] = $value;
 72         }
 73     }
 74 
 75     /**
 76      * @param mixed $offset
 77      * @return bool
 78      */
 79     public function offsetExists($offset)
 80     {
 81         return isset($this->data[$offset]);
 82     }
 83 
 84     /**
 85      * @param mixed $offset
 86      */
 87     public function offsetUnset($offset)
 88     {
 89         unset($this->data[$offset]);
 90     }
 91 
 92     /**
 93      * @param mixed $offset
 94      * @return null
 95      */
 96     public function offsetGet($offset)
 97     {
 98         return isset($this->data[$offset]) ? $this->data[$offset] : null;
 99     }
100 
101     /**
102      * @return array
103      */
104     public function jsonSerialize()
105     {
106         return $this->data;
107     }
108 
109     /**
110      * @return string
111      */
112     public function __toString()
113     {
114         return $this->toJson();
115     }
116 }
117 
API documentation generated by ApiGen