-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
123 lines (115 loc) · 4.4 KB
/
index.php
File metadata and controls
123 lines (115 loc) · 4.4 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
declare(strict_types = 1);
require_once 'autoload.php';
use \src\useCases\investInTranche\InvestInTranche;
use src\infrastructure\domain\loan\InMemoryLoanRepository;
use src\infrastructure\domain\tranche\InMemoryTrancheRepository;
use src\infrastructure\domain\investor\InMemoryInvestorRepository;
use src\infrastructure\controllers\investInTranche\request\FromJson;
use src\infrastructure\controllers\investInTranche\response\xml\InvestInTrancheResponse;
use \src\infrastructure\framework\routing\Route;
use \src\infrastructure\framework\front\WebFront;
use \src\infrastructure\framework\http\request\HttpMethod;
use \src\infrastructure\framework\http\request\HttpRequestStub;
use \src\infrastructure\framework\http\request\Uri;
use \src\infrastructure\framework\routing\resourceLocation\WithPlaceholders;
use \src\domain\tranche\DefaultTranche;
use \src\domain\tranche\TrancheId;
use \src\domain\loan\LoanId;
use \src\domain\money\currency\Pound;
use \src\domain\money\format\InMinorUnits;
use \src\domain\percentage\format\DefaultPercent;
use \src\infrastructure\framework\http\request\ReceivedHttpRequest;
use \src\domain\loan\DefaultLoan;
use \src\domain\loan\LoanInterval;
use \src\domain\investor\DefaultInvestor;
use \src\domain\investor\InvestorId;
use \src\infrastructure\framework\routing\RouteChain;
use \src\infrastructure\framework\fallback\Fallback;
use \src\infrastructure\framework\fallback\SystemFailure;
use src\infrastructure\framework\WithHeaders;
use \src\domain\language\En;
use \src\infrastructure\framework\http\response\header\ContentLanguage;
use \src\infrastructure\framework\http\response\header\DateHeader;
$trancheRepository = new InMemoryTrancheRepository();
$trancheRepository->add(
new DefaultTranche(
new TrancheId(1), new LoanId(1), new InMinorUnits(0, new Pound()), new InMinorUnits(1000000, new Pound()), new DefaultPercent(7)
)
);
$loanRepository = new InMemoryLoanRepository();
$loanRepository->add(
new DefaultLoan(
new LoanId(1), new LoanInterval(new DateTime('2018-02-01'), new DateTime('2018-02-28'))
)
);
$investorRepository = new InMemoryInvestorRepository();
$investorRepository->add(
new DefaultInvestor(
new InvestorId(1), new InMinorUnits(1000, new Pound())
)
);
try {
(new WithHeaders(
new Fallback(
new RouteChain(
[
new Route(
new WithPlaceholders('/investors/:id/invest'),
new HttpMethod($_SERVER['REQUEST_METHOD']),
new FromJson(
new InvestInTranche(
$loanRepository,
$trancheRepository,
$investorRepository,
new DateTime('now')
),
function (array $data) {
return new InvestInTrancheResponse($data);
}
)
)
]
),
new SystemFailure()
),
[new ContentLanguage([new En()]), new DateHeader(new DateTime('now'))]
))
->act(
new ReceivedHttpRequest()
)
->display()
;
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
}
//(new WebFront(
// new WithDateHeader(
// new Fallback(
// new RouteChain(
// [
// new Route(
// new WithPlaceholders('/investors/:id/invest'),
// new Post(),
// new FromJson(
// new InvestInTranche(
// new InMemoryLoanRepository(),
// new InMemoryTrancheRepository(),
// new InMemoryInvestorRepository(),
// new DateTime('now')
// ),
// function (array $data) {
// return new ToXml($data);
// }
// )
// ),
// ],
// new UrlNotFoundResponse()
// ),
// json_encode(['code' => 'exception', 'System failure. Come back later.'])
// ),
// new DateTime('now')
// )
//))
// ->respond();