|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Webperf plugin for Craft CMS 3.x |
|
4
|
|
|
* |
|
5
|
|
|
* Monitor the performance of your webpages through real-world user timing data |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2018 nystudio107 |
|
|
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\webperf\models; |
|
12
|
|
|
|
|
13
|
|
|
use nystudio107\retour\validators\DbStringValidator; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
use yii\behaviors\AttributeTypecastBehavior; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
|
|
|
|
|
18
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
19
|
|
|
* @package Webperf |
|
|
|
|
|
|
20
|
|
|
* @since 1.0.0 |
|
|
|
|
|
|
21
|
|
|
*/ |
|
|
|
|
|
|
22
|
|
|
class DataSample extends DbModel |
|
23
|
|
|
{ |
|
24
|
|
|
// Public Properties |
|
25
|
|
|
// ========================================================================= |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
|
|
|
|
|
28
|
|
|
* @var int |
|
29
|
|
|
*/ |
|
30
|
|
|
public $siteId; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
|
|
|
|
|
33
|
|
|
* @var string u - the URL of the User Timing sample |
|
34
|
|
|
*/ |
|
35
|
|
|
public $url; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
|
|
|
|
|
38
|
|
|
* @var int (nt_dns_end - nt_dns_st) in ms |
|
39
|
|
|
*/ |
|
40
|
|
|
public $dns; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
|
|
|
|
|
43
|
|
|
* @var int (nt_con_end - nt_con_st) in ms |
|
44
|
|
|
*/ |
|
45
|
|
|
public $connect; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
|
|
|
|
|
48
|
|
|
* @var int t_resp in ms |
|
49
|
|
|
*/ |
|
50
|
|
|
public $firstByte; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
|
|
|
|
|
53
|
|
|
* @var int pt_fp in ms |
|
54
|
|
|
*/ |
|
55
|
|
|
public $firstPaint; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
|
|
|
|
|
58
|
|
|
* @var int pt_fcp in ms |
|
59
|
|
|
*/ |
|
60
|
|
|
public $firstContentfulPaint; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
|
|
|
|
|
63
|
|
|
* @var int (nt_domint - nt_nav_st) in ms |
|
64
|
|
|
*/ |
|
65
|
|
|
public $domInteractive; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
|
|
|
|
|
68
|
|
|
* @var int (nt_domcomp - nt_nav_st) or t_done in ms |
|
69
|
|
|
*/ |
|
70
|
|
|
public $pageLoad; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
|
|
|
|
|
73
|
|
|
* @var string the country code from the IP address |
|
74
|
|
|
*/ |
|
75
|
|
|
public $countryCode; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
|
|
|
|
|
78
|
|
|
* @var string the browser name |
|
79
|
|
|
*/ |
|
80
|
|
|
public $browser; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
|
|
|
|
|
83
|
|
|
* @var string the operating system |
|
84
|
|
|
*/ |
|
85
|
|
|
public $os; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
|
|
|
|
|
88
|
|
|
* @var bool mobile or non-mobile |
|
89
|
|
|
*/ |
|
90
|
|
|
public $mobile; |
|
91
|
|
|
|
|
92
|
|
|
// Public Methods |
|
93
|
|
|
// ========================================================================= |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
|
|
|
|
|
96
|
|
|
* @inheritdoc |
|
97
|
|
|
*/ |
|
|
|
|
|
|
98
|
|
|
public function rules() |
|
99
|
|
|
{ |
|
100
|
|
|
return [ |
|
101
|
|
|
['siteId', 'integer'], |
|
102
|
|
|
['url', 'required'], |
|
103
|
|
|
['url', DbStringValidator::class, 'max' => 255], |
|
104
|
|
|
['countryCode', DbStringValidator::class, 'max' => 2], |
|
105
|
|
|
['browser', DbStringValidator::class, 'max' => 50], |
|
106
|
|
|
['os', DbStringValidator::class, 'max' => 50], |
|
107
|
|
|
[ |
|
108
|
|
|
[ |
|
109
|
|
|
'url', |
|
110
|
|
|
'countryCode', |
|
111
|
|
|
'browser', |
|
112
|
|
|
'os', |
|
113
|
|
|
], |
|
114
|
|
|
'string' |
|
115
|
|
|
], |
|
116
|
|
|
[ |
|
117
|
|
|
[ |
|
118
|
|
|
'dns', |
|
119
|
|
|
'connect', |
|
120
|
|
|
'firstByte', |
|
121
|
|
|
'firstPaint', |
|
122
|
|
|
'firstContentfulPaint', |
|
123
|
|
|
'domInteractive', |
|
124
|
|
|
'pageLoad', |
|
125
|
|
|
], |
|
126
|
|
|
'integer' |
|
127
|
|
|
], |
|
128
|
|
|
['mobile', 'boolean'], |
|
129
|
|
|
]; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
|
|
|
|
|
133
|
|
|
* @return array |
|
134
|
|
|
*/ |
|
135
|
|
|
public function behaviors() |
|
136
|
|
|
{ |
|
137
|
|
|
return [ |
|
138
|
|
|
'typecast' => [ |
|
139
|
|
|
'class' => AttributeTypecastBehavior::class, |
|
140
|
|
|
// 'attributeTypes' will be composed automatically according to `rules()` |
|
141
|
|
|
], |
|
142
|
|
|
]; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|