Passed
Push — master ( a355c3...d448eb )
by Fabio
07:53
created

TJavaScriptAsset::setUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
/**
3
 * TJavaScriptAsset classes
4
 *
5
 * @author Brad Anderson <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
8
 * @package Prado\Web\Javascripts
9
 */
10
11
namespace Prado\Web\Javascripts;
12
13
use Prado\Web\THttpUtility;
14
15
/**
16
 * TJavaScriptAsset class.
17
 *
18
 * TJavaScriptAsset class is a utility class for passing javascript
19
 * asset files between components of PRADO.  This class contains
20
 * the URL of the asset and whether or not to load it asynchronously.
21
 *
22
 * This renders the html script tag (with or w/o async) via __toString.
23
 *
24
 * @author Brad Anderson <[email protected]>
25
 * @package Prado\Web\Javascripts
26
 * @since 4.2.0
27
 */
28
class TJavaScriptAsset
29
{
30
	protected $_url;
31
	
32
	protected $_async;
33
34
	public function __construct($url, $async = false)
35
	{
36
		$this->_url = $url;
37
		$this->_async = $async;
38
	}
39
40
	public function __toString()
41
	{
42
		$async = $this->getAsync() ? 'async ' : '';
43
		return '<script ' . $async . 'src="' . THttpUtility::htmlEncode($this->getUrl()) . '"></script>';
44
	}
45
46
	public function getUrl()
47
	{
48
		return $this->_url;
49
	}
50
51
	public function setUrl($url)
52
	{
53
		$this->_url = $url;
54
	}
55
56
	public function getAsync()
57
	{
58
		return $this->_async;
59
	}
60
61
	public function setAsync($async)
62
	{
63
		$this->_async = $async;
64
	}
65
}
66