Completed
Push — middleware-wip ( 093aae...793014 )
by Romain
04:06
created

AbstractMiddleware::initializeMiddleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Middleware\Items;
15
16
use Romm\Formz\Exceptions\EntryNotFoundException;
17
use Romm\Formz\Form\FormObject;
18
use Romm\Formz\Middleware\MiddlewareInterface;
19
use Romm\Formz\Middleware\Signal\MiddlewareSignal;
20
use Romm\Formz\Middleware\State\StateMiddlewareDependencyTrait;
21
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
22
use TYPO3\CMS\Extbase\Mvc\Web\Request;
23
24
abstract class AbstractMiddleware implements MiddlewareInterface
25
{
26
    use StateMiddlewareDependencyTrait;
27
28
    /**
29
     * @param array $options
30
     */
31
    public function __construct(array $options = [])
32
    {
33
    }
34
35
    /**
36
     * @todo
37
     */
38
    final public function initialize()
39
    {
40
        // @todo add options handling
41
42
        $this->initializeMiddleware();
43
    }
44
45
    /**
46
     * @todo
47
     */
48
    protected function initializeMiddleware()
49
    {
50
    }
51
52
    /**
53
     * @return FormObject
54
     */
55
    protected function getFormObject()
56
    {
57
        return $this->state->getFormObject();
58
    }
59
60
    /**
61
     * @return Request
62
     */
63
    protected function getRequest()
64
    {
65
        return $this->state->getRequest();
66
    }
67
68
    /**
69
     * @return Arguments
70
     */
71
    protected function getArguments()
72
    {
73
        return $this->state->getArguments();
74
    }
75
76
    /**
77
     * @return int
78
     */
79
    public function getPriority()
80
    {
81
        return 0;
82
    }
83
84
    /**
85
     * Returns the name of the signal on which this middleware is bound.
86
     *
87
     * @return string
88
     * @throws EntryNotFoundException
89
     */
90
    final public function getBoundSignalName()
91
    {
92
        $interfaces = class_implements($this);
93
94
        foreach ($interfaces as $interface) {
95
            if (in_array(MiddlewareSignal::class, class_implements($interface))) {
96
                return $interface;
97
            }
98
        }
99
100
        throw new EntryNotFoundException('@todo'); // @todo
101
    }
102
}
103