Completed
Push — feature/middleware ( e1fdd7...832bfd )
by Romain
02:33
created

PresetMiddlewares::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\MiddlewareInterface;
22
23
class PresetMiddlewares implements DataPreProcessorInterface
24
{
25
    use MagicMethodsTrait;
26
27
    /**
28
     * @var \Romm\Formz\Middleware\Item\FormInjection\FormInjectionMiddleware
29
     */
30
    protected $formInjectionMiddleware;
31
32
    /**
33
     * @var \Romm\Formz\Middleware\Item\FormValidation\FormValidationMiddleware
34
     */
35
    protected $formValidationMiddleware;
36
37
    /**
38
     * Returns the full list of preset middlewares.
39
     *
40
     * @return MiddlewareInterface[]
41
     */
42
    public function getList()
43
    {
44
        return get_object_vars($this);
45
    }
46
47
    /**
48
     * Fills middlewares by default (if they are not filled in configuration).
49
     *
50
     * @param DataPreProcessor $processor
51
     */
52
    public static function dataPreProcessor(DataPreProcessor $processor)
53
    {
54
        $data = $processor->getData();
55
56
        foreach (array_keys(get_class_vars(self::class)) as $middleware) {
57
            if (false === isset($data[$middleware])) {
58
                $data[$middleware] = [];
59
            }
60
        }
61
62
        $processor->setData($data);
63
    }
64
65
    /**
66
     * @return FormInjectionMiddleware
67
     */
68
    public function getFormInjectionMiddleware()
69
    {
70
        return $this->formInjectionMiddleware;
71
    }
72
73
    /**
74
     * @return FormValidationMiddleware
75
     */
76
    public function getFormValidationMiddleware()
77
    {
78
        return $this->formValidationMiddleware;
79
    }
80
}
81