Completed
Branch GDPR/user-data-export (1838dd)
by
unknown
53:17 queued 40:13
created

AssetCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\services\assets;
4
5
use EventEspresso\core\domain\values\assets\JavascriptAsset;
6
use EventEspresso\core\domain\values\assets\ManifestFile;
7
use EventEspresso\core\domain\values\assets\StylesheetAsset;
8
use EventEspresso\core\exceptions\InvalidInterfaceException;
9
use EventEspresso\core\services\collections\Collection;
10
use EventEspresso\core\domain\values\assets\Asset;
11
12
/**
13
 * Class AssetCollection
14
 * SplObjectStorage Collection of \EventEspresso\core\domain\values\assets\Asset objects
15
 *
16
 * @package EventEspresso\core\services\assets
17
 * @author  Brent Christensen
18
 * @since   $VID:$
19
 */
20
class AssetCollection extends Collection
21
{
22
23
24
    /**
25
     * AssetCollection constructor
26
     *
27
     * @throws InvalidInterfaceException
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
    }
33
34
35
    /**
36
     * @return StylesheetAsset[]
37
     * @since $VID:$
38
     */
39
    public function getStylesheetAssets()
40
    {
41
        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
    }
43
44
45
    /**
46
     * @return JavascriptAsset[]
47
     * @since $VID:$
48
     */
49
    public function getJavascriptAssets()
50
    {
51
        return $this->getAssetsOfType(Asset::TYPE_JS);
52
    }
53
54
55
    /**
56
     * @return ManifestFile[]
57
     * @since $VID:$
58
     */
59
    public function getManifestFiles()
60
    {
61
        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
    }
63
64
65
    /**
66
     * @param $type
67
     * @return array
68
     * @since $VID:$
69
     */
70 View Code Duplication
    protected function getAssetsOfType($type)
71
    {
72
        $files = array();
73
        $this->rewind();
74
        while ($this->valid()) {
75
            /** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76
            $asset = $this->current();
77
            if ($asset->type() === $type) {
78
                $files[ $asset->handle() ] = $asset;
79
            }
80
            $this->next();
81
        }
82
        $this->rewind();
83
        return $files;
84
    }
85
86
87
    /**
88
     * @return JavascriptAsset[]
89
     * @since $VID:$
90
     */
91 View Code Duplication
    public function getJavascriptAssetsWithData()
92
    {
93
        $files = array();
94
        $this->rewind();
95
        while ($this->valid()) {
96
            /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97
            $asset = $this->current();
98
            if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) {
99
                $files[ $asset->handle() ] = $asset;
100
            }
101
            $this->next();
102
        }
103
        $this->rewind();
104
        return $files;
105
    }
106
}
107