-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssets.php
More file actions
89 lines (65 loc) · 1.75 KB
/
Assets.php
File metadata and controls
89 lines (65 loc) · 1.75 KB
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
87
88
89
<?
namespace cw\wp;
class Assets{
use \cw\php\core\traits\Singleton;
protected $_view;
public function theme(){
return Theme::getInstance();
}
public function scripts(){
return assets\Scripts::getInstance();
}
public function styles(){
return assets\Styles::getInstance();
}
public function view(\cw\wp\View $view = null){
if($view === null)
return $this->_view;
$this->_view = $view;
return $this;
}
public function expand($uri){
if(strpos($uri, '://') !== false
|| strpos($uri, '//') === 0)
return $uri;
if($this->version)
$uri = str_replace('{{version}}', $this->version, $uri);
return get_stylesheet_directory_uri() . '/' . $uri;
}
public function expandPath($uri){
if(strpos($uri, '://') !== false
|| strpos($uri, '//') === 0)
return $uri;
if($this->version)
$uri = str_replace('{{version}}', $this->version, $uri);
return get_stylesheet_directory() . '/' . $uri;
}
function getContent($relativePathOrUri){
return file_get_contents($this->expandPath($relativePathOrUri));
}
// for detecting whether to load default assets or not
private $published = false;
public function published($set=null){
if($set === null)
return $this->published;
$this->published = !!$set;
return $this;
}
protected $defaultCallable;
public function setDefault($callable){
$this->defaultCallable = $callable;
}
public function publishDefault(){
if(!is_callable($this->defaultCallable))
return ;
$tmp = $this->defaultCallable;
$tmp($this);
}
private $version = null;
public function version($set=null){
if($set === null)
return $this->version;
$this->version = $set;
return $this;
}
}