Completed
Push — develop ( e58249...8761a6 )
by
unknown
07:04
created

MetaDataProviderTrait::getMetaData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 4
nc 3
nop 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Entity;
12
13
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14
15
/**
16
 * Implementation of \Core\Entity\MetaDataProviderInterface
17
 * 
18
 * @author Mathias Gelhausen <[email protected]>
19
 * @since 0.27
20
 */
21
trait MetaDataProviderTrait
22
{
23
    /**
24
     * The meta data array.
25
     *
26
     * @ODM\Field(type="hash")
27
     * @var array
28
     */
29
    private $metaData = [];
30
31
    public function setMetaData($key, $value)
32
    {
33
        $this->metaData[$key] = $value;
34
35
        return $this;
36
    }
37
    /**
38
     * Get meta data.
39
     *
40
     * Returns the whole meta data array, if no <i>$key</i> is provided.
41
     * Returns <i>$default</i>, if there is no meta data for the provided <i>$key</i>.
42
     *
43
     * @param null|string $key
44
     * @param null|mixed $default
45
     *
46
     * @return array|mixed|null
47
     */
48
    public function getMetaData($key = null, $default = null)
49
    {
50
        if (null === $key) {
51
            return $this->metaData;
52
        }
53
54
        return $this->hasMetaData($key) ? $this->metaData[$key] : $default;
55
    }
56
57
    public function hasMetaData($key)
58
    {
59
        return array_key_exists($key, $this->metaData);
60
    }
61
}