-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
78 lines (60 loc) · 2.4 KB
/
app.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
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
#!/usr/bin/env php
<?php
use Src\Domain\Models\Student;
use Src\Infra\Printer\Printer;
use Src\Infra\Repository\StudentRepository;
require_once __DIR__ . '/vendor/autoload.php';
$printer = new Printer();
$studentRepo = new StudentRepository();
$helper = ['--help', '-h'];
$createHelper = ['--create'];
$listHelper = ['--list'];
$printer->display("
██████╗ ██╗ █████╗ ███████╗███████╗
██╔════╝██║ ██╔══██╗██╔════╝██╔════╝
██║ ██║ ███████║███████╗███████╗
██║ ██║ ██╔══██║╚════██║╚════██║
╚██████╗███████╗██║ ██║███████║███████║
╚═════╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝
[*] Author: Thiago thiiagoms
[*] Description: Little CLI crud
[*] Version: 1.0
=> For get help use: --help | -h
$ php app.php --help ");
if (isset($argv[1])) {
if (in_array($argv[1], $helper) !== null) {
return $printer->display("
Args:
--create => create new student
--list => list all students
--remove => remove all students
");
}
if (in_array($argv[1], $createHelper)) {
$printer->display('');
$studentName = readline("[*] Student name: ");
$studentBirthDate = readline("[*] Student birthdate (Y-m-d): ");
$student = new Student(
null,
$studentName,
new \DateTimeImmutable(date('Y-m-d', strtotime($studentBirthDate)))
);
if ($studentRepo->save($student)) {
$printer->display("=> Student {$studentName} registration was a success!");
return;
}
return $printer->display("=> Something wrong hgappened");
}
if (in_array($argv[1], $listHelper)) {
$printer->display("==== List all students ====");
$students = $studentRepo->index();
foreach ($students as $std) {
$printer->display("
[*] Student name: {$std->name()}
[*] Student birthdate: {$std->birthDate()->format('Y-m-d')}
[*] Age: {$std->age()}
");
}
return;
}
}