RoutesConfig::modify()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 9.1344
c 0
b 0
f 0
cc 2
nc 1
nop 1
1
<?php
2
3
namespace Scheduler\Web\Radar\Config;
4
5
use Aura\Di\Container;
6
use Aura\Di\ContainerConfig;
7
use Aura\Payload_Interface\PayloadInterface;
8
use Psr\Http\Message\ServerRequestInterface as Request;
9
use Scheduler\Application\Service;
10
use Scheduler\Web\Radar\Input;
11
use Scheduler\Web\Radar\Responder;
12
13
class RoutesConfig extends ContainerConfig
14
{
15
    public function define(Container $di)
16
    {
17
        $di->params[Input\Input::class]["authenticator"] = $di->lazyGet("user.authenticator");
18
        $di->params[Input\GetEmployeeShiftsInput::class]["authenticator"] = $di->lazyGet("user.authenticator");
19
        $di->params[Input\GetShiftsInput::class]["authenticator"] = $di->lazyGet("user.authenticator");
20
21
        $di->params[Service\CreateShift::class]["shiftMapper"] = $di->lazyGet("shift.mapper");
22
        $di->params[Service\GetEmployee::class]["userMapper"] = $di->lazyGet("user.mapper");
23
        $di->params[Service\GetHoursWorkedInWeek::class]["calculator"] = $di->lazyGet("hours.calculator");
24
        $di->params[Service\GetShift::class]["shiftMapper"] = $di->lazyGet("shift.mapper");
25
        $di->params[Service\GetShift::class]["shiftCoworkersFinder"] = $di->lazyGet("shift.coworkers.finder");
26
        $di->params[Service\GetShiftsAssignedToEmployee::class]["shiftMapper"] = $di->lazyGet("shift.mapper");
27
        $di->params[Service\GetShiftsInTimePeriod::class]["shiftMapper"] = $di->lazyGet("shift.mapper");
28
        $di->params[Service\UpdateShift::class]["shiftMapper"] = $di->lazyGet("shift.mapper");
29
        $di->params[Service\UpdateShift::class]["userMapper"] = $di->lazyGet("user.mapper");
30
31
        $di->params[Responder\HoursWorkedSummaryResponder::class]["resource"] = $di->lazyGet("summary.resource");
32
        $di->params[Responder\ShiftResponder::class]["resource"] = $di->lazyGet("shift.resource");
33
        $di->params[Responder\UserResponder::class]["resource"] = $di->lazyGet("user.resource");
34
    }
35
36
    public function modify(Container $di)
37
    {
38
        $adr = $di->get('radar/adr:adr');
39
        $adr->input(Input\Input::class);
40
41
        $adr->get('entry', "/", function ($user) {
42
            $payload = new \Aura\Payload\Payload();
43
44
            if (! $user->isAuthenticated()) {
45
                return $payload->setStatus($payload::NOT_AUTHENTICATED);
46
            }
47
48
            $payload->setStatus($payload::SUCCESS);
49
            $payload->setOutput([
50
                "documentation_url" => "/docs"
51
            ]);
52
53
            return $payload;
54
        })->responder(Responder\ApiProblemResponder::class);
55
56
        $adr->get('get.employee', '/employees/{id}', Service\GetEmployee::class)
57
            ->input(Input\GetEmployeeInput::class)
58
            ->responder(Responder\UserResponder::class);
59
60
        $adr->get('get.employee.shifts', "/employees/{id}/shifts", Service\GetShiftsAssignedToEmployee::class)
61
            ->input(Input\GetEmployeeInput::class)
62
            ->responder(Responder\ShiftResponder::class);
63
64
        $adr->get('get.employee.hours.weekly', "/employees/{id}/hours/weekly", Service\GetHoursWorkedInWeek::class)
65
            ->input(Input\GetEmployeeHoursWeeklyInput::class)
66
            ->responder(Responder\HoursWorkedSummaryResponder::class);
67
68
        $adr->get('get.shifts', "/shifts", Service\GetShiftsInTimePeriod::class)
69
            ->input(Input\GetShiftsInput::class)
70
            ->responder(Responder\ShiftResponder::class);
71
72
        $adr->post('post.shifts', "/shifts", Service\CreateShift::class)
73
            ->input(Input\CreateShiftInput::class)
74
            ->responder(Responder\ShiftResponder::class);
75
76
        $adr->get('get.shift', "/shifts/{id}", Service\GetShift::class)
77
            ->input(Input\GetShiftInput::class)
78
            ->responder(Responder\ShiftResponder::class);
79
80
        $adr->put('put.shifts', "/shifts/{id}", Service\UpdateShift::class)
81
            ->input(Input\UpdateShiftInput::class)
82
            ->responder(Responder\ShiftResponder::class);
83
    }
84
}
85