-
Notifications
You must be signed in to change notification settings - Fork 0
/
CleanArchitecture.php
65 lines (63 loc) · 1.64 KB
/
CleanArchitecture.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
<?php
class UserController{
public function store($request){
$input = new UserStoreInput($request);
$not = new EmailNotification();
$useCase = new UserStoreAndEmailNotification($not);
$jsonP = new JsonPresenter();
return $useCase->storAndNotify($input,$jsonP);
}
}
class UserStoreAndEmailNotification{
public function __construct(Notification $notification)
{
$this->notification = $notification;
}
public function storAndNotify($request,Presenter $p)
{
$user = (new User())->make($request);
new UserModel($user)->save();
return $p->parse($user);
}
}
class UserModel{
public function save($data){
// $this->username = $data['username'];
// $this->email = $data['email'];
// $this->age = $data['age'];
// $this->save();
DB::persist($data);
}
}
class User{
public function make($data){
$this->username = $data['username'];
$this->email = $data['email'];
$this->age = $this->getAge();
return $this;
}
public function getAge(){
if($age < 18) throw new Exception('You dont allow');
}
}
interface InputBoundary{
public function make($data);
}
class UserStoreInput implements InputBoundary{
public function make($data)
{
return array_merge($data, bcrypt($data['password']));
}
}
interface Presenter{
public function parse($dataObj);
}
class JsonPresenter implements Presenter {
public function parse($dataObject)
{
return json_encode([
'id' => $dataObject->id,
'username' => $dataObject->username
]);
}
}