Completed
Push — middleware-wip ( e0880a...664dc8 )
by Romain
02:51
created

AbstractMiddleware::getBoundSignalName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
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 protected function initialize()
39
    {
40
        // @todo add options handling
41
    }
42
43
    /**
44
     * @return FormObject
45
     */
46
    protected function getFormObject()
47
    {
48
        return $this->state->getFormObject();
49
    }
50
51
    /**
52
     * @return Request
53
     */
54
    protected function getRequest()
55
    {
56
        return $this->state->getRequest();
57
    }
58
59
    /**
60
     * @return Arguments
61
     */
62
    protected function getRequestArguments()
63
    {
64
        return $this->state->getRequestArguments();
65
    }
66
67
    /**
68
     * @return int
69
     */
70
    public function getPriority()
71
    {
72
        return 0;
73
    }
74
75
    /**
76
     * Returns the name of the signal on which this middleware is bound.
77
     *
78
     * @return string
79
     * @throws EntryNotFoundException
80
     */
81
    final public function getBoundSignalName()
82
    {
83
        $interfaces = class_implements($this);
84
85
        foreach ($interfaces as $interface) {
86
            if (in_array(MiddlewareSignal::class, class_implements($interface))) {
87
                return $interface;
88
            }
89
        }
90
91
        throw new EntryNotFoundException('@todo'); // @todo
92
    }
93
}
94