-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathProxy2.php
42 lines (34 loc) · 799 Bytes
/
Proxy2.php
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
<?php
/**
* Proxy design pattern (consuming and controlling access to another object)
*
* @author Enrico Zimuel ([email protected])
* @see http://mwop.net/blog/263-Proxies-in-PHP.html
*/
class SomeObject
{
protected $message;
public function __construct($message)
{
$this->message = $message;
}
protected function doSomething() {
return $this->message;
}
}
class Proxy extends SomeObject
{
protected $proxied;
public function __construct(SomeObject $o)
{
$this->proxied = $o;
}
public function doSomething()
{
return ucwords($this->proxied->doSomething());
}
}
// Usage example
$o = new SomeObject('foo bar');
$p = new Proxy($o);
printf("Message from Proxy: %s\n", $p->doSomething());