|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ADiaz\AML\OpenList\helpers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Faker |
|
7
|
|
|
* This class helps to create random elements. |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the OpenList Parser utility. |
|
10
|
|
|
* |
|
11
|
|
|
* @category PHP |
|
12
|
|
|
* |
|
13
|
|
|
* @author Alberto Diaz <[email protected]> |
|
14
|
|
|
* @copyright 2016 Alberto Diaz <[email protected]> |
|
15
|
|
|
* @license This source file is subject to the MIT license that is bundled |
|
16
|
|
|
* |
|
17
|
|
|
* @version Release: @package_version@ |
|
18
|
|
|
* |
|
19
|
|
|
* @link http://tytem.com |
|
20
|
|
|
*/ |
|
21
|
|
|
class Faker |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param array $array with elements |
|
25
|
|
|
* |
|
26
|
|
|
* @return mixed |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function randomElement(array $array) |
|
29
|
|
|
{ |
|
30
|
|
|
return $array[array_rand($array)]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* get random string. |
|
35
|
|
|
* |
|
36
|
|
|
* @param int $length |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function getString($length = 10) |
|
41
|
|
|
{ |
|
42
|
|
|
$characters = 'abcdefghijklmnopqrstuvwxyz'; |
|
43
|
|
|
$charactersLength = strlen($characters); |
|
44
|
|
|
$randomString = ''; |
|
45
|
|
|
for ($i = 0; $i < $length; ++$i) { |
|
46
|
|
|
$randomString .= $characters[mt_rand(0, $charactersLength - 1)]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $randomString; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* get a random name. |
|
54
|
|
|
* |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function getName() |
|
58
|
|
|
{ |
|
59
|
|
|
$names = ['James', 'David', 'Christopher', 'George', 'Ronald', 'John', 'Richard', 'Daniel', 'Kenneth', 'Anthony', 'Robert', 'Charles', 'Paul', 'Steven', 'Kevin', 'Michael', 'Joseph', 'Mary', 'Jennifer', 'Lisa', 'Sandra', 'Michelle', 'Patricia', 'Maria']; |
|
60
|
|
|
|
|
61
|
|
|
return self::randomElement($names); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* get a random surname. |
|
66
|
|
|
* |
|
67
|
|
|
* @return mixed |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function getSurname() |
|
70
|
|
|
{ |
|
71
|
|
|
$surnames = ['Johnson', 'Miller', 'Jones', 'Williams', 'Anderson', 'Smith', 'Taylor', 'Evans', 'Wilson', 'Thomas', 'Thompson', 'Wright', 'Walker', 'White', 'Edwards']; |
|
72
|
|
|
|
|
73
|
|
|
return self::randomElement($surnames); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* get a random date. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $format (date format) |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool|string |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function getDate($format = 'Y-m-d') |
|
84
|
|
|
{ |
|
85
|
|
|
return date($format, mt_rand(1, time())); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* get a random country. |
|
90
|
|
|
* |
|
91
|
|
|
* @return mixed |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function getCountry() |
|
94
|
|
|
{ |
|
95
|
|
|
return self::randomElement(['Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', |
|
96
|
|
|
'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', |
|
97
|
|
|
'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', |
|
98
|
|
|
'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', |
|
99
|
|
|
'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', |
|
100
|
|
|
'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, the Democratic Republic of the', 'Cook Islands', 'Costa Rica', 'Cote d\'Ivoire', |
|
101
|
|
|
'Croatia (Hrvatska)', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', |
|
102
|
|
|
'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'France Metropolitan', 'French Guiana', |
|
103
|
|
|
'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', |
|
104
|
|
|
'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard and Mc Donald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', |
|
105
|
|
|
'India', 'Indonesia', 'Iran (Islamic Republic of)', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', |
|
106
|
|
|
'Korea, Democratic People\'s Republic of', 'Korea, Republic of', 'Kuwait', 'Kyrgyzstan', 'Lao, People\'s Democratic Republic', 'Latvia', 'Lebanon', |
|
107
|
|
|
'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia, The Former Yugoslav Republic of', 'Madagascar', |
|
108
|
|
|
'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States of', |
|
109
|
|
|
'Moldova, Republic of', 'Monaco', 'Mongolia', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', |
|
110
|
|
|
'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', |
|
111
|
|
|
'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', |
|
112
|
|
|
'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Seychelles', |
|
113
|
|
|
'Sierra Leone', 'Singapore', 'Slovakia (Slovak Republic)', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia and the South Sandwich Islands', |
|
114
|
|
|
'Spain', 'Sri Lanka', 'St. Helena', 'St. Pierre and Miquelon', 'Sudan', 'Suriname', 'Svalbard and Jan Mayen Islands', 'Swaziland', 'Sweden', 'Switzerland', |
|
115
|
|
|
'Syrian Arab Republic', 'Taiwan, Province of China', 'Tajikistan', 'Tanzania, United Republic of', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', |
|
116
|
|
|
'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', |
|
117
|
|
|
'United States Minor Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands (British)', 'Virgin Islands (U.S.)', |
|
118
|
|
|
'Wallis and Futuna Islands', 'Western Sahara', 'Yemen', 'Yugoslavia', 'Zambia', 'Zimbabwe', ]); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|