Completed
Pull Request — master (#16)
by Flo
07:29
created

DbService::__construct()   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 1
1
<?php
2
/**
3
 * Class DbService | DbService.php
4
 * @package Faulancer\Service
5
 * @author  Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\Service;
8
9
use ORM\EntityFetcher;
10
use ORM\EntityManager;
11
use Faulancer\ORM\Entity;
12
use Faulancer\ServiceLocator\ServiceInterface;
13
14
/**
15
 * Class DbService
16
 */
17
class DbService implements ServiceInterface
18
{
19
20
    /** @var EntityManager */
21
    protected $entityManager;
22
23
    /**
24
     * ORM constructor.
25
     *
26
     * @param EntityManager $entityManager
27
     */
28
    public function __construct(EntityManager $entityManager)
29
    {
30
        $this->entityManager = $entityManager;
31
    }
32
33
    /**
34
     * @return EntityManager
35
     */
36
    public function getManager()
37
    {
38
        return $this->entityManager;
39
    }
40
41
    /**
42
     * Return the EntityFetcher
43
     *
44
     * @param string       $entity
45
     * @param integer|null $primaryKey
46
     * @return Entity|EntityFetcher
47
     * @codeCoverageIgnore Is covered by tflori/orm
48
     */
49
    public function fetch(string $entity, $primaryKey = null)
50
    {
51
        return $this->entityManager->fetch($entity, $primaryKey);
52
    }
53
54
    /**
55
     * Save an entity
56
     *
57
     * @param Entity $entity
58
     * @codeCoverageIgnore Is covered by tflori/orm
59
     */
60
    public function save(Entity $entity)
61
    {
62
        $entity->save($this->entityManager);
63
    }
64
65
}