Passed
Push — master ( 883d7f...cc20de )
by Fabio
05:10
created

TPageLoadTime::renderContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * TPageLoadTime class file.
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\UI\WebControls
9
 */
10
 
11
12
namespace Prado\Web\UI\WebControls;
13
14
use Prado\Prado;
15
use Prado\TPropertyValue;
16
17
/**
18
 * TPageLoadTime class.
19
 *
20
 * Writes the amount of time taken from Request start to rendering the contents of this control.
21
 * This is the longest possible time to wait.  Localize the suffix "s" with
22
 * {@link setSecondSuffix} or use PRADO localization.
23
 *
24
 * @author Brad Anderson <[email protected]>
25
 * @package Prado\Web\UI\WebControls
26
 * @since 4.2.0
27
 */
28
class TPageLoadTime extends TLabel
29
{
30
	/**
31
	 * writes the difference in time that the request started to the moment of this method call.
32
	 * @param mixed $writer
33
	 */
34
	public function renderContents($writer)
35
	{
36
		$writer->write(round(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"], 5) . Prado::localize($this->getSecondSuffix()));
37
	}
38
	
39
	/**
40
	 * @return string the string that is appended to the time.  default 's' for seconds.
41
	 */
42
	public function getSecondSuffix()
43
	{
44
		return $this->getViewState('Suffix', 's');
45
	}
46
	
47
	/**
48
	 * @param string $suffix the string that is appended to the time.
49
	 */
50
	public function setSecondSuffix($suffix)
51
	{
52
		$this->setViewState('Suffix', TPropertyValue::ensureString($suffix), 's');
53
	}
54
}
55