-
Notifications
You must be signed in to change notification settings - Fork 699
/
Copy pathtest.php
47 lines (39 loc) · 1.25 KB
/
test.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
<?php
/**
* 结构型模式
*
* php过滤器模式
* 使用不同的标准来过滤一组对象,说实话没明白该模式的意义,忘你留言补充讲解
*
*
* @author TIGERB <https://github.com/TIGERB>
* @example 运行 php test.php
*/
// 注册自加载
spl_autoload_register('autoload');
function autoload($class)
{
require dirname($_SERVER['SCRIPT_FILENAME']) . '//..//' . str_replace('\\', '/', $class) . '.php';
}
/************************************* test *************************************/
use filter\SportsPerson;
use filter\FilterSportType;
use filter\FilterGender;
try {
// 定义一组运动员
$persons = [];
$persons[] = new SportsPerson('male', 'basketball');
$persons[] = new SportsPerson('female', 'basketball');
$persons[] = new SportsPerson('male', 'football');
$persons[] = new SportsPerson('female', 'football');
$persons[] = new SportsPerson('male', 'swim');
$persons[] = new SportsPerson('female', 'swim');
// 按过滤男性
$filterGender = new FilterGender('male');
var_dump($filterGender->filter($persons));
// 过滤运动项目篮球
$filterSportType = new FilterSportType('basketball');
var_dump($filterSportType->filter($persons));
} catch (\Exception $e) {
echo $e->getMessage();
}