1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @see https://github.com/zendframework/zend-view for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-view/blob/master/LICENSE.md New BSD License
*/
namespace Zend\View\Helper;
use Zend\View\Exception;
/**
* View helper plugin to fetch asset from resource map.
*/
class Asset extends AbstractHelper
{
/**
* @var array
*/
protected $resourceMap = [];
/**
* @param string $asset
* @return string
* @throws Exception\InvalidArgumentException
*/
public function __invoke($asset)
{
if (! array_key_exists($asset, $this->resourceMap)) {
throw new Exception\InvalidArgumentException('Asset is not defined.');
}
return $this->resourceMap[$asset];
}
/**
* @param array $resourceMap
* @return $this
*/
public function setResourceMap(array $resourceMap)
{
$this->resourceMap = $resourceMap;
return $this;
}
/**
* @return array
*/
public function getResourceMap()
{
return $this->resourceMap;
}
}