|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\Seeders; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Faker\Generator; |
|
7
|
|
|
|
|
8
|
|
|
class Faker |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var \Faker\Generator */ |
|
11
|
|
|
public $faker; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct(Generator $faker) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->faker = $faker; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function sometimes(): bool |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->faker->boolean(50); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function rarely(): bool |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->faker->boolean(20); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function mostly(): bool |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->faker->boolean(80); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function sentence(): string |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->faker->sentence(mt_rand(4, 8)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function sentences(int $min, int $max = 0): string |
|
39
|
|
|
{ |
|
40
|
|
|
$amount = $max ? mt_rand($min, $max) : $min; |
|
41
|
|
|
|
|
42
|
|
|
return $this->faker->sentences($amount, true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function title(): string |
|
46
|
|
|
{ |
|
47
|
|
|
return rtrim($this->faker->sentence(mt_rand(2, 5)), '.'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function paragraph(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->faker->paragraph(mt_rand(6, 10)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function paragraphs(int $min, int $max = 0): string |
|
56
|
|
|
{ |
|
57
|
|
|
$amount = $max ? mt_rand($min, $max) : $min; |
|
58
|
|
|
|
|
59
|
|
|
return '<p>' . implode('</p><p>', $this->faker->paragraphs($amount)) . '</p>'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function text(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return el('p.intro', $this->paragraph()) . |
|
65
|
|
|
el('h3', $this->sentence()) . |
|
66
|
|
|
el('p', $this->paragraph()) . |
|
67
|
|
|
el('blockquote', $this->paragraph()) . |
|
68
|
|
|
el('h3', $this->sentence()) . |
|
69
|
|
|
el('p', $this->paragraph()) . |
|
70
|
|
|
el('p', $this->paragraph()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function person($firstName = '', $lastName = ''): array |
|
74
|
|
|
{ |
|
75
|
|
|
$firstName = $firstName ?: $this->faker->firstName; |
|
76
|
|
|
$lastName = $lastName ?: $this->faker->lastName; |
|
77
|
|
|
$email = strtolower($firstName) . '.' . strtolower($lastName) . '@spatie.be'; |
|
78
|
|
|
|
|
79
|
|
|
return compact('firstName', 'lastName', 'email'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function pastDate(): Carbon |
|
83
|
|
|
{ |
|
84
|
|
|
return Carbon::now()->addMinutes(-rand(0, 60 * 24 * 7 * 4)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function futureDate(): Carbon |
|
88
|
|
|
{ |
|
89
|
|
|
return Carbon::now()->addMinutes(rand(0, 60 * 24 * 7 * 4)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function translate(string $text): array |
|
93
|
|
|
{ |
|
94
|
|
|
return array_fill_keys(config('app.locales'), $text); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function latitude(): float |
|
98
|
|
|
{ |
|
99
|
|
|
return mt_rand(5035000000, 5147000000) / (10 ** 8); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function longitude(): float |
|
103
|
|
|
{ |
|
104
|
|
|
return mt_rand(266000000, 571000000) / (10 ** 8); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function __get(string $name) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->faker->$name; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function __call(string $method, array $arguments) |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->faker->$method(...$arguments); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|