Completed
Branch master (5acf81)
by Steevan
04:21
created

EntityOptionsBuilder::setRepositoryMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace steevanb\SymfonyFormOptionsBuilder\OptionsBuilder;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\QueryBuilder;
7
use steevanb\SymfonyFormOptionsBuilder\Behavior\ByReferenceTrait;
8
use steevanb\SymfonyFormOptionsBuilder\Behavior\DataClassTrait;
9
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
10
11
class EntityOptionsBuilder extends AbstractOptionsBuilder
12
{
13
    use Behavior\ChoiceTypeTrait;
14
    use DataClassTrait;
15
    use ByReferenceTrait;
16
17
    /**
18
     * @return string
19
     */
20
    public static function getBuilderType()
21
    {
22
        return EntityType::class;
23
    }
24
25
    /**
26
     * @param string $class
27
     * @return $this
28
     * @link http://symfony.com/doc/current/reference/forms/types/entity.html#class
29
     */
30
    public function setClass($class)
31
    {
32
        return $this->setOption('class', $class);
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getClass()
39
    {
40
        return $this->getOption('class');
41
    }
42
43
    /**
44
     * @param string $em
45
     * @return $this
46
     * @link http://symfony.com/doc/current/reference/forms/types/entity.html#em
47
     */
48
    public function setEm($em)
49
    {
50
        return $this->setOption('em', $em);
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getEm()
57
    {
58
        return $this->getOption('em');
59
    }
60
61
    /**
62
     * @param string $groupBy
63
     * @return $this
64
     * @link http://symfony.com/doc/current/reference/forms/types/entity.html#group-by
65
     */
66
    public function setGroupBy($groupBy)
67
    {
68
        return $this->setOption('group_by', $groupBy);
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getGroupBy()
75
    {
76
        return $this->getOption('group_by');
77
    }
78
79
    /**
80
     * @param QueryBuilder|\Closure $queryBuilder
81
     * @return $this
82
     * @link http://symfony.com/doc/current/reference/forms/types/entity.html#query-builder
83
     */
84
    public function setQueryBuilder($queryBuilder)
85
    {
86
        return $this->setOption('query_builder', $queryBuilder);
87
    }
88
89
    /**
90
     * @return null|QueryBuilder|\Closure
91
     */
92
    public function getQueryBuilder()
93
    {
94
        return $this->getOption('query_builder');
95
    }
96
97
    /**
98
     * @param string $method
99
     * @param array $params
100
     * @return $this
101
     */
102
    public function setRepositoryMethod($method, $params = array())
103
    {
104
        return $this->setOption('query_builder', function (EntityRepository $repository) use ($method, $params) {
105
            return call_user_func(array($repository, $method), $params);
106
        });
107
    }
108
}
109