forked from jkapuscik2/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
32 lines (22 loc) · 853 Bytes
/
demo.php
File metadata and controls
32 lines (22 loc) · 853 Bytes
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
<?php
namespace Behavioral\Iterator;
require(__DIR__ . '/../../vendor/autoload.php');
$john = new CompanyEmployeeTeam(new Employee("John", 'Director'));
$tom = new CompanyEmployeeTeam(new Employee("Tom", 'Developer'));
$johny = new CompanyEmployeeTeam(new Employee("Johny", 'Developer'));
$ceo = new CompanyEmployeeTeam(new Employee("Mark", "CEO"));
$john->addSubordinate($tom);
$john->addSubordinate($johny);
$ceo->addSubordinate($john);
showTeam($ceo);
$jan = new CompanyEmployeeTeam(new Employee("Jan", 'Developer'));
$ceo->addSubordinate($jan);
showTeam($ceo);
$ceo->removeSubordinate($jan);
showTeam($ceo);
function showTeam ($users) {
foreach ($users as $user) {
echo $user->getPosition() . ": " . $user->getName() . PHP_EOL;
}
echo "Number of subordinates of " . $users->getName() . ": " . count($users) . PHP_EOL;
}