Completed
Push — wip/steps ( 4a4cf9...a11a0b )
by Romain
02:37
created

getPersistenceInjectionMiddleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\Form\Definition\Middleware;
15
16
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor;
17
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface;
18
use Romm\ConfigurationObject\Traits\ConfigurationObject\MagicMethodsTrait;
19
use Romm\Formz\Middleware\Item\FormInjection\FormInjectionMiddleware;
20
use Romm\Formz\Middleware\Item\FormValidation\FormValidationMiddleware;
21
use Romm\Formz\Middleware\Item\Persistence\PersistenceFetchingMiddleware;
22
use Romm\Formz\Middleware\Item\Step\StepDispatchingMiddleware;
23
use Romm\Formz\Middleware\Item\Step\StepFetchingMiddleware;
24
use Romm\Formz\Middleware\MiddlewareInterface;
25
26
class PresetMiddlewares implements DataPreProcessorInterface
27
{
28
    use MagicMethodsTrait;
29
30
    /**
31
     * @var \Romm\Formz\Middleware\Item\FormInjection\FormInjectionMiddleware
32
     */
33
    protected $formInjectionMiddleware;
34
35
    /**
36
     * @var \Romm\Formz\Middleware\Item\FormValidation\FormValidationMiddleware
37
     */
38
    protected $formValidationMiddleware;
39
40
    /**
41
     * @var \Romm\Formz\Middleware\Item\Persistence\PersistenceFetchingMiddleware
42
     */
43
    protected $persistenceFetchingMiddleware;
44
45
    /**
46
     * @var \Romm\Formz\Middleware\Item\Step\StepFetchingMiddleware
47
     */
48
    protected $stepFetchingMiddleware;
49
50
    /**
51
     * @var \Romm\Formz\Middleware\Item\Step\StepDispatchingMiddleware
52
     */
53
    protected $stepDispatchingMiddleware;
54
55
    /**
56
     * Returns the full list of preset middlewares.
57
     *
58
     * @return MiddlewareInterface[]
59
     */
60
    public function getList()
61
    {
62
        return get_object_vars($this);
63
    }
64
65
    /**
66
     * Fills middlewares by default (if they are not filled in configuration).
67
     *
68
     * @param DataPreProcessor $processor
69
     */
70
    public static function dataPreProcessor(DataPreProcessor $processor)
71
    {
72
        $data = $processor->getData();
73
74
        foreach (array_keys(get_class_vars(self::class)) as $middleware) {
75
            if (false === isset($data[$middleware])) {
76
                $data[$middleware] = [];
77
            }
78
        }
79
80
        $processor->setData($data);
81
    }
82
83
    /**
84
     * @return FormInjectionMiddleware
85
     */
86
    public function getFormInjectionMiddleware()
87
    {
88
        return $this->formInjectionMiddleware;
89
    }
90
91
    /**
92
     * @return FormValidationMiddleware
93
     */
94
    public function getFormValidationMiddleware()
95
    {
96
        return $this->formValidationMiddleware;
97
    }
98
99
    /**
100
     * @return PersistenceFetchingMiddleware
101
     */
102
    public function getPersistenceFetchingMiddleware()
103
    {
104
        return $this->persistenceFetchingMiddleware;
105
    }
106
107
    /**
108
     * @return StepFetchingMiddleware
109
     */
110
    public function getStepFetchingMiddleware()
111
    {
112
        return $this->stepFetchingMiddleware;
113
    }
114
115
    /**
116
     * @return StepDispatchingMiddleware
117
     */
118
    public function getStepDispatchingMiddleware()
119
    {
120
        return $this->stepDispatchingMiddleware;
121
    }
122
}
123