forked from mcrumm/phlack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhlack.php
More file actions
84 lines (73 loc) · 1.95 KB
/
Phlack.php
File metadata and controls
84 lines (73 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Crummy\Phlack;
use Crummy\Phlack\Bridge\Guzzle\PhlackClient;
use Crummy\Phlack\Bridge\Guzzle\Response\MessageResponse;
use Crummy\Phlack\Message\MessageInterface;
use Guzzle\Common\Collection;
class Phlack extends Collection
{
/**
* @param PhlackClient $client
*/
public function __construct(PhlackClient $client)
{
parent::__construct([
'client' => $client,
'builders' => [],
'commands' => [
'send' => 'Send'
],
]);
}
/**
* @param array $config
* @return Phlack
*/
static public function factory(array $config = [ ])
{
return new self(PhlackClient::factory($config));
}
/**
* {@inhertiDoc}
*/
public static function fromConfig(array $config = array(), array $defaults = array(), array $required = array())
{
return new self($config['client']);
}
/**
* @param MessageInterface $message
* @return MessageResponse
*/
public function send(MessageInterface $message)
{
$command = $this['client']->getCommand($this['commands']['send'], $message->jsonSerialize());
return $this['client']->execute($command);
}
/**
* @return Bridge\Guzzle\PhlackClient
*/
public function getClient()
{
return $this['client'];
}
/**
* @return Builder\MessageBuilder
*/
public function getMessageBuilder()
{
if (!isset($this['builders']['message'])) {
$this->setPath('builders/message', new Builder\MessageBuilder());
}
return $this['builders']['message'];
}
/**
* @return Builder\AttachmentBuilder
*/
public function getAttachmentBuilder()
{
if (!isset($this['builders']['attachment'])) {
$this->setPath('builders/attachment', new Builder\AttachmentBuilder());
}
return $this['builders']['attachment'];
}
}