Test Failed
Push — develop ( c3d980...50f9bb )
by nguereza
02:14
created

HomeAction::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
namespace Platine\Framework\Demo;
4
5
use Platine\Cache\CacheInterface;
6
use Platine\Config\Config;
7
use Platine\Cookie\CookieManagerInterface;
8
use Platine\Framework\App\Application;
9
use Platine\Framework\Demo\Repository\UserRepository;
10
use Platine\Http\Handler\RequestHandlerInterface;
11
use Platine\Http\ResponseInterface;
12
use Platine\Http\ServerRequestInterface;
13
use Platine\Logger\LoggerInterface;
14
use Platine\Session\Session;
15
use Platine\Template\Template;
16
17
/**
18
 * Description of HomeAction
19
 *
20
 * @author tony
21
 */
22
class HomeAction implements RequestHandlerInterface
23
{
24
25
    protected LoggerInterface $logger;
26
    protected Application $app;
27
    protected Config $config;
28
    protected Session $session;
29
    protected UserRepository $userRepository;
30
    protected Template $template;
31
    protected CookieManagerInterface $cookieManager;
32
    protected CacheInterface $cache;
33
34
35
    public function __construct(
36
        LoggerInterface $logger,
37
        Application $app,
38
        Config $config,
39
        Session $session,
40
        Template $template,
41
        UserRepository $userRepository,
42
        CookieManagerInterface $cookieManager,
43
        CacheInterface $cache
44
    ) {
45
        $this->logger = $logger;
46
        $this->app = $app;
47
        $this->config = $config;
48
        $this->session = $session;
49
        $this->userRepository = $userRepository;
50
        $this->template = $template;
51
        $this->cookieManager = $cookieManager;
52
        $this->cache = $cache;
53
    }
54
55
    public function handle(ServerRequestInterface $request): ResponseInterface
56
    {
57
        $user = $this->session->get('user');
58
        if (!$user) {
59
            $this->logger->info('User ot yet login');
60
61
            return (new RedirectResponse('login'))->redirect();
62
        }
63
64
        return new TemplateResponse(
65
            $this->template,
66
            'home',
67
            [
68
                'user' => $user,
69
            ]
70
        );
71
    }
72
}
73