Index::dispatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * File: Index.php
7
 *
8
 * @author Bartosz Kubicki [email protected]>
9
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
10
 */
11
12
namespace LizardMedia\ProductAttachment\Controller\Customer\Attachment;
13
14
use Magento\Customer\Model\Session;
15
use Magento\Customer\Model\Url;
16
use Magento\Framework\App\Action\Action;
17
use Magento\Framework\App\Action\Context;
18
use Magento\Framework\App\RequestInterface;
19
use Magento\Framework\App\ResponseInterface;
20
use Magento\Framework\Exception\NotFoundException;
21
use Magento\Framework\View\Result\Page;
22
use Magento\Framework\View\Result\PageFactory;
23
24
/**
25
 * Class Index
26
 * @package LizardMedia\ProductAttachment\Controller\Customer\Attachment
27
 */
28
class Index extends Action
29
{
30
    /**
31
     * @var Session
32
     */
33
    private $customerSession;
34
35
    /**
36
     * @var Url
37
     */
38
    private $customerUrl;
39
40
    /**
41
     * @var PageFactory
42
     */
43
    private $resultPageFactory;
44
45
    /**
46
     * @param Session $customerSession
47
     * @param Url $customerUrl
48
     * @param Context $context
49
     * @param PageFactory $resultPageFactory
50
     */
51
    public function __construct(
52
        Session $customerSession,
53
        Url $customerUrl,
54
        Context $context,
55
        PageFactory $resultPageFactory
56
    ) {
57
        parent::__construct($context);
58
        $this->customerSession = $customerSession;
59
        $this->customerUrl = $customerUrl;
60
        $this->resultPageFactory = $resultPageFactory;
61
    }
62
63
    /**
64
     * Authenticate customer.
65
     *
66
     * @param RequestInterface $request
67
     * @return ResponseInterface
68
     * @throws NotFoundException
69
     */
70
    public function dispatch(RequestInterface $request)
71
    {
72
        $loginUrl = $this->customerUrl->getLoginUrl();
73
74
        if (!$this->customerSession->authenticate($loginUrl)) {
75
            $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
76
        }
77
78
        return parent::dispatch($request);
79
    }
80
81
    /**
82
     * @return Page
83
     */
84
    public function execute(): Page
85
    {
86
        return $this->resultPageFactory->create();
87
    }
88
}
89