Maknz\Slack\Attachment::toArray PHP Method

toArray() public method

Convert this attachment to its array representation.
public toArray ( ) : array
return array
    public function toArray()
    {
        $data = ['fallback' => $this->getFallback(), 'text' => $this->getText(), 'pretext' => $this->getPretext(), 'color' => $this->getColor(), 'footer' => $this->getFooter(), 'footer_icon' => $this->getFooterIcon(), 'ts' => $this->getTimestamp() ? $this->getTimestamp()->getTimestamp() : null, 'mrkdwn_in' => $this->getMarkdownFields(), 'image_url' => $this->getImageUrl(), 'thumb_url' => $this->getThumbUrl(), 'title' => $this->getTitle(), 'title_link' => $this->getTitleLink(), 'author_name' => $this->getAuthorName(), 'author_link' => $this->getAuthorLink(), 'author_icon' => $this->getAuthorIcon()];
        $data['fields'] = $this->getFieldsAsArrays();
        $data['actions'] = $this->getActionsAsArrays();
        return $data;
    }

Usage Example

Beispiel #1
0
 public function testAttachmentToArray()
 {
     $now = new DateTime();
     $in = ['fallback' => 'Fallback', 'text' => 'Text', 'pretext' => 'Pretext', 'color' => 'bad', 'footer' => 'Footer', 'footer_icon' => 'https://platform.slack-edge.com/img/default_application_icon.png', 'timestamp' => $now, 'mrkdwn_in' => ['pretext', 'text'], 'image_url' => 'http://fake.host/image.png', 'thumb_url' => 'http://fake.host/image.png', 'title' => 'A title', 'title_link' => 'http://fake.host/', 'author_name' => 'Joe Bloggs', 'author_link' => 'http://fake.host/', 'author_icon' => 'http://fake.host/image.png', 'fields' => [['title' => 'Title 1', 'value' => 'Value 1', 'short' => false], ['title' => 'Title 2', 'value' => 'Value 1', 'short' => false]], 'actions' => [['name' => 'Name 1', 'text' => 'Text 1', 'style' => 'default', 'type' => 'button', 'value' => 'Value 1', 'confirm' => ['title' => 'Title 1', 'text' => 'Text 1', 'ok_text' => 'OK Text 1', 'dismiss_text' => 'Dismiss Text 1']], ['name' => 'Name 2', 'text' => 'Text 2', 'style' => 'default', 'type' => 'button', 'value' => 'Value 2', 'confirm' => ['title' => 'Title 2', 'text' => 'Text 2', 'ok_text' => 'OK Text 2', 'dismiss_text' => 'Dismiss Text 2']]]];
     // Sublte difference with timestamp
     $out = ['fallback' => 'Fallback', 'text' => 'Text', 'pretext' => 'Pretext', 'color' => 'bad', 'footer' => 'Footer', 'footer_icon' => 'https://platform.slack-edge.com/img/default_application_icon.png', 'ts' => $now->getTimestamp(), 'mrkdwn_in' => ['pretext', 'text'], 'image_url' => 'http://fake.host/image.png', 'thumb_url' => 'http://fake.host/image.png', 'title' => 'A title', 'title_link' => 'http://fake.host/', 'author_name' => 'Joe Bloggs', 'author_link' => 'http://fake.host/', 'author_icon' => 'http://fake.host/image.png', 'fields' => [['title' => 'Title 1', 'value' => 'Value 1', 'short' => false], ['title' => 'Title 2', 'value' => 'Value 1', 'short' => false]], 'actions' => [['name' => 'Name 1', 'text' => 'Text 1', 'style' => 'default', 'type' => 'button', 'value' => 'Value 1', 'confirm' => ['title' => 'Title 1', 'text' => 'Text 1', 'ok_text' => 'OK Text 1', 'dismiss_text' => 'Dismiss Text 1']], ['name' => 'Name 2', 'text' => 'Text 2', 'style' => 'default', 'type' => 'button', 'value' => 'Value 2', 'confirm' => ['title' => 'Title 2', 'text' => 'Text 2', 'ok_text' => 'OK Text 2', 'dismiss_text' => 'Dismiss Text 2']]]];
     $a = new Attachment($in);
     $this->assertSame($out, $a->toArray());
 }
All Usage Examples Of Maknz\Slack\Attachment::toArray