Completed
Push — master ( 4f60d6...4d6323 )
by Maxim
03:40
created

AbstractEntityService::getMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\core\entity;
4
5
use WebComplete\core\condition\Condition;
6
7
abstract class AbstractEntityService implements EntityRepositoryInterface
8
{
9
10
    /**
11
     * @var EntityRepositoryInterface
12
     */
13
    protected $repository;
14
15
    /**
16
     * @param EntityRepositoryInterface $repository
17
     */
18
    public function __construct(EntityRepositoryInterface $repository)
19
    {
20
        $this->repository = $repository;
21
    }
22
23
    /**
24
     * Proxy method
25
     * @param \Closure $closure
26
     * @throws \Exception
27
     */
28
    public function transaction(\Closure $closure)
29
    {
30
        return $this->repository->transaction($closure);
31
    }
32
33
    /**
34
     * Proxy method
35
     * @return AbstractEntity
36
     */
37
    public function create(): AbstractEntity
38
    {
39
        return $this->repository->create();
40
    }
41
42
    /**
43
     * Proxy method
44
     *
45
     * @param array $data
46
     * @param array|null $map
47
     *
48
     * @return AbstractEntity
49
     */
50
    public function createFromData(array $data, array $map = null): AbstractEntity
51
    {
52
        return $this->repository->createFromData($data, $map);
53
    }
54
55
    /**
56
     * Proxy method
57
     * @param $id
58
     * @return AbstractEntity|null
59
     */
60
    public function findById($id)
61
    {
62
        return $this->repository->findById($id);
63
    }
64
65
    /**
66
     * Proxy method
67
     * @param Condition $condition
68
     * @return AbstractEntity|null
69
     */
70
    public function findOne(Condition $condition)
71
    {
72
        return $this->repository->findOne($condition);
73
    }
74
75
    /**
76
     * Proxy method
77
     * @param Condition $condition
78
     * @return AbstractEntity[]
79
     */
80
    public function findAll(Condition $condition = null): array
81
    {
82
        return $this->repository->findAll($condition);
83
    }
84
85
    /**
86
     * Proxy method
87
     * @param Condition|null $condition
88
     * @return int
89
     */
90
    public function count(Condition $condition = null): int
91
    {
92
        return $this->repository->count($condition);
93
    }
94
95
    /**
96
     * Proxy method
97
     * @param AbstractEntity $item
98
     */
99
    public function save(AbstractEntity $item)
100
    {
101
        return $this->repository->save($item);
102
    }
103
104
    /**
105
     * Proxy method
106
     * @param $id
107
     */
108
    public function delete($id)
109
    {
110
        return $this->repository->delete($id);
111
    }
112
113
    /**
114
     * @param Condition|null $condition
115
     *
116
     * @return mixed
117
     */
118
    public function deleteAll(Condition $condition = null)
119
    {
120
        return $this->repository->deleteAll($condition);
121
    }
122
123
    /**
124
     * @param string $field
125
     * @param string $key
126
     * @param Condition|null $condition
127
     *
128
     * @return array
129
     */
130
    public function getMap(string $field, string $key = 'id', Condition $condition = null): array
131
    {
132
        return $this->repository->getMap($field, $key, $condition);
133
    }
134
}
135