|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* hirak/prestissimo |
|
4
|
|
|
* @author Hiraku NAKANO |
|
5
|
|
|
* @license MIT https://github.com/hirak/prestissimo |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace Hirak\Prestissimo\Aspects; |
|
8
|
|
|
|
|
9
|
|
|
use SplSubject; |
|
10
|
|
|
use SplObserver; |
|
11
|
|
|
use SplObjectStorage; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Simple EventDispatcher for extending downloader |
|
15
|
|
|
*/ |
|
16
|
|
|
class JoinPoint implements SplSubject |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var SplObjectStorage */ |
|
19
|
|
|
protected $storage; |
|
20
|
|
|
|
|
21
|
|
|
/** @var HttpGetRequest */ |
|
22
|
|
|
protected $request; |
|
23
|
|
|
|
|
24
|
|
|
/** @var HttpGetResponse */ |
|
25
|
|
|
protected $response; |
|
26
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
protected $name; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $pointName |
|
32
|
|
|
*/ |
|
33
|
6 |
|
public function __construct($pointName, HttpGetRequest $request) |
|
34
|
|
|
{ |
|
35
|
6 |
|
$this->name = $pointName; |
|
36
|
6 |
|
$this->detachAll(); |
|
37
|
6 |
|
$this->request = $request; |
|
38
|
6 |
|
} |
|
39
|
|
|
|
|
40
|
5 |
|
public function attach(SplObserver $observer) |
|
41
|
|
|
{ |
|
42
|
5 |
|
$this->storage->attach($observer); |
|
43
|
5 |
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function attachArray(array $observers) |
|
46
|
|
|
{ |
|
47
|
1 |
|
$storage = $this->storage; |
|
48
|
1 |
|
foreach ($observers as $observer) { |
|
49
|
1 |
|
$storage->attach($observer); |
|
50
|
|
|
} |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function detach(SplObserver $observer) |
|
54
|
|
|
{ |
|
55
|
1 |
|
$this->storage->detach($observer); |
|
56
|
1 |
|
} |
|
57
|
|
|
|
|
58
|
6 |
|
public function detachAll() |
|
59
|
|
|
{ |
|
60
|
6 |
|
$this->storage = new SplObjectStorage; |
|
61
|
6 |
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function notify() |
|
64
|
|
|
{ |
|
65
|
2 |
|
foreach ($this->storage as $observer) { |
|
66
|
2 |
|
$observer->update($this); |
|
67
|
|
|
} |
|
68
|
2 |
|
} |
|
69
|
|
|
|
|
70
|
3 |
|
final public function refRequest() |
|
71
|
|
|
{ |
|
72
|
3 |
|
return $this->request; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function setRequest(HttpGetRequest $req) |
|
76
|
|
|
{ |
|
77
|
1 |
|
$this->request = $req; |
|
78
|
1 |
|
} |
|
79
|
|
|
|
|
80
|
3 |
|
final public function refResponse() |
|
81
|
|
|
{ |
|
82
|
3 |
|
return $this->response; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
3 |
|
public function setResponse(HttpGetResponse $res) |
|
86
|
|
|
{ |
|
87
|
3 |
|
$this->response = $res; |
|
88
|
3 |
|
} |
|
89
|
|
|
|
|
90
|
4 |
|
public function __toString() |
|
91
|
|
|
{ |
|
92
|
4 |
|
return $this->name; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|