-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.php
64 lines (50 loc) · 1.05 KB
/
strategy.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
interface OutputInterface
{
public function load();
}
class SerializedArrayOutput implements OutputInterface
{
public function load($param = array())
{
return serialize($param);
}
}
class JsonStringOutput implements OutputInterface
{
public function load($param = array())
{
return json_encode($param);
}
}
class ArrayOutput implements OutputInterface
{
public function load($param = array())
{
return $param;
}
}
class SomeClient
{
private $output;
public function setOutput(OutputInterface $outputType)
{
$this->output = $outputType;
}
public function loadOutput()
{
return $this->output->load();
}
}
$client = new SomeClient();
$arrData = array(
"le",
"thanh",
"phat",
);
// Want an array?
$client->setOutput(new ArrayOutput());
$data = $client->loadOutput($arrData);
// Want some JSON?
$client->setOutput(new JsonStringOutput());
$data = $client->loadOutput($arrData);