-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFontAwesome5Component.php
66 lines (58 loc) · 1.98 KB
/
FontAwesome5Component.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
<?php
/**
* Class Fontawesome5Component
*
* Include this component in your application configuration, and make sure it is a preloaded
* component, and it makes sure your Font Awesome v5.x assets are published for you.
*
* This component is inspired by this extension created by Tomasz Trejderowski:
* @link https://www.yiiframework.com/extension/fontawesome
*
* @author Paal Gammelsaeter
*/
class FontAwesome5Component extends CApplicationComponent {
/**
* If component should publish the assets. If not set, it will be published if
* application is not console.
* @var bool
*/
public $publish;
/**
* If minified version should be used, defaults to true.
* @var bool
*/
public $minified = true;
/**
* The path of the assets if they were published.
* @var string
*/
protected $publishedAssetsPath;
public function init() {
// Setting new path alias for fontawesome
if (Yii::getPathOfAlias('fontawesome') === false) {
Yii::setPathOfAlias('fontawesome', dirname(__FILE__));
}
// If publish is not set, then set to false if running in console, elsewise true
if (!isset($this->publish)) {
$this->publish = (!Yii::app() instanceof CConsoleApplication);
}
if ($this->publish) {
$filename = $this->minified ? 'all.min.css' : 'all.css';
Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl() . '/css/'.$filename);
}
}
/**
* The path of the assets
* @return CList|mixed
*/
public function getAssetsUrl() {
if (!isset($this->publishedAssetsPath)) {
$assetsSourcePath = Yii::getPathOfAlias('fontawesome.assets');
$publishedAssetsPath = Yii::app()->assetManager->publish($assetsSourcePath, false, -1);
return $this->publishedAssetsPath = $publishedAssetsPath;
}
else {
return $this->publishedAssetsPath;
}
}
}