Completed
Push — 4-cactus ( 55a524...a97d34 )
by Alberto
15s queued 11s
created

Media::_getMediaUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2017 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
14
namespace BEdita\Core\Model\Entity;
15
16
use Cake\Utility\Hash;
17
18
/**
19
 * Media Entity
20
 *
21
 * @property int $id
22
 * @property string $name
23
 * @property string $provider
24
 * @property string $provider_uid
25
 * @property string $provider_url
26
 * @property string $provider_thumbnail
27
 * @property array $provider_extra
28
 * @property \BEdita\Core\Model\Entity\Stream[] $streams
29
 */
30
class Media extends ObjectEntity
31
{
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function __construct(array $properties = [], array $options = [])
36
    {
37
        parent::__construct($properties, $options);
38
39
        // Virtual properties.
40
        $this->setVirtual(['media_url'], true);
41
        $this->setAccess('media_url', false);
42
    }
43
44
    /**
45
     * Getter for media url.
46
     *
47
     * @return string|null
48
     */
49
    protected function _getMediaUrl()
50
    {
51
        $stream = Hash::get((array)$this->get('streams'), '0');
52
        if (empty($stream)) {
53
            return null;
54
        }
55
56
        return $stream->get('url');
57
    }
58
}
59