1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Database\Factories; |
4
|
|
|
|
5
|
|
|
use Database\Factories\Traits\ModelChanges; |
6
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use Sfneal\Tracking\Utils\ModelAdapter; |
9
|
|
|
|
10
|
|
|
class TrackTrafficFactory extends Factory |
11
|
|
|
{ |
12
|
|
|
use ModelChanges; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* TrackActivityFactory constructor. |
16
|
|
|
* |
17
|
|
|
* @param null $count |
|
|
|
|
18
|
|
|
* @param Collection|null $states |
19
|
|
|
* @param Collection|null $has |
20
|
|
|
* @param Collection|null $for |
21
|
|
|
* @param Collection|null $afterMaking |
22
|
|
|
* @param Collection|null $afterCreating |
23
|
|
|
* @param null $connection |
|
|
|
|
24
|
|
|
*/ |
25
|
|
|
public function __construct($count = null, |
26
|
|
|
?Collection $states = null, |
27
|
|
|
?Collection $has = null, |
28
|
|
|
?Collection $for = null, |
29
|
|
|
?Collection $afterMaking = null, |
30
|
|
|
?Collection $afterCreating = null, |
31
|
|
|
$connection = null) |
32
|
|
|
{ |
33
|
|
|
$this->model = ModelAdapter::TrackTraffic(); |
34
|
|
|
parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Define the model's default state. |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function definition(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
'user_id' => $this->faker->randomNumber(3), |
46
|
|
|
'session_id' => session_id(), |
47
|
|
|
|
48
|
|
|
// Application |
49
|
|
|
'app_version' => $this->version(), |
50
|
|
|
'app_environment' => $this->environment(), |
51
|
|
|
|
52
|
|
|
// Request |
53
|
|
|
'request_host' => $this->environment().'.example.com', |
54
|
|
|
'request_uri' => $this->uri(), |
55
|
|
|
'request_method' => $this->faker->randomElement(['GET', 'POST', 'PUT', 'DELETE']), |
56
|
|
|
'request_payload' => ['page' => $this->faker->randomNumber(1)], |
57
|
|
|
'request_browser' => null, |
58
|
|
|
'request_ip' => '192.168.150.51', |
59
|
|
|
'request_referrer' => null, |
60
|
|
|
'request_token' => $this->faker->uuid, |
61
|
|
|
|
62
|
|
|
// Response |
63
|
|
|
'response_code' => $this->faker->randomElement([200, 201, 500, 504]), |
64
|
|
|
'response_time' => $this->faker->randomFloat(2, 0, 10), |
65
|
|
|
'response_content' => null, |
66
|
|
|
|
67
|
|
|
// Agent |
68
|
|
|
'agent_platform' => $this->faker->randomElement(['OS X', 'Windows', 'iOS', 'AndroidOS', 'Linux']), |
69
|
|
|
'agent_device' => $this->faker->randomElement(['Macintosh', 'WebKit']), |
70
|
|
|
'agent_browser' => $this->faker->randomElement(['Chrome', 'Mozilla', 'Safari']), |
71
|
|
|
|
72
|
|
|
// Timestamp |
73
|
|
|
'time_stamp' => $this->faker->date('Y-m-d H:i:s'), |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Retrieve a random semantic version number. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function version(): string |
83
|
|
|
{ |
84
|
|
|
return $this->faker->randomDigit.'.'.$this->faker->randomDigit.'.'.$this->faker->randomDigit; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Retrieve a random application environment name. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
protected function environment(): string |
93
|
|
|
{ |
94
|
|
|
return $this->faker->randomElement(['production', 'development', 'staging']); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Retrieve a random request uri. |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
protected function uri(): string |
103
|
|
|
{ |
104
|
|
|
return '/'.$this->faker->randomElement([ |
105
|
|
|
'about', |
106
|
|
|
'services', |
107
|
|
|
'team', |
108
|
|
|
'portfolio', |
109
|
|
|
'faqs', |
110
|
|
|
]); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|