-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotification.php
More file actions
94 lines (81 loc) · 2.31 KB
/
Copy pathNotification.php
File metadata and controls
94 lines (81 loc) · 2.31 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
85
86
87
88
89
90
91
92
93
94
<?php namespace Yoozi\Notification;
use Closure;
use Yoozi\Notification\Contracts\Notifiable;
/**
* Define how we deal with a notificiation message.
*
*
* @author Saturn <yangg.hu@yoozi.cn>
* @copyright 2013 Yoozi Information Technology Co., Ltd.
*/
class Notification {
/**
* Holds the transport handle.
*
* @var \Yoozi\Notification\Contracts\Notifiable
*/
protected $transport;
/**
* Holds the transport message handle.
*
* @var mixed
*/
protected $message;
/**
* Set the transport to drive the notification.
*
* @param \Yoozi\Notification\Contracts\Notifiable
* @param mixed The concrete message instance.
*/
public function __construct(Notifiable $transport, $message)
{
$this->transport = $transport;
$this->message = $message;
}
/**
* Send the actual message to the recipient.
*
* @param string Type of the notification.
* @param \Closure Closure to set the messages.
* @return mixed
*/
public function send($type, Closure $callback = null)
{
if ( ! $this->transport->isValid($type))
{
throw new \RuntimeException("Invalid notification type $type. Miss type definition?", 1);
}
// It's handy to set a default subject for the message when using realtime
// notification API.
$this->message->subject($type);
return $this->transport->send($callback ? call_user_func($callback, $this->message) : $this->message);
}
/**
* Dynamically pass missing methods to the transport instance.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
$callable = array($this->transport, $method);
return call_user_func_array($callable, $parameters);
}
/**
* Dynamically set attributes on the transport instance.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function __set($key, $value)
{
$method = 'set' . ucfirst($key);
if (method_exists($this->transport, $method))
{
return $this->transport->$method($value);
}
$this->transport->$key = $value;
}
}