This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
/
asset.php
86 lines (77 loc) · 1.54 KB
/
asset.php
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Site messaging class
*
* @package Kollection_Message
* @author Lysender
*/
class Kollection_Asset {
/**
* Protocol to use
*
* @var string
*/
protected $_protocol;
/**
* Domain name to use, must no include protocol and trailing slash
*
* @var string
*/
protected $_domain;
/**
* Prefix to prepend to asset URL paths
*
* @var string
*/
protected $_path_prefix;
/**
* Prefix to prepend to asset cannonical URLs
* This is pre-calculated upon initialization
*
* @var string
*/
protected $_asset_prefix;
/**
* Initializes the asset object's configuration
*
* Config keys:
* protocol
* domain
* path_prefix
*
* @param array $config
* @return void
*/
public function __construct(array $config = array())
{
$this->_protocol = Arr::get($config, 'protocol');
$this->_domain = Arr::get($config, 'domain');
$this->_path_prefix = Arr::get($config, 'path_prefix');
// Generate asset prefix
$prefix = '';
if ($this->_domain)
{
if ($this->_protocol)
{
$prefix = $this->_protocol.'://'.$this->_domain;
}
else
{
$prefix = '//'.$this->_domain;
}
}
$this->_asset_prefix = $prefix.$this->_path_prefix;
}
/**
* Returns the asset url based on config
* When using path prefix, trailing slash and leading slash must be
* handled by the developer
*
* @param string $file
* @return string
*/
public function asset_url($file)
{
return $this->_asset_prefix.$file;
}
}