-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
38 lines (31 loc) · 837 Bytes
/
index.php
File metadata and controls
38 lines (31 loc) · 837 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
33
34
35
36
37
<?php
define('FILENAME', 'data.txt');
require_once 'functions.php';
$data = array_fill(0, 3, null);
$argv = array_replace($data, $argv);
[$filename, $command, $content] = $argv;
switch ($command) {
case 'add':
if (!empty($content)) {
$tasks = add($content);
saveToFile($tasks);
} else {
echo '! Error: Task can\'t be empty.';
}
break;
case 'remove':
$tasks = remove($content);
saveToFile($tasks);
break;
case null:
$tasks = readFromFile();
foreach ($tasks as $number => $task) {
echo ($number + 1) . ' | ' . $task . PHP_EOL;
}
echo '-----' . PHP_EOL . 'All tasks: ' . count($tasks);
break;
default:
echo 'Sorry, invalid command!';
break;
}
echo PHP_EOL;