Completed
Push — master ( f87c77...be4ea7 )
by Marko
02:11
created

Assets::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 20, 2016 - 9:08:14 PM
5
 * Contact      [email protected]
6
 * @copyright   2016 Marko Kungla - https://github.com/mkungla
7
 * @license     The MIT License (MIT)
8
 * 
9
 * @category       AframeVR
10
 * @package        aframe-php
11
 * 
12
 * Lang         PHP (php version >= 7)
13
 * Encoding     UTF-8
14
 * File         Assets.php
15
 * Code format  PSR-2 and 12
16
 * @link        https://github.com/mkungla/aframe-php
17
 * @issues      https://github.com/mkungla/aframe-php/issues
18
 * ********************************************************************
19
 * Contributors:
20
 * @author Marko Kungla <[email protected]>
21
 * ********************************************************************
22
 * Comments:
23
 * @formatter:on */
24
namespace AframeVR\Core;
25
26
use \AframeVR\Core\Assets\{
27
    AssetAudio,
28
    AssetImage,
29
    AssetItem,
30
    AssetVideo,
31
    Mixin
32
};
33
34
final class Assets
35
{
36
37
    /**
38
     * Array of mixins
39
     *
40
     * @var array
41
     */
42
    protected $assets;
43
44
    /**
45
     * Set assets timeout attribute
46
     * 
47
     * @var int
48
     */
49
    protected $attr_timeout;
50
    
51
    /**
52
     * <a-scene><a-assets><audio>
53
     *
54
     * @param string $id            
55
     * @return \AframeVR\Interfaces\Core\Assets\AssetAudioInterface
56
     */
57 1
    public function audio(string $id = 'untitled'): \AframeVR\Interfaces\Core\Assets\AssetAudioInterface
58
    {
59 1
        return $this->assets[$id] ?? $this->assets[$id] = new AssetAudio($id);
60
    }
61
62
    /**
63
     * <a-scene><a-assets><img>
64
     *
65
     * @param string $id            
66
     * @return \AframeVR\Interfaces\Core\Assets\AssetImageInterface
67
     */
68 1
    public function img(string $id = 'untitled'): \AframeVR\Interfaces\Core\Assets\AssetImageInterface
69
    {
70 1
        return $this->assets[$id] ?? $this->assets[$id] = new AssetImage($id);
71
    }
72
73
    /**
74
     * <a-scene><a-assets><a-asset-item>
75
     *
76
     * @param string $id            
77
     * @return \AframeVR\Interfaces\Core\Assets\AssetItemInterface
78
     */
79 1
    public function item(string $id = 'untitled'): \AframeVR\Interfaces\Core\Assets\AssetItemInterface
80
    {
81 1
        return $this->assets[$id] ?? $this->assets[$id] = new AssetItem($id);
82
    }
83
84
    /**
85
     * <a-scene><a-assets><video>
86
     *
87
     * @param string $id            
88
     * @return \AframeVR\Interfaces\Core\Assets\AssetVideoInterface
89
     */
90 1
    public function video(string $id = 'untitled'): \AframeVR\Interfaces\Core\Assets\AssetVideoInterface
91
    {
92 1
        return $this->assets[$id] ?? $this->assets[$id] = new AssetVideo($id);
93
    }
94
95
    /**
96
     * Mixin which will be directly applied to element usin it
97
     *
98
     * A-Frame PHP does not create <a-mixin>. Instead it is appling
99
     * mixin directly on element using this mixin.
100
     *
101
     * @param string $id            
102
     * @return \AframeVR\Interfaces\Core\Assets\MixinInterface
103
     */
104 2
    public function mixin(string $id = 'untitled'): \AframeVR\Interfaces\Core\Assets\MixinInterface
105
    {
106 2
        return $this->assets[$id] ?? $this->assets[$id] = new Mixin($id);
107
    }
108
109
    /**
110
     * Setting a timeout
111
     *
112
     * @param int $milliseconds            
113
     * @return Assets
114
     */
115 1
    public function timeout(int $milliseconds = 3000)
116
    {
117 1
        $this->attr_timeout = $milliseconds;
118 1
        return $this;
119
    }
120
121
    /**
122
     * Get all assets
123
     *
124
     * @return array|null
125
     */
126 19
    public function getAssets()
127
    {
128 19
        return $this->assets;
129
    }
130
}
131