Completed
Push — feature/middleware ( f1ca06...1ed36f )
by Romain
02:16
created

AbstractFormObjectBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 70
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormDefinitionObject() 0 7 1
A process() 0 3 1
getFormDefinition() 0 1 ?
B getStaticInstance() 0 28 1
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\FormObject\Builder;
15
16
use Romm\Formz\Core\Core;
17
use Romm\Formz\Form\Definition\FormDefinition;
18
use Romm\Formz\Form\FormObject\Definition\FormDefinitionObject;
19
use Romm\Formz\Form\FormObject\FormObjectStatic;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
abstract class AbstractFormObjectBuilder implements FormObjectBuilderInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    protected $className;
28
29
    /**
30
     * @var FormObjectStatic
31
     */
32
    protected $static;
33
34
    /**
35
     * @param string $className
36
     * @return FormObjectStatic
37
     */
38
    public function getStaticInstance($className)
39
    {
40
        $this->className = $className;
41
42
        $formDefinitionObject = $this->getFormDefinitionObject();
43
44
        $this->static = Core::instantiate(
45
            FormObjectStatic::class,
46
            $this->className,
47
            $formDefinitionObject
48
        );
49
50
        $this->process();
51
52
//        $middleware = $this->static->getDefinition()->addMiddleware(
53
//            'test',
54
//            \Romm\FormzExample\Middlewares\TestMiddleware::class,
55
//            function (\Romm\FormzExample\Middlewares\Options\TestOptions $options) {
56
//                $options->setFoo('pouet');
57
//            }
58
//        );
59
//        debug($middleware);
60
//        die('!!');
61
62
        $formDefinitionObject->refreshValidationResult();
63
64
        return $this->static;
65
    }
66
67
    /**
68
     * @return FormDefinitionObject
69
     */
70
    protected function getFormDefinitionObject()
71
    {
72
        /** @var FormDefinitionObject $formDefinitionObject */
73
        $formDefinitionObject = GeneralUtility::makeInstance(FormDefinitionObject::class, $this->getFormDefinition());
74
75
        return $formDefinitionObject;
76
    }
77
78
    /**
79
     * Override this function in child classes to implement custom processes.
80
     */
81
    protected function process()
82
    {
83
    }
84
85
    /**
86
     * Must return the form definition of the form class.
87
     *
88
     * @return FormDefinition
89
     */
90
    abstract public function getFormDefinition();
91
}
92