-
Notifications
You must be signed in to change notification settings - Fork 50
/
builder.php
73 lines (60 loc) · 1.36 KB
/
builder.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
65
66
67
68
69
70
71
72
73
<?php
/**
* Created by PhpStorm.
* User: lock
* Date: 2017/7/15
* Time: 23:44
* 建造者模式也称生成器模式
* 以docker举例
*/
class leader{
/**
* leader 并不知道具体实现细节
* @param BuilderInterface $builder
* @return mixed
*/
public function build(BuilderInterface $builder){
$builder->pullDockerImage();
$builder->createContainer();
$builder->runContainer();
return $builder->getContainer();
}
}
interface BuilderInterface{
/**
* 拉取镜像
* @return mixed
*/
public function pullDockerImage();
/**
* 创建容器
* @return mixed
*/
public function createContainer();
/**
* 运行容器
* @return mixed
*/
public function runContainer();
/**
* 获得这个容器
* @return mixed
*/
public function getContainer();
}
class buildCentOsContainer implements BuilderInterface{
public function pullDockerImage() {
echo 'start pull docker image'.PHP_EOL;
}
public function createContainer() {
echo 'start create container'.PHP_EOL;
}
public function runContainer() {
echo 'run container'.PHP_EOL;
}
public function getContainer() {
echo 'get container'.PHP_EOL;
}
}
$leader = new leader();
$leader->build(new buildCentOsContainer());