Completed
Push — master ( 058435...d3162a )
by Patrick
02:34
created

Entity::readOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Builders;
4
5
use Doctrine\ORM\Mapping\ClassMetadataInfo;
6
7
class Entity extends AbstractBuilder
8
{
9
    /**
10
     * @param string $class
11
     *
12
     * @return Entity
13
     */
14
    public function setRepositoryClass($class)
15
    {
16
        $this->builder->setCustomRepositoryClass($class);
17
18
        return $this;
19
    }
20
21
    /**
22
     * @return Entity
23
     */
24
    public function readOnly()
25
    {
26
        $this->builder->setReadOnly();
27
28
        return $this;
29
    }
30
31
    /**
32
     * Enables second-level cache on this entity.
33
     * If you want to enable second-level cache,
34
     * you must enable it on the EntityManager configuration.
35
     * Depending on the cache mode selected, you may also need to configure
36
     * lock modes.
37
     *
38
     * @param int         $usage  Cache mode. use ClassMetadataInfo::CACHE_USAGE_* constants.
39
     *                            Defaults to READ_ONLY mode.
40
     * @param string|null $region The cache region to be used. Doctrine will use a default region
41
     *                            for each entity, if none is provided.
42
     *
43
     * @return Entity
44
     * @see http://doctrine-orm.readthedocs.org/en/latest/reference/second-level-cache.html
45
     */
46
    public function cacheable($usage = ClassMetadataInfo::CACHE_USAGE_READ_ONLY, $region = null)
47
    {
48
        $meta = $this->builder->getClassMetadata();
49
        $meta->enableCache(compact('usage', $region === null ?: 'region'));
50
51
        return $this;
52
    }
53
}
54