Completed
Pull Request — master (#119)
by Arnaud
38:04 queued 35:40
created

FormEvent::addForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\AdminBundle\Event\Events;
4
5
use LAG\AdminBundle\Event\AbstractEvent;
6
use LAG\AdminBundle\Exception\Exception;
7
use LAG\AdminBundle\Field\Definition\FieldDefinitionInterface;
8
use Symfony\Component\Form\FormInterface;
9
10
class FormEvent extends AbstractEvent
11
{
12
    /**
13
     * @var FormInterface[]
14
     */
15
    private $forms = [];
16
17
    /**
18
     * @var FieldDefinitionInterface[]
19
     */
20
    private $definitions = [];
21
22
    /**
23
     * @param FormInterface $form
24
     * @param string        $identifier
25
     *
26
     * @throws Exception
27
     */
28
    public function addForm(FormInterface $form, string $identifier)
29
    {
30
        if (array_key_exists($identifier, $this->forms)) {
31
            throw new Exception('A form with the identifier "'.$identifier.'" was already added');
32
        }
33
        $this->forms[$identifier] = $form;
34
    }
35
36
    /**
37
     * @return FormInterface[]
38
     */
39
    public function getForms()
40
    {
41
        return $this->forms;
42
    }
43
44
    public function addFieldDefinition(string $name, FieldDefinitionInterface $definition): void
45
    {
46
        $this->definitions[$name] = $definition;
47
    }
48
49
    public function removeFieldDefinition(string $name): void
50
    {
51
        unset($this->definitions[$name]);
52
    }
53
54
    /**
55
     * @return FieldDefinitionInterface[]
56
     */
57
    public function getFieldDefinitions(): array
58
    {
59
        return $this->definitions;
60
    }
61
}
62