Completed
Push — middleware-wip ( 106169...2ebda9 )
by Romain
02:43
created

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