forked from TIGERB/easy-tips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolder.php
More file actions
96 lines (88 loc) · 1.55 KB
/
Copy pathFolder.php
File metadata and controls
96 lines (88 loc) · 1.55 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
95
96
<?php
namespace composite;
/**
* 文件夹实体
*/
class Folder implements CompositeInterface
{
/**
* 对象组合
* @var array
*/
private $_composite = [];
/**
* 文件夹名称
* @var string
*/
private $_name = '';
/**
* 构造函数
*
* @param string $name
*/
public function __construct($name='')
{
$this->_name = $name;
}
/**
* 魔法函数
* @param string $name 属性名称
* @return mixed
*/
public function __get($name='')
{
$name = '_' . $name;
return $this->$name;
}
/**
* 增加一个节点对象
*
* @return void
*/
public function add(CompositeInterface $composite)
{
if (in_array($composite, $this->_composite, true)) {
return;
}
$this->_composite[] = $composite;
}
/**
* 删除节点一个对象
*
* @return void
*/
public function delete(CompositeInterface $composite)
{
$key = array_search($composite, $this->_composite, true);
if (!$key) {
throw new Exception("not found", 404);
}
unset($this->_composite[$key]);
$this->_composite = array_values($this->_composite);
}
/**
* 打印对象组合
*
* @return void
*/
public function printComposite()
{
foreach ($this->_composite as $v) {
if ($v instanceof Folder) {
echo '---' . $v->name . "---\n";
$v->printComposite();
continue;
}
echo $v->name . "\n";
}
}
/**
* 实体类要实现的方法
*
* @return mixed
*/
public function operation()
{
return;
}
}