-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry-2.php
More file actions
106 lines (80 loc) · 2.9 KB
/
Copy pathentry-2.php
File metadata and controls
106 lines (80 loc) · 2.9 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
97
98
99
100
101
102
103
104
105
106
<?php
use PHPModules\Demo\Todo::TaskList;
use PHPModules\Demo\Todo::Task;
use PHPModules\Demo\Todo::ListRepository;
require __DIR__ . "/vendor/autoload.php";
echo "=== Todo App — Realistic Workflow ===\n\n";
$repo = new ListRepository();
// ---- Morning ----
echo "--- Morning: Planning the day ---\n\n";
$shopping = new TaskList('Grocery Shopping');
foreach (['Milk', 'Eggs', 'Bread', 'Apples', 'Chicken'] as $item) {
$shopping->addTask(new Task($item));
}
$repo->save($shopping);
printf("Created \"%s\" with %d items\n", $shopping->title(), count($shopping->tasks()));
// ---- Later ----
echo "\n--- Later: Checking things off ---\n";
$milk = $shopping->tasks()[0];
$milk->complete();
printf("Bought milk: %s\n", $milk->completed ? '✓ done' : '○ still needed');
$eggs = $shopping->tasks()[1];
$eggs->complete();
printf("Bought eggs: %s\n", $eggs->completed ? '✓ done' : '○ still needed');
// ---- End of day ----
echo "\n--- End of day: Review ---\n\n";
printf("List: %s\n", $shopping->title());
echo str_repeat('-', 30) . "\n";
foreach ($shopping->tasks() as $t) {
printf(" %s %s\n", $t->completed ? '✓' : '○', $t->title());
}
$done = count(array_filter($shopping->tasks(), fn($t) => $t->completed));
echo str_repeat('-', 30) . "\n";
printf(" %d / %d tasks completed\n\n", $done, count($shopping->tasks()));
// ---- Second list ----
echo "--- Adding a work list ---\n\n";
$work = new TaskList('Work Tasks');
$work->addTask(new Task('Write report'));
$work->addTask(new Task('Review PR'));
$work->addTask(new Task('Deploy release'));
$repo->save($work);
$work->tasks()[2]->complete();
echo "All lists in repository:\n";
foreach ($repo->findAll() as $l) {
$n = count($l->tasks());
$d = count(array_filter($l->tasks(), fn($t) => $t->completed));
printf(" \"%s\" — %d/%d done\n", $l->title(), $d, $n);
}
// ---- Boundary note ----
echo "\n--- Note: Module boundaries stay enforced ---\n\n";
echo "(Uncomment the lines below to see the guards in action)\n";
echo "// \$shopping->reorderTasks(['task_c', 'task_a']); // internal method\n";
echo "// \$milk->completed = false; // internal(set)\n";
echo "\n=== Done ===\n";
/*
=== Todo App — Realistic Workflow ===
--- Morning: Planning the day ---
Created "Grocery Shopping" with 5 items
--- Later: Checking things off ---
Bought milk: ✓ done
Bought eggs: ✓ done
--- End of day: Review ---
List: Grocery Shopping
------------------------------
✓ Milk
✓ Eggs
○ Bread
○ Apples
○ Chicken
------------------------------
2 / 5 tasks completed
--- Adding a work list ---
All lists in repository:
"Grocery Shopping" — 2/5 done
"Work Tasks" — 1/3 done
--- Note: Module boundaries stay enforced ---
(Uncomment the lines below to see the guards in action)
// $shopping->reorderTasks(['task_c', 'task_a']); // internal method
// $milk->completed = false; // internal(set)
=== Done ===
*/