fix vari - doc - viste
This commit is contained in:
@@ -41,6 +41,7 @@ App gestionale Laravel 13 con AdminLTE 4 per gestione Persone e Gruppi.
|
|||||||
- Vista backup: badge .env (grigio) e Files (giallo) nella colonna "Contenuto" basati sul manifest
|
- Vista backup: badge .env (grigio) e Files (giallo) nella colonna "Contenuto" basati sul manifest
|
||||||
- `run()` restituisce `steps` array; mostrato in flash message (controller) e output (command)
|
- `run()` restituisce `steps` array; mostrato in flash message (controller) e output (command)
|
||||||
- **2026-06-18**: Diagnose script (`diagnose.php`), .env.example aggiornato (SESSION_SECURE_COOKIE, FORCE_HTTPS, TRUSTED_PROXIES), build-dist.sh aggiornato con passo diagnose
|
- **2026-06-18**: Diagnose script (`diagnose.php`), .env.example aggiornato (SESSION_SECURE_COOKIE, FORCE_HTTPS, TRUSTED_PROXIES), build-dist.sh aggiornato con passo diagnose
|
||||||
|
- **2026-06-23**: Usabilità viste colonne: se non si clicca ✏️ su una vista, la vista attiva corrente viene auto-assunta come target di modifica. Se il nome viene cambiato, crea nuova vista invece di aggiornare (rilevamento rename via `currentVistaOriginalNome`)
|
||||||
|
|
||||||
## Funzionalità Implementate
|
## Funzionalità Implementate
|
||||||
|
|
||||||
@@ -339,9 +340,10 @@ if (!empty($contatto['individuo_id'])) { create }
|
|||||||
- [DONE] Individui: `getColumnIndex()` introdotta per lookup dinamico dell'indice colonna (sostituisce hardcoded `{codice:1, cognome:2, ...}` in `sortTable()` e `applyColumnFilter()`)
|
- [DONE] Individui: `getColumnIndex()` introdotta per lookup dinamico dell'indice colonna (sostituisce hardcoded `{codice:1, cognome:2, ...}` in `sortTable()` e `applyColumnFilter()`)
|
||||||
- [DONE] I controller per eventi, documenti, mailing-liste hanno già `$tableColumns` con flag `visible` — stesso meccanismo di gruppi. Nessuna modifica necessaria.
|
- [DONE] I controller per eventi, documenti, mailing-liste hanno già `$tableColumns` con flag `visible` — stesso meccanismo di gruppi. Nessuna modifica necessaria.
|
||||||
- [DONE] Fix: pulsante edit vista usa `data-*` attributi invece di `onclick` con `addslashes(json_encode(...))` — previene rottura HTML per JSON contenente `"`
|
- [DONE] Fix: pulsante edit vista usa `data-*` attributi invece di `onclick` con `addslashes(json_encode(...))` — previene rottura HTML per JSON contenente `"`
|
||||||
- [DA FARE] Test browser: caricare ogni pagina entity, verificare default vista, toggle colonne, resize, drag-reorder, print
|
- [DONE] Test browser: caricare ogni pagina entity, verificare default vista, toggle colonne, resize, drag-reorder, print
|
||||||
- [DA FARE] Test browser: flusso edit vista (✏️ → popola form → modifica → Aggiorna → reload)
|
- [DONE] Test browser: flusso edit vista (✏️ → popola form → modifica → Aggiorna → reload)
|
||||||
- [DA FARE] Test browser: salvare nuova vista, switching tra viste, cancellazione vista
|
- [DONE] Test browser: salvare nuova vista, switching tra viste, cancellazione vista
|
||||||
|
- [DONE] Usabilità viste colonne: se non si seleziona una vista esplicita (✏️), la vista attiva corrente viene auto-assunta come target. Se il nome viene cambiato, crea nuova vista invece di aggiornare (rename detection)
|
||||||
|
|
||||||
## 2026-06-10 — Per-User Column Views (colonne visibili, larghezze, ordine)
|
## 2026-06-10 — Per-User Column Views (colonne visibili, larghezze, ordine)
|
||||||
|
|
||||||
@@ -1090,3 +1092,26 @@ Fasi install (9 step): come upgrade + setup .env con pausa interattiva
|
|||||||
- `resources/views/email/compose.blade.php` — firma spostata dopo il body
|
- `resources/views/email/compose.blade.php` — firma spostata dopo il body
|
||||||
- `resources/views/mailing-liste/create.blade.php` — select mittente aggiunto
|
- `resources/views/mailing-liste/create.blade.php` — select mittente aggiunto
|
||||||
- `resources/views/mailing-liste/edit.blade.php` — select mittente aggiunto
|
- `resources/views/mailing-liste/edit.blade.php` — select mittente aggiunto
|
||||||
|
|
||||||
|
## 2026-06-23 — Fix document move: modal event listener + PHP empty-ids guard
|
||||||
|
|
||||||
|
**Problema**: Spostare documenti (singolo via icona cartella o mass move via toolbar) mostrava "successo" ma non spostava nulla. Il documento rimaneva nella cartella originale.
|
||||||
|
|
||||||
|
**Root cause**:
|
||||||
|
1. **JS — Bootstrap 4 event compatibility**: `addEventListener('show.bs.modal', ...)` al mass move modal usava native DOM listener, ma Bootstrap 4.6.2 dispone `show.bs.modal` come evento jQuery. Il listener non veniva mai eseguito → hidden input `massMoveIds` mai popolato → `explode(',', '')` → `['']` → `empty([''])` è `false` → `Documento::whereIn('id', [''])` (0 rows affected) → falso successo.
|
||||||
|
2. **PHP — No guardia su array vuoto dopo explode**: `massMove()`, `massDownload()`, `massDestroy()`, `massAssociate()`, `massTag()` in `DocumentoController.php` non filtravano valori vuoti/non-numerici da `$ids`.
|
||||||
|
|
||||||
|
**Fix**:
|
||||||
|
- `resources/views/documenti/index.blade.php:1306`: `document.getElementById('massMoveModal')?.addEventListener('show.bs.modal', ...)` → `$('#massMoveModal').on('show.bs.modal', ...)` (jQuery event, coerente con tutti gli altri listener nello stesso file)
|
||||||
|
- `app/Http/Controllers/DocumentoController.php`: aggiunto `array_values(array_filter($ids, fn($v) => is_numeric($v)))` in `massMove()`, `massDownload()`, `massDestroy()`, `massAssociate()`, `massTag()` — filtra stringhe vuote e non-numeriche prima di ogni `whereIn`
|
||||||
|
- `massMove()`: aggiunto controllo esplicito `count($ids)` per validare singolo documento nel flusso per-documento
|
||||||
|
|
||||||
|
**File modificati**:
|
||||||
|
- `resources/views/documenti/index.blade.php` — `addEventListener` → jQuery `.on()` a riga 1306
|
||||||
|
- `app/Http/Controllers/DocumentoController.php` — `array_filter` guard in 5 mass-action metodi
|
||||||
|
|
||||||
|
**Verifica**:
|
||||||
|
- PHP lint: OK su controller
|
||||||
|
- JS brace balance: OK (diff=0)
|
||||||
|
- Tutti gli altri listener modal nel file usano già jQuery `.on()` — il fix allinea `massMoveModal` al pattern esistente
|
||||||
|
- Nessun test automatizzato presente nel progetto (no Pest, no PHPUnit config)
|
||||||
|
|||||||
@@ -506,9 +506,10 @@ class DocumentoController extends Controller
|
|||||||
{
|
{
|
||||||
$idsInput = $request->input('ids', '');
|
$idsInput = $request->input('ids', '');
|
||||||
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
||||||
|
$ids = array_values(array_filter($ids, fn($v) => is_numeric($v)));
|
||||||
|
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return response()->json(['linked_count' => 0, 'links' => []]);
|
return back()->with('error', 'Nessun documento selezionato.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$documenti = Documento::whereIn('id', $ids)->get();
|
$documenti = Documento::whereIn('id', $ids)->get();
|
||||||
@@ -584,6 +585,7 @@ class DocumentoController extends Controller
|
|||||||
$this->authorizeRead('documenti');
|
$this->authorizeRead('documenti');
|
||||||
$idsInput = $request->input('ids', '');
|
$idsInput = $request->input('ids', '');
|
||||||
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
||||||
|
$ids = array_values(array_filter($ids, fn($v) => is_numeric($v)));
|
||||||
|
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return back()->with('error', 'Nessun documento selezionato.');
|
return back()->with('error', 'Nessun documento selezionato.');
|
||||||
@@ -648,6 +650,7 @@ class DocumentoController extends Controller
|
|||||||
$this->authorizeDelete('documenti');
|
$this->authorizeDelete('documenti');
|
||||||
$idsInput = $request->input('ids', '');
|
$idsInput = $request->input('ids', '');
|
||||||
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
||||||
|
$ids = array_values(array_filter($ids, fn($v) => is_numeric($v)));
|
||||||
|
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return back()->with('error', 'Nessun documento selezionato.');
|
return back()->with('error', 'Nessun documento selezionato.');
|
||||||
@@ -743,6 +746,7 @@ class DocumentoController extends Controller
|
|||||||
$this->authorizeWrite('documenti');
|
$this->authorizeWrite('documenti');
|
||||||
$idsInput = $request->input('ids', '');
|
$idsInput = $request->input('ids', '');
|
||||||
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
||||||
|
$ids = array_values(array_filter($ids, fn($v) => is_numeric($v)));
|
||||||
|
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return back()->with('error', 'Nessun documento selezionato.');
|
return back()->with('error', 'Nessun documento selezionato.');
|
||||||
@@ -774,6 +778,7 @@ class DocumentoController extends Controller
|
|||||||
$this->authorizeWrite('documenti');
|
$this->authorizeWrite('documenti');
|
||||||
$idsInput = $request->input('ids', '');
|
$idsInput = $request->input('ids', '');
|
||||||
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
||||||
|
$ids = array_values(array_filter($ids, fn($v) => is_numeric($v)));
|
||||||
|
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return back()->with('error', 'Nessun documento selezionato.');
|
return back()->with('error', 'Nessun documento selezionato.');
|
||||||
|
|||||||
@@ -1303,7 +1303,7 @@ function showMoveModal(id, nome) {
|
|||||||
$('#moveModal').modal('show');
|
$('#moveModal').modal('show');
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('massMoveModal')?.addEventListener('show.bs.modal', function() {
|
$('#massMoveModal').on('show.bs.modal', function() {
|
||||||
const ids = getSelectedIds();
|
const ids = getSelectedIds();
|
||||||
document.getElementById('massMoveIds').value = ids.join(',');
|
document.getElementById('massMoveIds').value = ids.join(',');
|
||||||
document.getElementById('massMoveCount').textContent = ids.length;
|
document.getElementById('massMoveCount').textContent = ids.length;
|
||||||
|
|||||||
@@ -196,9 +196,11 @@ function syncColumnListToTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let editingVistaId = null;
|
let editingVistaId = null;
|
||||||
|
let currentVistaOriginalNome = '';
|
||||||
|
|
||||||
function editVista(id, nome, isDefault, colonneVisibili) {
|
function editVista(id, nome, isDefault, colonneVisibili) {
|
||||||
editingVistaId = id;
|
editingVistaId = id;
|
||||||
|
currentVistaOriginalNome = nome;
|
||||||
document.getElementById('vista-nome').value = nome;
|
document.getElementById('vista-nome').value = nome;
|
||||||
document.getElementById('vista-default').checked = isDefault;
|
document.getElementById('vista-default').checked = isDefault;
|
||||||
document.querySelectorAll('.column-toggle').forEach(cb => {
|
document.querySelectorAll('.column-toggle').forEach(cb => {
|
||||||
@@ -210,6 +212,19 @@ function editVista(id, nome, isDefault, colonneVisibili) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initTableSettings() {
|
function initTableSettings() {
|
||||||
|
const currentVistaEl = document.getElementById('vista-data');
|
||||||
|
if (currentVistaEl && currentVistaEl.textContent && currentVistaEl.textContent !== 'null') {
|
||||||
|
try {
|
||||||
|
const cv = JSON.parse(currentVistaEl.textContent);
|
||||||
|
if (cv && cv.id) {
|
||||||
|
editingVistaId = cv.id;
|
||||||
|
currentVistaOriginalNome = cv.nome || '';
|
||||||
|
document.getElementById('vista-nome').value = cv.nome || '';
|
||||||
|
document.getElementById('save-vista-btn').innerHTML = '<i class="fas fa-save mr-1"></i> Aggiorna';
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
const columnList = document.getElementById('column-list');
|
const columnList = document.getElementById('column-list');
|
||||||
if (!columnList) return;
|
if (!columnList) return;
|
||||||
|
|
||||||
@@ -310,7 +325,8 @@ function initTableSettings() {
|
|||||||
const isDefault = document.getElementById('vista-default')?.checked || false;
|
const isDefault = document.getElementById('vista-default')?.checked || false;
|
||||||
const entityType = '{{ $entityType ?? 'individui' }}';
|
const entityType = '{{ $entityType ?? 'individui' }}';
|
||||||
|
|
||||||
const isEditing = editingVistaId !== null;
|
const isRename = editingVistaId !== null && nome !== currentVistaOriginalNome;
|
||||||
|
const isEditing = editingVistaId !== null && !isRename;
|
||||||
const url = isEditing ? '/viste/' + editingVistaId : '/viste';
|
const url = isEditing ? '/viste/' + editingVistaId : '/viste';
|
||||||
const method = isEditing ? 'PUT' : 'POST';
|
const method = isEditing ? 'PUT' : 'POST';
|
||||||
|
|
||||||
|
|||||||
Vendored
-122
@@ -1,122 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../phpunit/phpunit/phpunit)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
$GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST'] = $GLOBALS['__PHPUNIT_ISOLATION_BLACKLIST'] = array(realpath(__DIR__ . '/..'.'/phpunit/phpunit/phpunit'));
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = 'phpvfscomposer://'.$this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
$data = str_replace('__DIR__', var_export(dirname($this->realpath), true), $data);
|
|
||||||
$data = str_replace('__FILE__', var_export($this->realpath, true), $data);
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/phpunit/phpunit/phpunit');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/phpunit/phpunit/phpunit';
|
|
||||||
Vendored
-119
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Proxy PHP file generated by Composer
|
|
||||||
*
|
|
||||||
* This file includes the referenced bin path (../laravel/pint/builds/pint)
|
|
||||||
* using a stream wrapper to prevent the shebang from being output on PHP<8
|
|
||||||
*
|
|
||||||
* @generated
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Composer;
|
|
||||||
|
|
||||||
$GLOBALS['_composer_bin_dir'] = __DIR__;
|
|
||||||
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
|
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 80000) {
|
|
||||||
if (!class_exists('Composer\BinProxyWrapper')) {
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class BinProxyWrapper
|
|
||||||
{
|
|
||||||
private $handle;
|
|
||||||
private $position;
|
|
||||||
private $realpath;
|
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path)
|
|
||||||
{
|
|
||||||
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
|
|
||||||
$opened_path = substr($path, 17);
|
|
||||||
$this->realpath = realpath($opened_path) ?: $opened_path;
|
|
||||||
$opened_path = $this->realpath;
|
|
||||||
$this->handle = fopen($this->realpath, $mode);
|
|
||||||
$this->position = 0;
|
|
||||||
|
|
||||||
return (bool) $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_read($count)
|
|
||||||
{
|
|
||||||
$data = fread($this->handle, $count);
|
|
||||||
|
|
||||||
if ($this->position === 0) {
|
|
||||||
$data = preg_replace('{^#!.*\r?\n}', '', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->position += strlen($data);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_cast($castAs)
|
|
||||||
{
|
|
||||||
return $this->handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_close()
|
|
||||||
{
|
|
||||||
fclose($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_lock($operation)
|
|
||||||
{
|
|
||||||
return $operation ? flock($this->handle, $operation) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_seek($offset, $whence)
|
|
||||||
{
|
|
||||||
if (0 === fseek($this->handle, $offset, $whence)) {
|
|
||||||
$this->position = ftell($this->handle);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_tell()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_eof()
|
|
||||||
{
|
|
||||||
return feof($this->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_stat()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stream_set_option($option, $arg1, $arg2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function url_stat($path, $flags)
|
|
||||||
{
|
|
||||||
$path = substr($path, 17);
|
|
||||||
if (file_exists($path)) {
|
|
||||||
return stat($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|
|
||||||
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
|
|
||||||
) {
|
|
||||||
return include("phpvfscomposer://" . __DIR__ . '/..'.'/laravel/pint/builds/pint');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return include __DIR__ . '/..'.'/laravel/pint/builds/pint';
|
|
||||||
-2094
File diff suppressed because it is too large
Load Diff
Vendored
+3
-10
@@ -11,11 +11,11 @@ return array(
|
|||||||
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
|
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
|
||||||
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
|
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
|
||||||
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
|
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
|
||||||
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
|
|
||||||
'f598d06aa772fa33d905e87be6398fb1' => $vendorDir . '/symfony/polyfill-intl-idn/bootstrap.php',
|
'f598d06aa772fa33d905e87be6398fb1' => $vendorDir . '/symfony/polyfill-intl-idn/bootstrap.php',
|
||||||
'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
|
|
||||||
'383eaff206634a77a1be54e64e6459c7' => $vendorDir . '/sabre/uri/lib/functions.php',
|
'383eaff206634a77a1be54e64e6459c7' => $vendorDir . '/sabre/uri/lib/functions.php',
|
||||||
|
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
|
||||||
'def43f6c87e4f8dfd0c9e1b1bab14fe8' => $vendorDir . '/symfony/polyfill-iconv/bootstrap.php',
|
'def43f6c87e4f8dfd0c9e1b1bab14fe8' => $vendorDir . '/symfony/polyfill-iconv/bootstrap.php',
|
||||||
|
'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
|
||||||
'667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
|
'667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
|
||||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
|
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||||
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
|
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
|
||||||
@@ -27,15 +27,13 @@ return array(
|
|||||||
'2203a247e6fda86070a5e4e07aed533a' => $vendorDir . '/symfony/clock/Resources/now.php',
|
'2203a247e6fda86070a5e4e07aed533a' => $vendorDir . '/symfony/clock/Resources/now.php',
|
||||||
'606a39d89246991a373564698c2d8383' => $vendorDir . '/symfony/polyfill-php85/bootstrap.php',
|
'606a39d89246991a373564698c2d8383' => $vendorDir . '/symfony/polyfill-php85/bootstrap.php',
|
||||||
'a1105708a18b76903365ca1c4aa61b02' => $vendorDir . '/symfony/translation/Resources/functions.php',
|
'a1105708a18b76903365ca1c4aa61b02' => $vendorDir . '/symfony/translation/Resources/functions.php',
|
||||||
'35a6ad97d21e794e7e22a17d806652e4' => $vendorDir . '/nunomaduro/termwind/src/Functions.php',
|
|
||||||
'b33e3d135e5d9e47d845c576147bda89' => $vendorDir . '/php-di/php-di/src/functions.php',
|
'b33e3d135e5d9e47d845c576147bda89' => $vendorDir . '/php-di/php-di/src/functions.php',
|
||||||
'1f87db08236948d07391152dccb70f04' => $vendorDir . '/google/apiclient-services/autoload.php',
|
'1f87db08236948d07391152dccb70f04' => $vendorDir . '/google/apiclient-services/autoload.php',
|
||||||
'ebdb698ed4152ae445614b69b5e4bb6a' => $vendorDir . '/sabre/http/lib/functions.php',
|
'ebdb698ed4152ae445614b69b5e4bb6a' => $vendorDir . '/sabre/http/lib/functions.php',
|
||||||
'09f6b20656683369174dd6fa83b7e5fb' => $vendorDir . '/symfony/polyfill-uuid/bootstrap.php',
|
'09f6b20656683369174dd6fa83b7e5fb' => $vendorDir . '/symfony/polyfill-uuid/bootstrap.php',
|
||||||
'a8d3953fd9959404dd22d3dfcd0a79f0' => $vendorDir . '/google/apiclient/src/aliases.php',
|
'a8d3953fd9959404dd22d3dfcd0a79f0' => $vendorDir . '/google/apiclient/src/aliases.php',
|
||||||
'23dd7ece5822da3d0100ef3deb0ef55f' => $vendorDir . '/laravel/agent-detector/src/functions.php',
|
|
||||||
'47e1160838b5e5a10346ac4084b58c23' => $vendorDir . '/laravel/prompts/src/helpers.php',
|
'47e1160838b5e5a10346ac4084b58c23' => $vendorDir . '/laravel/prompts/src/helpers.php',
|
||||||
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
|
'35a6ad97d21e794e7e22a17d806652e4' => $vendorDir . '/nunomaduro/termwind/src/Functions.php',
|
||||||
'801c31d8ed748cfa537fa45402288c95' => $vendorDir . '/psy/psysh/src/functions.php',
|
'801c31d8ed748cfa537fa45402288c95' => $vendorDir . '/psy/psysh/src/functions.php',
|
||||||
'e39a8b23c42d4e1452234d762b03835a' => $vendorDir . '/ramsey/uuid/src/functions.php',
|
'e39a8b23c42d4e1452234d762b03835a' => $vendorDir . '/ramsey/uuid/src/functions.php',
|
||||||
'9d2b9fc6db0f153a0a149fefb182415e' => $vendorDir . '/symfony/polyfill-php84/bootstrap.php',
|
'9d2b9fc6db0f153a0a149fefb182415e' => $vendorDir . '/symfony/polyfill-php84/bootstrap.php',
|
||||||
@@ -49,10 +47,5 @@ return array(
|
|||||||
'91892b814db86b8442ad76273bb7aec5' => $vendorDir . '/laravel/framework/src/Illuminate/Reflection/helpers.php',
|
'91892b814db86b8442ad76273bb7aec5' => $vendorDir . '/laravel/framework/src/Illuminate/Reflection/helpers.php',
|
||||||
'493c6aea52f6009bab023b26c21a386a' => $vendorDir . '/laravel/framework/src/Illuminate/Support/functions.php',
|
'493c6aea52f6009bab023b26c21a386a' => $vendorDir . '/laravel/framework/src/Illuminate/Support/functions.php',
|
||||||
'58571171fd5812e6e447dce228f52f4d' => $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php',
|
'58571171fd5812e6e447dce228f52f4d' => $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php',
|
||||||
'309cd39bb536ff667b25a3a76938cb83' => $vendorDir . '/laravel/pao/src/Autoload.php',
|
|
||||||
'c72349b1fe8d0deeedd3a52e8aa814d8' => $vendorDir . '/mockery/mockery/library/helpers.php',
|
|
||||||
'ce9671a430e4846b44e1c68c7611f9f5' => $vendorDir . '/mockery/mockery/library/Mockery.php',
|
|
||||||
'a1cfe24d14977df6878b9bf804af2d1c' => $vendorDir . '/nunomaduro/collision/src/Adapters/Phpunit/Autoload.php',
|
|
||||||
'ec07570ca5a812141189b1fa81503674' => $vendorDir . '/phpunit/phpunit/src/Framework/Assert/Functions.php',
|
|
||||||
'377b22b161c09ed6e5152de788ca020a' => $vendorDir . '/spatie/laravel-permission/src/helpers.php',
|
'377b22b161c09ed6e5152de788ca020a' => $vendorDir . '/spatie/laravel-permission/src/helpers.php',
|
||||||
);
|
);
|
||||||
|
|||||||
Vendored
+3
-12
@@ -10,10 +10,8 @@ return array(
|
|||||||
'ZBateson\\StreamDecorators\\' => array($vendorDir . '/zbateson/stream-decorators/src'),
|
'ZBateson\\StreamDecorators\\' => array($vendorDir . '/zbateson/stream-decorators/src'),
|
||||||
'ZBateson\\MbWrapper\\' => array($vendorDir . '/zbateson/mb-wrapper/src'),
|
'ZBateson\\MbWrapper\\' => array($vendorDir . '/zbateson/mb-wrapper/src'),
|
||||||
'ZBateson\\MailMimeParser\\' => array($vendorDir . '/zbateson/mail-mime-parser/src'),
|
'ZBateson\\MailMimeParser\\' => array($vendorDir . '/zbateson/mail-mime-parser/src'),
|
||||||
'Whoops\\' => array($vendorDir . '/filp/whoops/src/Whoops'),
|
|
||||||
'Webklex\\PHPIMAP\\' => array($vendorDir . '/webklex/php-imap/src'),
|
'Webklex\\PHPIMAP\\' => array($vendorDir . '/webklex/php-imap/src'),
|
||||||
'TijsVerkoyen\\CssToInlineStyles\\' => array($vendorDir . '/tijsverkoyen/css-to-inline-styles/src'),
|
'TijsVerkoyen\\CssToInlineStyles\\' => array($vendorDir . '/tijsverkoyen/css-to-inline-styles/src'),
|
||||||
'Tests\\' => array($baseDir . '/tests'),
|
|
||||||
'Termwind\\' => array($vendorDir . '/nunomaduro/termwind/src'),
|
'Termwind\\' => array($vendorDir . '/nunomaduro/termwind/src'),
|
||||||
'Symfony\\Polyfill\\Uuid\\' => array($vendorDir . '/symfony/polyfill-uuid'),
|
'Symfony\\Polyfill\\Uuid\\' => array($vendorDir . '/symfony/polyfill-uuid'),
|
||||||
'Symfony\\Polyfill\\Php86\\' => array($vendorDir . '/symfony/polyfill-php86'),
|
'Symfony\\Polyfill\\Php86\\' => array($vendorDir . '/symfony/polyfill-php86'),
|
||||||
@@ -66,10 +64,8 @@ return array(
|
|||||||
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
|
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
|
||||||
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
|
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
|
||||||
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
|
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
|
||||||
'NunoMaduro\\Collision\\' => array($vendorDir . '/nunomaduro/collision/src'),
|
|
||||||
'Nette\\' => array($vendorDir . '/nette/schema/src', $vendorDir . '/nette/utils/src'),
|
'Nette\\' => array($vendorDir . '/nette/schema/src', $vendorDir . '/nette/utils/src'),
|
||||||
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
|
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
|
||||||
'Mockery\\' => array($vendorDir . '/mockery/mockery/library/Mockery'),
|
|
||||||
'League\\Uri\\' => array($vendorDir . '/league/uri', $vendorDir . '/league/uri-interfaces'),
|
'League\\Uri\\' => array($vendorDir . '/league/uri', $vendorDir . '/league/uri-interfaces'),
|
||||||
'League\\MimeTypeDetection\\' => array($vendorDir . '/league/mime-type-detection/src'),
|
'League\\MimeTypeDetection\\' => array($vendorDir . '/league/mime-type-detection/src'),
|
||||||
'League\\Flysystem\\WebDAV\\' => array($vendorDir . '/league/flysystem-webdav'),
|
'League\\Flysystem\\WebDAV\\' => array($vendorDir . '/league/flysystem-webdav'),
|
||||||
@@ -80,9 +76,6 @@ return array(
|
|||||||
'Laravel\\Tinker\\' => array($vendorDir . '/laravel/tinker/src'),
|
'Laravel\\Tinker\\' => array($vendorDir . '/laravel/tinker/src'),
|
||||||
'Laravel\\SerializableClosure\\' => array($vendorDir . '/laravel/serializable-closure/src'),
|
'Laravel\\SerializableClosure\\' => array($vendorDir . '/laravel/serializable-closure/src'),
|
||||||
'Laravel\\Prompts\\' => array($vendorDir . '/laravel/prompts/src'),
|
'Laravel\\Prompts\\' => array($vendorDir . '/laravel/prompts/src'),
|
||||||
'Laravel\\Pao\\' => array($vendorDir . '/laravel/pao/src'),
|
|
||||||
'Laravel\\Pail\\' => array($vendorDir . '/laravel/pail/src'),
|
|
||||||
'Laravel\\AgentDetector\\' => array($vendorDir . '/laravel/agent-detector/src'),
|
|
||||||
'Invoker\\' => array($vendorDir . '/php-di/invoker/src'),
|
'Invoker\\' => array($vendorDir . '/php-di/invoker/src'),
|
||||||
'Illuminate\\Support\\' => array($vendorDir . '/laravel/framework/src/Illuminate/Macroable', $vendorDir . '/laravel/framework/src/Illuminate/Collections', $vendorDir . '/laravel/framework/src/Illuminate/Conditionable', $vendorDir . '/laravel/framework/src/Illuminate/Reflection'),
|
'Illuminate\\Support\\' => array($vendorDir . '/laravel/framework/src/Illuminate/Macroable', $vendorDir . '/laravel/framework/src/Illuminate/Collections', $vendorDir . '/laravel/framework/src/Illuminate/Conditionable', $vendorDir . '/laravel/framework/src/Illuminate/Reflection'),
|
||||||
'Illuminate\\' => array($vendorDir . '/laravel/framework/src/Illuminate'),
|
'Illuminate\\' => array($vendorDir . '/laravel/framework/src/Illuminate'),
|
||||||
@@ -96,7 +89,6 @@ return array(
|
|||||||
'Google\\' => array($vendorDir . '/google/apiclient/src'),
|
'Google\\' => array($vendorDir . '/google/apiclient/src'),
|
||||||
'Fruitcake\\Cors\\' => array($vendorDir . '/fruitcake/php-cors/src'),
|
'Fruitcake\\Cors\\' => array($vendorDir . '/fruitcake/php-cors/src'),
|
||||||
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
|
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
|
||||||
'Faker\\' => array($vendorDir . '/fakerphp/faker/src/Faker'),
|
|
||||||
'Egulias\\EmailValidator\\' => array($vendorDir . '/egulias/email-validator/src'),
|
'Egulias\\EmailValidator\\' => array($vendorDir . '/egulias/email-validator/src'),
|
||||||
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
|
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
|
||||||
'Doctrine\\Inflector\\' => array($vendorDir . '/doctrine/inflector/src'),
|
'Doctrine\\Inflector\\' => array($vendorDir . '/doctrine/inflector/src'),
|
||||||
@@ -104,9 +96,8 @@ return array(
|
|||||||
'DirectoryTree\\ImapEngine\\Laravel\\' => array($vendorDir . '/directorytree/imapengine-laravel/src'),
|
'DirectoryTree\\ImapEngine\\Laravel\\' => array($vendorDir . '/directorytree/imapengine-laravel/src'),
|
||||||
'DirectoryTree\\ImapEngine\\' => array($vendorDir . '/directorytree/imapengine/src'),
|
'DirectoryTree\\ImapEngine\\' => array($vendorDir . '/directorytree/imapengine/src'),
|
||||||
'Dflydev\\DotAccessData\\' => array($vendorDir . '/dflydev/dot-access-data/src'),
|
'Dflydev\\DotAccessData\\' => array($vendorDir . '/dflydev/dot-access-data/src'),
|
||||||
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
|
'Database\\Seeders\\' => array($baseDir . '/database/seeders'),
|
||||||
'Database\\Seeders\\' => array($baseDir . '/database/seeders', $vendorDir . '/laravel/pint/database/seeders'),
|
'Database\\Factories\\' => array($baseDir . '/database/factories'),
|
||||||
'Database\\Factories\\' => array($baseDir . '/database/factories', $vendorDir . '/laravel/pint/database/factories'),
|
|
||||||
'DI\\' => array($vendorDir . '/php-di/php-di/src'),
|
'DI\\' => array($vendorDir . '/php-di/php-di/src'),
|
||||||
'Cron\\' => array($vendorDir . '/dragonmantank/cron-expression/src/Cron'),
|
'Cron\\' => array($vendorDir . '/dragonmantank/cron-expression/src/Cron'),
|
||||||
'Carbon\\Doctrine\\' => array($vendorDir . '/carbonphp/carbon-doctrine-types/src/Carbon/Doctrine'),
|
'Carbon\\Doctrine\\' => array($vendorDir . '/carbonphp/carbon-doctrine-types/src/Carbon/Doctrine'),
|
||||||
@@ -114,5 +105,5 @@ return array(
|
|||||||
'Brick\\Math\\' => array($vendorDir . '/brick/math/src'),
|
'Brick\\Math\\' => array($vendorDir . '/brick/math/src'),
|
||||||
'As247\\Flysystem\\GoogleDrive\\' => array($vendorDir . '/as247/flysystem-google-drive/src'),
|
'As247\\Flysystem\\GoogleDrive\\' => array($vendorDir . '/as247/flysystem-google-drive/src'),
|
||||||
'As247\\CloudStorages\\' => array($vendorDir . '/as247/cloud-storages/src'),
|
'As247\\CloudStorages\\' => array($vendorDir . '/as247/cloud-storages/src'),
|
||||||
'App\\' => array($baseDir . '/app', $vendorDir . '/laravel/pint/app'),
|
'App\\' => array($baseDir . '/app'),
|
||||||
);
|
);
|
||||||
|
|||||||
Vendored
+3
-2152
File diff suppressed because it is too large
Load Diff
Vendored
+2
-2405
File diff suppressed because it is too large
Load Diff
Vendored
+3
-318
@@ -3,11 +3,11 @@
|
|||||||
'name' => 'laravel/laravel',
|
'name' => 'laravel/laravel',
|
||||||
'pretty_version' => 'dev-main',
|
'pretty_version' => 'dev-main',
|
||||||
'version' => 'dev-main',
|
'version' => 'dev-main',
|
||||||
'reference' => 'c5127da750123ed4b569cc18681360a1ba1d04af',
|
'reference' => 'def8d225449e5e84df57d03313c64e7b3e8d2834',
|
||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev' => true,
|
'dev' => false,
|
||||||
),
|
),
|
||||||
'versions' => array(
|
'versions' => array(
|
||||||
'as247/cloud-storages' => array(
|
'as247/cloud-storages' => array(
|
||||||
@@ -46,18 +46,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'cordoval/hamcrest-php' => array(
|
|
||||||
'dev_requirement' => true,
|
|
||||||
'replaced' => array(
|
|
||||||
0 => '*',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'davedevelopment/hamcrest-php' => array(
|
|
||||||
'dev_requirement' => true,
|
|
||||||
'replaced' => array(
|
|
||||||
0 => '*',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'dflydev/dot-access-data' => array(
|
'dflydev/dot-access-data' => array(
|
||||||
'pretty_version' => 'v3.0.3',
|
'pretty_version' => 'v3.0.3',
|
||||||
'version' => '3.0.3.0',
|
'version' => '3.0.3.0',
|
||||||
@@ -121,24 +109,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'fakerphp/faker' => array(
|
|
||||||
'pretty_version' => 'v1.24.1',
|
|
||||||
'version' => '1.24.1.0',
|
|
||||||
'reference' => 'e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../fakerphp/faker',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'filp/whoops' => array(
|
|
||||||
'pretty_version' => '2.18.4',
|
|
||||||
'version' => '2.18.4.0',
|
|
||||||
'reference' => 'd2102955e48b9fd9ab24280a7ad12ed552752c4d',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../filp/whoops',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'firebase/php-jwt' => array(
|
'firebase/php-jwt' => array(
|
||||||
'pretty_version' => 'v7.0.5',
|
'pretty_version' => 'v7.0.5',
|
||||||
'version' => '7.0.5.0',
|
'version' => '7.0.5.0',
|
||||||
@@ -229,15 +199,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'hamcrest/hamcrest-php' => array(
|
|
||||||
'pretty_version' => 'v2.1.1',
|
|
||||||
'version' => '2.1.1.0',
|
|
||||||
'reference' => 'f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../hamcrest/hamcrest-php',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'illuminate/auth' => array(
|
'illuminate/auth' => array(
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
'replaced' => array(
|
'replaced' => array(
|
||||||
@@ -454,21 +415,6 @@
|
|||||||
0 => 'v13.8.0',
|
0 => 'v13.8.0',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'kodova/hamcrest-php' => array(
|
|
||||||
'dev_requirement' => true,
|
|
||||||
'replaced' => array(
|
|
||||||
0 => '*',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'laravel/agent-detector' => array(
|
|
||||||
'pretty_version' => 'v2.0.2',
|
|
||||||
'version' => '2.0.2.0',
|
|
||||||
'reference' => '90694b9256099591cf9e55d08c18ba7a00bf099f',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../laravel/agent-detector',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'laravel/framework' => array(
|
'laravel/framework' => array(
|
||||||
'pretty_version' => 'v13.8.0',
|
'pretty_version' => 'v13.8.0',
|
||||||
'version' => '13.8.0.0',
|
'version' => '13.8.0.0',
|
||||||
@@ -481,39 +427,12 @@
|
|||||||
'laravel/laravel' => array(
|
'laravel/laravel' => array(
|
||||||
'pretty_version' => 'dev-main',
|
'pretty_version' => 'dev-main',
|
||||||
'version' => 'dev-main',
|
'version' => 'dev-main',
|
||||||
'reference' => 'c5127da750123ed4b569cc18681360a1ba1d04af',
|
'reference' => 'def8d225449e5e84df57d03313c64e7b3e8d2834',
|
||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'laravel/pail' => array(
|
|
||||||
'pretty_version' => 'v1.2.6',
|
|
||||||
'version' => '1.2.6.0',
|
|
||||||
'reference' => 'aa71a01c309e7f66bc2ec4fb1a59291b82eb4abf',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../laravel/pail',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'laravel/pao' => array(
|
|
||||||
'pretty_version' => 'v1.0.6',
|
|
||||||
'version' => '1.0.6.0',
|
|
||||||
'reference' => '02f62a64c2b60af44a418ee490fee193590d8269',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../laravel/pao',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'laravel/pint' => array(
|
|
||||||
'pretty_version' => 'v1.29.1',
|
|
||||||
'version' => '1.29.1.0',
|
|
||||||
'reference' => '0770e9b7fafd50d4586881d456d6eb41c9247a80',
|
|
||||||
'type' => 'project',
|
|
||||||
'install_path' => __DIR__ . '/../laravel/pint',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'laravel/prompts' => array(
|
'laravel/prompts' => array(
|
||||||
'pretty_version' => 'v0.3.17',
|
'pretty_version' => 'v0.3.17',
|
||||||
'version' => '0.3.17.0',
|
'version' => '0.3.17.0',
|
||||||
@@ -613,15 +532,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'mockery/mockery' => array(
|
|
||||||
'pretty_version' => '1.6.12',
|
|
||||||
'version' => '1.6.12.0',
|
|
||||||
'reference' => '1f4efdd7d3beafe9807b08156dfcb176d18f1699',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../mockery/mockery',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'monolog/monolog' => array(
|
'monolog/monolog' => array(
|
||||||
'pretty_version' => '3.10.0',
|
'pretty_version' => '3.10.0',
|
||||||
'version' => '3.10.0.0',
|
'version' => '3.10.0.0',
|
||||||
@@ -637,15 +547,6 @@
|
|||||||
0 => '^1.0',
|
0 => '^1.0',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'myclabs/deep-copy' => array(
|
|
||||||
'pretty_version' => '1.13.4',
|
|
||||||
'version' => '1.13.4.0',
|
|
||||||
'reference' => '07d290f0c47959fd5eed98c95ee5602db07e0b6a',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../myclabs/deep-copy',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'nesbot/carbon' => array(
|
'nesbot/carbon' => array(
|
||||||
'pretty_version' => '3.11.4',
|
'pretty_version' => '3.11.4',
|
||||||
'version' => '3.11.4.0',
|
'version' => '3.11.4.0',
|
||||||
@@ -682,15 +583,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'nunomaduro/collision' => array(
|
|
||||||
'pretty_version' => 'v8.9.4',
|
|
||||||
'version' => '8.9.4.0',
|
|
||||||
'reference' => '716af8f95a470e9094cfca09ed897b023be191a5',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../nunomaduro/collision',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'nunomaduro/termwind' => array(
|
'nunomaduro/termwind' => array(
|
||||||
'pretty_version' => 'v2.4.0',
|
'pretty_version' => 'v2.4.0',
|
||||||
'version' => '2.4.0.0',
|
'version' => '2.4.0.0',
|
||||||
@@ -700,24 +592,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'phar-io/manifest' => array(
|
|
||||||
'pretty_version' => '2.0.4',
|
|
||||||
'version' => '2.0.4.0',
|
|
||||||
'reference' => '54750ef60c58e43759730615a392c31c80e23176',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phar-io/manifest',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'phar-io/version' => array(
|
|
||||||
'pretty_version' => '3.2.1',
|
|
||||||
'version' => '3.2.1.0',
|
|
||||||
'reference' => '4f7fd7836c6f332bb2933569e566a0d6c4cbed74',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phar-io/version',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'php-di/invoker' => array(
|
'php-di/invoker' => array(
|
||||||
'pretty_version' => '2.3.7',
|
'pretty_version' => '2.3.7',
|
||||||
'version' => '2.3.7.0',
|
'version' => '2.3.7.0',
|
||||||
@@ -745,60 +619,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'phpunit/php-code-coverage' => array(
|
|
||||||
'pretty_version' => '12.5.6',
|
|
||||||
'version' => '12.5.6.0',
|
|
||||||
'reference' => '876099a072646c7745f673d7aeab5382c4439691',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phpunit/php-code-coverage',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'phpunit/php-file-iterator' => array(
|
|
||||||
'pretty_version' => '6.0.1',
|
|
||||||
'version' => '6.0.1.0',
|
|
||||||
'reference' => '3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phpunit/php-file-iterator',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'phpunit/php-invoker' => array(
|
|
||||||
'pretty_version' => '6.0.0',
|
|
||||||
'version' => '6.0.0.0',
|
|
||||||
'reference' => '12b54e689b07a25a9b41e57736dfab6ec9ae5406',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phpunit/php-invoker',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'phpunit/php-text-template' => array(
|
|
||||||
'pretty_version' => '5.0.0',
|
|
||||||
'version' => '5.0.0.0',
|
|
||||||
'reference' => 'e1367a453f0eda562eedb4f659e13aa900d66c53',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phpunit/php-text-template',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'phpunit/php-timer' => array(
|
|
||||||
'pretty_version' => '8.0.0',
|
|
||||||
'version' => '8.0.0.0',
|
|
||||||
'reference' => 'f258ce36aa457f3aa3339f9ed4c81fc66dc8c2cc',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phpunit/php-timer',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'phpunit/phpunit' => array(
|
|
||||||
'pretty_version' => '12.5.24',
|
|
||||||
'version' => '12.5.24.0',
|
|
||||||
'reference' => 'd75dd30597caa80e72fad2ef7904601a30ef1046',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../phpunit/phpunit',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'psr/cache' => array(
|
'psr/cache' => array(
|
||||||
'pretty_version' => '3.0.0',
|
'pretty_version' => '3.0.0',
|
||||||
'version' => '3.0.0.0',
|
'version' => '3.0.0.0',
|
||||||
@@ -1027,123 +847,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'sebastian/cli-parser' => array(
|
|
||||||
'pretty_version' => '4.2.0',
|
|
||||||
'version' => '4.2.0.0',
|
|
||||||
'reference' => '90f41072d220e5c40df6e8635f5dafba2d9d4d04',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/cli-parser',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/comparator' => array(
|
|
||||||
'pretty_version' => '7.1.6',
|
|
||||||
'version' => '7.1.6.0',
|
|
||||||
'reference' => 'c769009dee98f494e0edc3fd4f4087501688f11e',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/comparator',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/complexity' => array(
|
|
||||||
'pretty_version' => '5.0.0',
|
|
||||||
'version' => '5.0.0.0',
|
|
||||||
'reference' => 'bad4316aba5303d0221f43f8cee37eb58d384bbb',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/complexity',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/diff' => array(
|
|
||||||
'pretty_version' => '7.0.0',
|
|
||||||
'version' => '7.0.0.0',
|
|
||||||
'reference' => '7ab1ea946c012266ca32390913653d844ecd085f',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/diff',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/environment' => array(
|
|
||||||
'pretty_version' => '8.1.0',
|
|
||||||
'version' => '8.1.0.0',
|
|
||||||
'reference' => 'b121608b28a13f721e76ffbbd386d08eff58f3f6',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/environment',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/exporter' => array(
|
|
||||||
'pretty_version' => '7.0.2',
|
|
||||||
'version' => '7.0.2.0',
|
|
||||||
'reference' => '016951ae10980765e4e7aee491eb288c64e505b7',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/exporter',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/global-state' => array(
|
|
||||||
'pretty_version' => '8.0.2',
|
|
||||||
'version' => '8.0.2.0',
|
|
||||||
'reference' => 'ef1377171613d09edd25b7816f05be8313f9115d',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/global-state',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/lines-of-code' => array(
|
|
||||||
'pretty_version' => '4.0.0',
|
|
||||||
'version' => '4.0.0.0',
|
|
||||||
'reference' => '97ffee3bcfb5805568d6af7f0f893678fc076d2f',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/lines-of-code',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/object-enumerator' => array(
|
|
||||||
'pretty_version' => '7.0.0',
|
|
||||||
'version' => '7.0.0.0',
|
|
||||||
'reference' => '1effe8e9b8e068e9ae228e542d5d11b5d16db894',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/object-enumerator',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/object-reflector' => array(
|
|
||||||
'pretty_version' => '5.0.0',
|
|
||||||
'version' => '5.0.0.0',
|
|
||||||
'reference' => '4bfa827c969c98be1e527abd576533293c634f6a',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/object-reflector',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/recursion-context' => array(
|
|
||||||
'pretty_version' => '7.0.1',
|
|
||||||
'version' => '7.0.1.0',
|
|
||||||
'reference' => '0b01998a7d5b1f122911a66bebcb8d46f0c82d8c',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/recursion-context',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/type' => array(
|
|
||||||
'pretty_version' => '6.0.3',
|
|
||||||
'version' => '6.0.3.0',
|
|
||||||
'reference' => 'e549163b9760b8f71f191651d22acf32d56d6d4d',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/type',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'sebastian/version' => array(
|
|
||||||
'pretty_version' => '6.0.0',
|
|
||||||
'version' => '6.0.0.0',
|
|
||||||
'reference' => '3e6ccf7657d4f0a59200564b08cead899313b53c',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../sebastian/version',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'spatie/laravel-package-tools' => array(
|
'spatie/laravel-package-tools' => array(
|
||||||
'pretty_version' => '1.93.0',
|
'pretty_version' => '1.93.0',
|
||||||
'version' => '1.93.0.0',
|
'version' => '1.93.0.0',
|
||||||
@@ -1168,15 +871,6 @@
|
|||||||
0 => '*',
|
0 => '*',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'staabm/side-effects-detector' => array(
|
|
||||||
'pretty_version' => '1.0.5',
|
|
||||||
'version' => '1.0.5.0',
|
|
||||||
'reference' => 'd8334211a140ce329c13726d4a715adbddd0a163',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../staabm/side-effects-detector',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'symfony/clock' => array(
|
'symfony/clock' => array(
|
||||||
'pretty_version' => 'v8.0.8',
|
'pretty_version' => 'v8.0.8',
|
||||||
'version' => '8.0.8.0',
|
'version' => '8.0.8.0',
|
||||||
@@ -1468,15 +1162,6 @@
|
|||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'theseer/tokenizer' => array(
|
|
||||||
'pretty_version' => '2.0.1',
|
|
||||||
'version' => '2.0.1.0',
|
|
||||||
'reference' => '7989e43bf381af0eac72e4f0ca5bcbfa81658be4',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../theseer/tokenizer',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => true,
|
|
||||||
),
|
|
||||||
'tijsverkoyen/css-to-inline-styles' => array(
|
'tijsverkoyen/css-to-inline-styles' => array(
|
||||||
'pretty_version' => 'v2.4.0',
|
'pretty_version' => 'v2.4.0',
|
||||||
'version' => '2.4.0.0',
|
'version' => '2.4.0.0',
|
||||||
|
|||||||
Vendored
-209
@@ -1,209 +0,0 @@
|
|||||||
# CHANGELOG
|
|
||||||
|
|
||||||
## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.24.0...1.24.1)
|
|
||||||
|
|
||||||
- Removed domain `gmail.com.au` from `Provider\en_AU\Internet` (#886)
|
|
||||||
|
|
||||||
## [2024-11-09, v1.24.0](https://github.com/FakerPHP/Faker/compare/v1.23.1..v1.24.0)
|
|
||||||
|
|
||||||
- Fix internal deprecations in Doctrine's populator by @gnutix in (#889)
|
|
||||||
- Fix mobile phone number pattern for France by @ker0x in (#859)
|
|
||||||
- PHP 8.4 Support by @Jubeki in (#904)
|
|
||||||
|
|
||||||
- Added support for PHP 8.4 (#904)
|
|
||||||
|
|
||||||
## [2023-09-29, v1.23.1](https://github.com/FakerPHP/Faker/compare/v1.23.0..v1.23.1)
|
|
||||||
|
|
||||||
- Fixed double `а` female lastName in `ru_RU/Person::name()` (#832)
|
|
||||||
- Fixed polish license plates (#685)
|
|
||||||
- Stopped using `static` in callables in `Provider\pt_BR\PhoneNumber` (#785)
|
|
||||||
- Fixed incorrect female name (#794)
|
|
||||||
- Stopped using the deprecated `MT_RAND_PHP` constant to seed the random generator on PHP 8.3 (#844)
|
|
||||||
|
|
||||||
## [2023-06-12, v1.23.0](https://github.com/FakerPHP/Faker/compare/v1.22.0..v1.23.0)
|
|
||||||
|
|
||||||
- Update `randomElements` to return random number of elements when no count is provided (#658)
|
|
||||||
|
|
||||||
## [2023-05-14, v1.22.0](https://github.com/FakerPHP/Faker/compare/v1.21.0..v1.22.0)
|
|
||||||
|
|
||||||
- Fixed `randomElements()` to accept empty iterator (#605)
|
|
||||||
- Added support for passing an `Enum` to `randomElement()` and `randomElements()` (#620)
|
|
||||||
- Started rejecting invalid arguments passed to `randomElement()` and `randomElements()` (#642)
|
|
||||||
|
|
||||||
## [2022-12-13, v1.21.0](https://github.com/FakerPHP/Faker/compare/v1.20.0..v1.21.0)
|
|
||||||
|
|
||||||
- Dropped support for PHP 7.1, 7.2, and 7.3 (#543)
|
|
||||||
- Added support for PHP 8.2 (#528)
|
|
||||||
|
|
||||||
## [2022-07-20, v1.20.0](https://github.com/FakerPHP/Faker/compare/v1.19.0..v1.20.0)
|
|
||||||
|
|
||||||
- Fixed typo in French phone number (#452)
|
|
||||||
- Fixed some Hungarian naming bugs (#451)
|
|
||||||
- Fixed bug where the NL-BE VAT generation was incorrect (#455)
|
|
||||||
- Improve Turkish phone numbers for E164 and added landline support (#460)
|
|
||||||
- Add Microsoft Edge User Agent (#464)
|
|
||||||
- Added option to set image formats on Faker\Provider\Image (#473)
|
|
||||||
- Added support for French color translations (#466)
|
|
||||||
- Support filtering timezones by country code (#480)
|
|
||||||
- Fixed typo in some greek names (#490)
|
|
||||||
- Marked the Faker\Provider\Image as deprecated
|
|
||||||
|
|
||||||
## [2022-02-02, v1.19.0](https://github.com/FakerPHP/Faker/compare/v1.18.0..v1.19.0)
|
|
||||||
|
|
||||||
- Added color extension to core (#442)
|
|
||||||
- Added conflict with `doctrine/persistence` below version `1.4`
|
|
||||||
- Fix for support on different Doctrine ORM versions (#414)
|
|
||||||
- Fix usage of `Doctrine\Persistence` dependency
|
|
||||||
- Fix CZ Person birthNumber docblock return type (#437)
|
|
||||||
- Fix is_IS Person docbock types (#439)
|
|
||||||
- Fix is_IS Address docbock type (#438)
|
|
||||||
- Fix regexify escape backslash in character class (#434)
|
|
||||||
- Removed UUID from Generator to be able to extend it (#441)
|
|
||||||
|
|
||||||
## [2022-01-23, v1.18.0](https://github.com/FakerPHP/Faker/compare/v1.17.0..v1.18.0)
|
|
||||||
|
|
||||||
- Deprecated UUID, use uuid3 to specify version (#427)
|
|
||||||
- Reset formatters when adding a new provider (#366)
|
|
||||||
- Helper methods to use our custom generators (#155)
|
|
||||||
- Set allow-plugins for Composer 2.2 (#405)
|
|
||||||
- Fix kk_KZ\Person::individualIdentificationNumber generation (#411)
|
|
||||||
- Allow for -> syntax to be used in parsing (#423)
|
|
||||||
- Person->name was missing string return type (#424)
|
|
||||||
- Generate a valid BE TAX number (#415)
|
|
||||||
- Added the UUID extension to Core (#427)
|
|
||||||
|
|
||||||
## [2021-12-05, v1.17.0](https://github.com/FakerPHP/Faker/compare/v1.16.0..v1.17.0)
|
|
||||||
|
|
||||||
- Partial PHP 8.1 compatibility (#373)
|
|
||||||
- Add payment provider for `ne_NP` locale (#375)
|
|
||||||
- Add Egyptian Arabic `ar_EG` locale (#377)
|
|
||||||
- Updated list of South African TLDs (#383)
|
|
||||||
- Fixed formatting of E.164 numbers (#380)
|
|
||||||
- Allow `symfony/deprecation-contracts` `^3.0` (#397)
|
|
||||||
|
|
||||||
## [2021-09-06, v1.16.0](https://github.com/FakerPHP/Faker/compare/v1.15.0..v1.16.0)
|
|
||||||
|
|
||||||
- Add Company extension
|
|
||||||
- Add Address extension
|
|
||||||
- Add Person extension
|
|
||||||
- Add PhoneNumber extension
|
|
||||||
- Add VersionExtension (#350)
|
|
||||||
- Stricter types in Extension\Container and Extension\GeneratorAwareExtension (#345)
|
|
||||||
- Fix deprecated property access in `nl_NL` (#348)
|
|
||||||
- Add support for `psr/container` >= 2.0 (#354)
|
|
||||||
- Add missing union types in Faker\Generator (#352)
|
|
||||||
|
|
||||||
## [2021-07-06, v1.15.0](https://github.com/FakerPHP/Faker/compare/v1.14.1..v1.15.0)
|
|
||||||
|
|
||||||
- Updated the generator phpdoc to help identify magic methods (#307)
|
|
||||||
- Prevent direct access and triggered deprecation warning for "word" (#302)
|
|
||||||
- Updated length on all global e164 numbers (#301)
|
|
||||||
- Updated last names from different source (#312)
|
|
||||||
- Don't generate birth number of '000' for Swedish personal identity (#306)
|
|
||||||
- Add job list for localization id_ID (#339)
|
|
||||||
|
|
||||||
## [2021-03-30, v1.14.1](https://github.com/FakerPHP/Faker/compare/v1.14.0..v1.14.1)
|
|
||||||
|
|
||||||
- Fix where randomNumber and randomFloat would return a 0 value (#291 / #292)
|
|
||||||
|
|
||||||
## [2021-03-29, v1.14.0](https://github.com/FakerPHP/Faker/compare/v1.13.0..v1.14.0)
|
|
||||||
|
|
||||||
- Fix for realText to ensure the text keeps closer to its boundaries (#152)
|
|
||||||
- Fix where regexify produces a random character instead of a literal dot (#135
|
|
||||||
- Deprecate zh_TW methods that only call base methods (#122)
|
|
||||||
- Add used extensions to composer.json as suggestion (#120)
|
|
||||||
- Moved TCNo and INN from calculator to localized providers (#108)
|
|
||||||
- Fix regex dot/backslash issue where a dot is replaced with a backslash as escape character (#206)
|
|
||||||
- Deprecate direct property access (#164)
|
|
||||||
- Added test to assert unique() behaviour (#233)
|
|
||||||
- Added RUC for the es_PE locale (#244)
|
|
||||||
- Test IBAN formats for Latin America (AR/PE/VE) (#260)
|
|
||||||
- Added VAT number for en_GB (#255)
|
|
||||||
- Added new districts for the ne_NP locale (#258)
|
|
||||||
- Fix for U.S. Area Code Generation (#261)
|
|
||||||
- Fix in numerify where a better random numeric value is guaranteed (#256)
|
|
||||||
- Fix e164PhoneNumber to only generate valid phone numbers with valid country codes (#264)
|
|
||||||
- Extract fixtures into separate classes (#234)
|
|
||||||
- Remove french domains that no longer exists (#277)
|
|
||||||
- Fix error that occurs when getting a polish title (#279)
|
|
||||||
- Use valid area codes for North America E164 phone numbers (#280)
|
|
||||||
|
|
||||||
- Adding support for extensions and PSR-11 (#154)
|
|
||||||
- Adding trait for GeneratorAwareExtension (#165)
|
|
||||||
- Added helper class for extension (#162)
|
|
||||||
- Added blood extension to core (#232)
|
|
||||||
- Added barcode extension to core (#252)
|
|
||||||
- Added number extension (#257)
|
|
||||||
|
|
||||||
- Various code style updates
|
|
||||||
- Added a note about our breaking change promise (#273)
|
|
||||||
|
|
||||||
## [2020-12-18, v1.13.0](https://github.com/FakerPHP/Faker/compare/v1.12.1..v1.13.0)
|
|
||||||
|
|
||||||
Several fixes and new additions in this release. A lot of cleanup has been done
|
|
||||||
on the codebase on both tests and consistency.
|
|
||||||
|
|
||||||
- Feature/pl pl license plate (#62)
|
|
||||||
- Fix greek phone numbers (#16)
|
|
||||||
- Move AT payment provider logic to de_AT (#72)
|
|
||||||
- Fix wiktionary links (#73)
|
|
||||||
- Fix AT person links (#74)
|
|
||||||
- Fix AT cities (#75)
|
|
||||||
- Deprecate at_AT providers (#78)
|
|
||||||
- Add Austrian `ssn()` to `Person` provider (#79)
|
|
||||||
- Fix typos in id_ID Address (#83)
|
|
||||||
- Austrian post codes (#86)
|
|
||||||
- Updated Polish data (#70)
|
|
||||||
- Improve Austrian social security number generation (#88)
|
|
||||||
- Move US phone numbers with extension to own method (#91)
|
|
||||||
- Add UK National Insurance number generator (#89)
|
|
||||||
- Fix en_SG phone number generator (#100)
|
|
||||||
- Remove usage of mt_rand (#87)
|
|
||||||
- Remove whitespace from beginning of el_GR phone numbers (#105)
|
|
||||||
- Building numbers can not be 0, 00, 000 (#107)
|
|
||||||
- Add 172.16/12 local IPv4 block (#121)
|
|
||||||
- Add JCB credit card type (#124)
|
|
||||||
- Remove json_decode from emoji generation (#123)
|
|
||||||
- Remove ro street address (#146)
|
|
||||||
|
|
||||||
## [2020-12-11, v1.12.1](https://github.com/FakerPHP/Faker/compare/v1.12.0..v1.12.1)
|
|
||||||
|
|
||||||
This is a security release that prevents a hacker to execute code on the server.
|
|
||||||
|
|
||||||
## [2020-11-23, v1.12.0](https://github.com/FakerPHP/Faker/compare/v1.11.0..v1.12.0)
|
|
||||||
|
|
||||||
- Fix ro_RO first and last day of year calculation offset (#65)
|
|
||||||
- Fix en_NG locale test namespaces that did not match PSR-4 (#57)
|
|
||||||
- Added Singapore NRIC/FIN provider (#56)
|
|
||||||
- Added provider for Lithuanian municipalities (#58)
|
|
||||||
- Added blood types provider (#61)
|
|
||||||
|
|
||||||
## [2020-11-15, v1.11.0](https://github.com/FakerPHP/Faker/compare/v1.10.1..v1.11.0)
|
|
||||||
|
|
||||||
- Added Provider for Swedish Municipalities
|
|
||||||
- Updates to person names in pt_BR
|
|
||||||
- Many code style changes
|
|
||||||
|
|
||||||
## [2020-10-28, v1.10.1](https://github.com/FakerPHP/Faker/compare/v1.10.0..v1.10.1)
|
|
||||||
|
|
||||||
- Updates the Danish addresses in dk_DK
|
|
||||||
- Removed offense company names in nl_NL
|
|
||||||
- Clarify changelog with original fork
|
|
||||||
- Standin replacement for LoremPixel to Placeholder.com (#11)
|
|
||||||
|
|
||||||
## [2020-10-27, v1.10.0](https://github.com/FakerPHP/Faker/compare/v1.9.1..v1.10.0)
|
|
||||||
|
|
||||||
- Support PHP 7.1-8.0
|
|
||||||
- Fix typo in de_DE Company Provider
|
|
||||||
- Fix dateTimeThisYear method
|
|
||||||
- Fix typo in de_DE jobTitleFormat
|
|
||||||
- Fix IBAN generation for CR
|
|
||||||
- Fix typos in greek first names
|
|
||||||
- Fix US job title typo
|
|
||||||
- Do not clear entity manager for doctrine orm populator
|
|
||||||
- Remove persian rude words
|
|
||||||
- Corrections to RU names
|
|
||||||
|
|
||||||
## 2020-10-27, v1.9.1
|
|
||||||
|
|
||||||
- Initial version. Same as `fzaninotto/Faker:v1.9.1`.
|
|
||||||
Vendored
-22
@@ -1,22 +0,0 @@
|
|||||||
Copyright (c) 2011 François Zaninotto
|
|
||||||
Portions Copyright (c) 2008 Caius Durling
|
|
||||||
Portions Copyright (c) 2008 Adam Royle
|
|
||||||
Portions Copyright (c) 2008 Fiona Burrows
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
Vendored
-114
@@ -1,114 +0,0 @@
|
|||||||
<p style="text-align: center"><img src="https://github.com/FakerPHP/Artwork/raw/main/src/socialcard.png" alt="Social card of FakerPHP"></p>
|
|
||||||
|
|
||||||
# Faker
|
|
||||||
|
|
||||||
[](https://packagist.org/packages/fakerphp/faker)
|
|
||||||
[](https://github.com/FakerPHP/Faker/actions)
|
|
||||||
[](https://shepherd.dev/github/FakerPHP/Faker)
|
|
||||||
[](https://codecov.io/gh/FakerPHP/Faker)
|
|
||||||
|
|
||||||
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
|
|
||||||
|
|
||||||
It's heavily inspired by Perl's [Data::Faker](https://metacpan.org/pod/Data::Faker), and by Ruby's [Faker](https://rubygems.org/gems/faker).
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
Faker requires PHP >= 7.4.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
composer require fakerphp/faker
|
|
||||||
```
|
|
||||||
|
|
||||||
### Documentation
|
|
||||||
|
|
||||||
Full documentation can be found over on [fakerphp.github.io](https://fakerphp.github.io).
|
|
||||||
|
|
||||||
### Basic Usage
|
|
||||||
|
|
||||||
Use `Faker\Factory::create()` to create and initialize a Faker generator, which can generate data by accessing methods named after the type of data you want.
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
|
|
||||||
// use the factory to create a Faker\Generator instance
|
|
||||||
$faker = Faker\Factory::create();
|
|
||||||
// generate data by calling methods
|
|
||||||
echo $faker->name();
|
|
||||||
// 'Vince Sporer'
|
|
||||||
echo $faker->email();
|
|
||||||
// 'walter.sophia@hotmail.com'
|
|
||||||
echo $faker->text();
|
|
||||||
// 'Numquam ut mollitia at consequuntur inventore dolorem.'
|
|
||||||
```
|
|
||||||
|
|
||||||
Each call to `$faker->name()` yields a different (random) result. This is because Faker uses `__call()` magic, and forwards `Faker\Generator->$method()` calls to `Faker\Generator->format($method, $attributes)`.
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
for ($i = 0; $i < 3; $i++) {
|
|
||||||
echo $faker->name() . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'Cyrus Boyle'
|
|
||||||
// 'Alena Cummerata'
|
|
||||||
// 'Orlo Bergstrom'
|
|
||||||
```
|
|
||||||
|
|
||||||
## Automated refactoring
|
|
||||||
|
|
||||||
If you already used this library with its properties, they are now deprecated and needs to be replaced by their equivalent methods.
|
|
||||||
|
|
||||||
You can use the provided [Rector](https://github.com/rectorphp/rector) config file to automate the work.
|
|
||||||
|
|
||||||
Run
|
|
||||||
|
|
||||||
```bash
|
|
||||||
composer require --dev rector/rector
|
|
||||||
```
|
|
||||||
|
|
||||||
to install `rector/rector`.
|
|
||||||
|
|
||||||
Run
|
|
||||||
|
|
||||||
```bash
|
|
||||||
vendor/bin/rector process src/ --config vendor/fakerphp/faker/rector-migrate.php
|
|
||||||
```
|
|
||||||
|
|
||||||
to run `rector/rector`.
|
|
||||||
|
|
||||||
*Note:* do not forget to replace `src/` with the path to your source directory.
|
|
||||||
|
|
||||||
Alternatively, import the configuration in your `rector.php` file:
|
|
||||||
|
|
||||||
```php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
use Rector\Config;
|
|
||||||
|
|
||||||
return static function (Config\RectorConfig $rectorConfig): void {
|
|
||||||
$rectorConfig->import('vendor/fakerphp/faker/rector-migrate.php');
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Faker is released under the MIT License. See [`LICENSE`](LICENSE) for details.
|
|
||||||
|
|
||||||
## Backward compatibility promise
|
|
||||||
|
|
||||||
Faker is using [Semver](https://semver.org/). This means that versions are tagged
|
|
||||||
with MAJOR.MINOR.PATCH. Only a new major version will be allowed to break backward
|
|
||||||
compatibility (BC).
|
|
||||||
|
|
||||||
Classes marked as `@experimental` or `@internal` are not included in our backward compatibility promise.
|
|
||||||
You are also not guaranteed that the value returned from a method is always the
|
|
||||||
same. You are guaranteed that the data type will not change.
|
|
||||||
|
|
||||||
PHP 8 introduced [named arguments](https://wiki.php.net/rfc/named_params), which
|
|
||||||
increased the cost and reduces flexibility for package maintainers. The names of the
|
|
||||||
arguments for methods in Faker is not included in our BC promise.
|
|
||||||
Vendored
-56
@@ -1,56 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "fakerphp/faker",
|
|
||||||
"type": "library",
|
|
||||||
"description": "Faker is a PHP library that generates fake data for you.",
|
|
||||||
"keywords": [
|
|
||||||
"faker",
|
|
||||||
"fixtures",
|
|
||||||
"data"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "François Zaninotto"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"require": {
|
|
||||||
"php": "^7.4 || ^8.0",
|
|
||||||
"psr/container": "^1.0 || ^2.0",
|
|
||||||
"symfony/deprecation-contracts": "^2.2 || ^3.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"ext-intl": "*",
|
|
||||||
"bamarni/composer-bin-plugin": "^1.4.1",
|
|
||||||
"doctrine/persistence": "^1.3 || ^2.0",
|
|
||||||
"phpunit/phpunit": "^9.5.26",
|
|
||||||
"symfony/phpunit-bridge": "^5.4.16"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Faker\\": "src/Faker/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload-dev": {
|
|
||||||
"psr-4": {
|
|
||||||
"Faker\\Test\\": "test/Faker/",
|
|
||||||
"Faker\\Test\\Fixture\\": "test/Fixture/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"conflict": {
|
|
||||||
"fzaninotto/faker": "*"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"ext-curl": "Required by Faker\\Provider\\Image to download images.",
|
|
||||||
"ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.",
|
|
||||||
"ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.",
|
|
||||||
"ext-mbstring": "Required for multibyte Unicode string functionality.",
|
|
||||||
"doctrine/orm": "Required to use Faker\\ORM\\Doctrine"
|
|
||||||
},
|
|
||||||
"config": {
|
|
||||||
"allow-plugins": {
|
|
||||||
"bamarni/composer-bin-plugin": true,
|
|
||||||
"composer/package-versions-deprecated": true
|
|
||||||
},
|
|
||||||
"sort-packages": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-161
@@ -1,161 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
use Rector\Config;
|
|
||||||
use Rector\Transform;
|
|
||||||
|
|
||||||
// This file configures rector/rector to replace all deprecated property usages with their equivalent functions.
|
|
||||||
return static function (Config\RectorConfig $rectorConfig): void {
|
|
||||||
$properties = [
|
|
||||||
'address',
|
|
||||||
'amPm',
|
|
||||||
'asciify',
|
|
||||||
'biasedNumberBetween',
|
|
||||||
'boolean',
|
|
||||||
'bothify',
|
|
||||||
'buildingNumber',
|
|
||||||
'century',
|
|
||||||
'chrome',
|
|
||||||
'city',
|
|
||||||
'citySuffix',
|
|
||||||
'colorName',
|
|
||||||
'company',
|
|
||||||
'companyEmail',
|
|
||||||
'companySuffix',
|
|
||||||
'country',
|
|
||||||
'countryCode',
|
|
||||||
'countryISOAlpha3',
|
|
||||||
'creditCardDetails',
|
|
||||||
'creditCardExpirationDate',
|
|
||||||
'creditCardExpirationDateString',
|
|
||||||
'creditCardNumber',
|
|
||||||
'creditCardType',
|
|
||||||
'currencyCode',
|
|
||||||
'date',
|
|
||||||
'dateTime',
|
|
||||||
'dateTimeAD',
|
|
||||||
'dateTimeBetween',
|
|
||||||
'dateTimeInInterval',
|
|
||||||
'dateTimeThisCentury',
|
|
||||||
'dateTimeThisDecade',
|
|
||||||
'dateTimeThisMonth',
|
|
||||||
'dateTimeThisYear',
|
|
||||||
'dayOfMonth',
|
|
||||||
'dayOfWeek',
|
|
||||||
'domainName',
|
|
||||||
'domainWord',
|
|
||||||
'e164PhoneNumber',
|
|
||||||
'email',
|
|
||||||
'emoji',
|
|
||||||
'file',
|
|
||||||
'firefox',
|
|
||||||
'firstName',
|
|
||||||
'firstNameFemale',
|
|
||||||
'firstNameMale',
|
|
||||||
'freeEmail',
|
|
||||||
'freeEmailDomain',
|
|
||||||
'getDefaultTimezone',
|
|
||||||
'hexColor',
|
|
||||||
'hslColor',
|
|
||||||
'hslColorAsArray',
|
|
||||||
'iban',
|
|
||||||
'image',
|
|
||||||
'imageUrl',
|
|
||||||
'imei',
|
|
||||||
'internetExplorer',
|
|
||||||
'iosMobileToken',
|
|
||||||
'ipv4',
|
|
||||||
'ipv6',
|
|
||||||
'iso8601',
|
|
||||||
'jobTitle',
|
|
||||||
'languageCode',
|
|
||||||
'lastName',
|
|
||||||
'latitude',
|
|
||||||
'lexify',
|
|
||||||
'linuxPlatformToken',
|
|
||||||
'linuxProcessor',
|
|
||||||
'localCoordinates',
|
|
||||||
'localIpv4',
|
|
||||||
'locale',
|
|
||||||
'longitude',
|
|
||||||
'macAddress',
|
|
||||||
'macPlatformToken',
|
|
||||||
'macProcessor',
|
|
||||||
'md5',
|
|
||||||
'month',
|
|
||||||
'monthName',
|
|
||||||
'msedge',
|
|
||||||
'name',
|
|
||||||
'numerify',
|
|
||||||
'opera',
|
|
||||||
'paragraph',
|
|
||||||
'paragraphs',
|
|
||||||
'passthrough',
|
|
||||||
'password',
|
|
||||||
'phoneNumber',
|
|
||||||
'postcode',
|
|
||||||
'randomAscii',
|
|
||||||
'randomDigitNotNull',
|
|
||||||
'randomElement',
|
|
||||||
'randomElements',
|
|
||||||
'randomHtml',
|
|
||||||
'randomKey',
|
|
||||||
'randomLetter',
|
|
||||||
'realText',
|
|
||||||
'realTextBetween',
|
|
||||||
'regexify',
|
|
||||||
'rgbColor',
|
|
||||||
'rgbColorAsArray',
|
|
||||||
'rgbCssColor',
|
|
||||||
'rgbaCssColor',
|
|
||||||
'safari',
|
|
||||||
'safeColorName',
|
|
||||||
'safeEmail',
|
|
||||||
'safeEmailDomain',
|
|
||||||
'safeHexColor',
|
|
||||||
'sentence',
|
|
||||||
'sentences',
|
|
||||||
'setDefaultTimezone',
|
|
||||||
'sha1',
|
|
||||||
'sha256',
|
|
||||||
'shuffle',
|
|
||||||
'shuffleArray',
|
|
||||||
'shuffleString',
|
|
||||||
'slug',
|
|
||||||
'streetAddress',
|
|
||||||
'streetName',
|
|
||||||
'streetSuffix',
|
|
||||||
'swiftBicNumber',
|
|
||||||
'text',
|
|
||||||
'time',
|
|
||||||
'timezone',
|
|
||||||
'title',
|
|
||||||
'titleFemale',
|
|
||||||
'titleMale',
|
|
||||||
'tld',
|
|
||||||
'toLower',
|
|
||||||
'toUpper',
|
|
||||||
'unixTime',
|
|
||||||
'url',
|
|
||||||
'userAgent',
|
|
||||||
'userName',
|
|
||||||
'uuid',
|
|
||||||
'windowsPlatformToken',
|
|
||||||
'word',
|
|
||||||
'words',
|
|
||||||
'year',
|
|
||||||
];
|
|
||||||
|
|
||||||
$rectorConfig->ruleWithConfiguration(
|
|
||||||
Transform\Rector\Assign\PropertyFetchToMethodCallRector::class,
|
|
||||||
array_map(static function (string $property): Transform\ValueObject\PropertyFetchToMethodCall {
|
|
||||||
return new Transform\ValueObject\PropertyFetchToMethodCall(
|
|
||||||
Generator::class,
|
|
||||||
$property,
|
|
||||||
$property,
|
|
||||||
);
|
|
||||||
}, $properties),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Calculator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for validating EAN-8 and EAN-13 numbers
|
|
||||||
*/
|
|
||||||
class Ean
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string EAN validation pattern
|
|
||||||
*/
|
|
||||||
public const PATTERN = '/^(?:\d{8}|\d{13})$/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Computes the checksum of an EAN number.
|
|
||||||
*
|
|
||||||
* @see https://en.wikipedia.org/wiki/International_Article_Number
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function checksum(string $digits)
|
|
||||||
{
|
|
||||||
$sequence = (strlen($digits) + 1) === 8 ? [3, 1] : [1, 3];
|
|
||||||
$sums = 0;
|
|
||||||
|
|
||||||
foreach (str_split($digits) as $n => $digit) {
|
|
||||||
$sums += ((int) $digit) * $sequence[$n % 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
return (10 - $sums % 10) % 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the provided number is an EAN compliant number and that
|
|
||||||
* the checksum is correct.
|
|
||||||
*
|
|
||||||
* @param string $ean An EAN number
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isValid(string $ean)
|
|
||||||
{
|
|
||||||
if (!preg_match(self::PATTERN, $ean)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::checksum(substr($ean, 0, -1)) === (int) substr($ean, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Calculator;
|
|
||||||
|
|
||||||
class Iban
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Generates IBAN Checksum
|
|
||||||
*
|
|
||||||
* @return string Checksum (numeric string)
|
|
||||||
*/
|
|
||||||
public static function checksum(string $iban)
|
|
||||||
{
|
|
||||||
// Move first four digits to end and set checksum to '00'
|
|
||||||
$checkString = substr($iban, 4) . substr($iban, 0, 2) . '00';
|
|
||||||
|
|
||||||
// Replace all letters with their number equivalents
|
|
||||||
$checkString = preg_replace_callback(
|
|
||||||
'/[A-Z]/',
|
|
||||||
static function (array $matches): string {
|
|
||||||
return (string) self::alphaToNumber($matches[0]);
|
|
||||||
},
|
|
||||||
$checkString,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Perform mod 97 and subtract from 98
|
|
||||||
$checksum = 98 - self::mod97($checkString);
|
|
||||||
|
|
||||||
return str_pad($checksum, 2, '0', STR_PAD_LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts letter to number
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function alphaToNumber(string $char)
|
|
||||||
{
|
|
||||||
return ord($char) - 55;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates mod97 on a numeric string
|
|
||||||
*
|
|
||||||
* @param string $number Numeric string
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function mod97(string $number)
|
|
||||||
{
|
|
||||||
$checksum = (int) $number[0];
|
|
||||||
|
|
||||||
for ($i = 1, $size = strlen($number); $i < $size; ++$i) {
|
|
||||||
$checksum = (10 * $checksum + (int) $number[$i]) % 97;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether an IBAN has a valid checksum
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isValid(string $iban)
|
|
||||||
{
|
|
||||||
return self::checksum($iban) === substr($iban, 2, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Calculator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated moved to ru_RU\Company, use {@link \Faker\Provider\ru_RU\Company}.
|
|
||||||
* @see \Faker\Provider\ru_RU\Company
|
|
||||||
*/
|
|
||||||
class Inn
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Generates INN Checksum
|
|
||||||
*
|
|
||||||
* https://ru.wikipedia.org/wiki/%D0%98%D0%B4%D0%B5%D0%BD%D1%82%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D1%8B%D0%B9_%D0%BD%D0%BE%D0%BC%D0%B5%D1%80_%D0%BD%D0%B0%D0%BB%D0%BE%D0%B3%D0%BE%D0%BF%D0%BB%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D1%89%D0%B8%D0%BA%D0%B0
|
|
||||||
*
|
|
||||||
* @param string $inn
|
|
||||||
*
|
|
||||||
* @return string Checksum (one digit)
|
|
||||||
*
|
|
||||||
* @deprecated use {@link \Faker\Provider\ru_RU\Company::inn10Checksum()} instead
|
|
||||||
* @see \Faker\Provider\ru_RU\Company::inn10Checksum()
|
|
||||||
*/
|
|
||||||
public static function checksum($inn)
|
|
||||||
{
|
|
||||||
return \Faker\Provider\ru_RU\Company::inn10Checksum($inn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether an INN has a valid checksum
|
|
||||||
*
|
|
||||||
* @param string $inn
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @deprecated use {@link \Faker\Provider\ru_RU\Company::inn10IsValid()} instead
|
|
||||||
* @see \Faker\Provider\ru_RU\Company::inn10IsValid()
|
|
||||||
*/
|
|
||||||
public static function isValid($inn)
|
|
||||||
{
|
|
||||||
return \Faker\Provider\ru_RU\Company::inn10IsValid($inn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Calculator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for validating ISBN-10
|
|
||||||
*/
|
|
||||||
class Isbn
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string ISBN-10 validation pattern
|
|
||||||
*/
|
|
||||||
public const PATTERN = '/^\d{9}[0-9X]$/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ISBN-10 check digit
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits
|
|
||||||
*
|
|
||||||
* @param string $input ISBN without check-digit
|
|
||||||
*
|
|
||||||
* @throws \LengthException When wrong input length passed
|
|
||||||
*/
|
|
||||||
public static function checksum(string $input): string
|
|
||||||
{
|
|
||||||
// We're calculating check digit for ISBN-10
|
|
||||||
// so, the length of the input should be 9
|
|
||||||
$length = 9;
|
|
||||||
|
|
||||||
if (strlen($input) !== $length) {
|
|
||||||
throw new \LengthException(sprintf('Input length should be equal to %d', $length));
|
|
||||||
}
|
|
||||||
|
|
||||||
$digits = str_split($input);
|
|
||||||
array_walk(
|
|
||||||
$digits,
|
|
||||||
static function (&$digit, $position): void {
|
|
||||||
$digit = (10 - $position) * $digit;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
$result = (11 - array_sum($digits) % 11) % 11;
|
|
||||||
|
|
||||||
// 10 is replaced by X
|
|
||||||
return ($result < 10) ? (string) $result : 'X';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the provided number is a valid ISBN-10 number
|
|
||||||
*
|
|
||||||
* @param string $isbn ISBN to check
|
|
||||||
*/
|
|
||||||
public static function isValid(string $isbn): bool
|
|
||||||
{
|
|
||||||
if (!preg_match(self::PATTERN, $isbn)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::checksum(substr($isbn, 0, -1)) === substr($isbn, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Calculator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for generating and validating Luhn numbers.
|
|
||||||
*
|
|
||||||
* Luhn algorithm is used to validate credit card numbers, IMEI numbers, and
|
|
||||||
* National Provider Identifier numbers.
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/Luhn_algorithm
|
|
||||||
*/
|
|
||||||
class Luhn
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
private static function checksum(string $number)
|
|
||||||
{
|
|
||||||
$number = (string) $number;
|
|
||||||
$length = strlen($number);
|
|
||||||
$sum = 0;
|
|
||||||
|
|
||||||
for ($i = $length - 1; $i >= 0; $i -= 2) {
|
|
||||||
$sum += $number[$i];
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = $length - 2; $i >= 0; $i -= 2) {
|
|
||||||
$sum += array_sum(str_split($number[$i] * 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sum % 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function computeCheckDigit(string $partialNumber)
|
|
||||||
{
|
|
||||||
$checkDigit = self::checksum($partialNumber . '0');
|
|
||||||
|
|
||||||
if ($checkDigit === 0) {
|
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (string) (10 - $checkDigit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a number (partial number + check digit) is Luhn compliant
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isValid(string $number)
|
|
||||||
{
|
|
||||||
return self::checksum($number) === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a Luhn compliant number.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function generateLuhnNumber(string $partialValue)
|
|
||||||
{
|
|
||||||
if (!preg_match('/^\d+$/', $partialValue)) {
|
|
||||||
throw new \InvalidArgumentException('Argument should be an integer.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $partialValue . Luhn::computeCheckDigit($partialValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Calculator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated moved to tr_TR\Person, use {@link \Faker\Provider\tr_TR\Person}.
|
|
||||||
* @see \Faker\Provider\tr_TR\Person
|
|
||||||
*/
|
|
||||||
class TCNo
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Generates Turkish Identity Number Checksum
|
|
||||||
* Gets first 9 digit as prefix and calculates checksum
|
|
||||||
*
|
|
||||||
* https://en.wikipedia.org/wiki/Turkish_Identification_Number
|
|
||||||
*
|
|
||||||
* @param string $identityPrefix
|
|
||||||
*
|
|
||||||
* @return string Checksum (two digit)
|
|
||||||
*
|
|
||||||
* @deprecated use {@link \Faker\Provider\tr_TR\Person::tcNoChecksum()} instead
|
|
||||||
* @see \Faker\Provider\tr_TR\Person::tcNoChecksum()
|
|
||||||
*/
|
|
||||||
public static function checksum($identityPrefix)
|
|
||||||
{
|
|
||||||
return \Faker\Provider\tr_TR\Person::tcNoChecksum($identityPrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a TCNo has a valid checksum
|
|
||||||
*
|
|
||||||
* @param string $tcNo
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @deprecated use {@link \Faker\Provider\tr_TR\Person::tcNoIsValid()} instead
|
|
||||||
* @see \Faker\Provider\tr_TR\Person::tcNoIsValid()
|
|
||||||
*/
|
|
||||||
public static function isValid($tcNo)
|
|
||||||
{
|
|
||||||
return \Faker\Provider\tr_TR\Person::tcNoIsValid($tcNo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker;
|
|
||||||
|
|
||||||
use Faker\Extension\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This generator returns a default value for all called properties
|
|
||||||
* and methods. It works with Faker\Generator::optional().
|
|
||||||
*
|
|
||||||
* @mixin Generator
|
|
||||||
*/
|
|
||||||
class ChanceGenerator
|
|
||||||
{
|
|
||||||
private $generator;
|
|
||||||
private $weight;
|
|
||||||
protected $default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Extension|Generator $generator
|
|
||||||
*/
|
|
||||||
public function __construct($generator, float $weight, $default = null)
|
|
||||||
{
|
|
||||||
$this->default = $default;
|
|
||||||
$this->generator = $generator;
|
|
||||||
$this->weight = $weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ext(string $id)
|
|
||||||
{
|
|
||||||
return new self($this->generator->ext($id), $this->weight, $this->default);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Catch and proxy all generator calls but return only valid values
|
|
||||||
*
|
|
||||||
* @param string $attribute
|
|
||||||
*
|
|
||||||
* @deprecated Use a method instead.
|
|
||||||
*/
|
|
||||||
public function __get($attribute)
|
|
||||||
{
|
|
||||||
trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute);
|
|
||||||
|
|
||||||
return $this->__call($attribute, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param array $arguments
|
|
||||||
*/
|
|
||||||
public function __call($name, $arguments)
|
|
||||||
{
|
|
||||||
if (mt_rand(1, 100) <= (100 * $this->weight)) {
|
|
||||||
return call_user_func_array([$this->generator, $name], $arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Container;
|
|
||||||
|
|
||||||
use Faker\Extension\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple implementation of a container.
|
|
||||||
*
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Container implements ContainerInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array<string, callable|object|string>
|
|
||||||
*/
|
|
||||||
private array $definitions;
|
|
||||||
|
|
||||||
private array $services = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a container object with a set of definitions. The array value MUST
|
|
||||||
* produce an object that implements Extension.
|
|
||||||
*
|
|
||||||
* @param array<string, callable|object|string> $definitions
|
|
||||||
*/
|
|
||||||
public function __construct(array $definitions)
|
|
||||||
{
|
|
||||||
$this->definitions = $definitions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a definition from the container.
|
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @throws \RuntimeException
|
|
||||||
* @throws ContainerException
|
|
||||||
* @throws NotInContainerException
|
|
||||||
*/
|
|
||||||
public function get($id): Extension
|
|
||||||
{
|
|
||||||
if (!is_string($id)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'First argument of %s::get() must be string',
|
|
||||||
self::class,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists($id, $this->services)) {
|
|
||||||
return $this->services[$id];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->has($id)) {
|
|
||||||
throw new NotInContainerException(sprintf(
|
|
||||||
'There is not service with id "%s" in the container.',
|
|
||||||
$id,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$definition = $this->definitions[$id];
|
|
||||||
|
|
||||||
$service = $this->getService($id, $definition);
|
|
||||||
|
|
||||||
if (!$service instanceof Extension) {
|
|
||||||
throw new \RuntimeException(sprintf(
|
|
||||||
'Service resolved for identifier "%s" does not implement the %s" interface.',
|
|
||||||
$id,
|
|
||||||
Extension::class,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->services[$id] = $service;
|
|
||||||
|
|
||||||
return $service;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the service from a definition.
|
|
||||||
*
|
|
||||||
* @param callable|object|string $definition
|
|
||||||
*/
|
|
||||||
private function getService(string $id, $definition)
|
|
||||||
{
|
|
||||||
if (is_callable($definition)) {
|
|
||||||
try {
|
|
||||||
return $definition();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
throw new ContainerException(
|
|
||||||
sprintf('Error while invoking callable for "%s"', $id),
|
|
||||||
0,
|
|
||||||
$e,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} elseif (is_object($definition)) {
|
|
||||||
return $definition;
|
|
||||||
} elseif (is_string($definition)) {
|
|
||||||
if (class_exists($definition)) {
|
|
||||||
try {
|
|
||||||
return new $definition();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
throw new ContainerException(sprintf('Could not instantiate class "%s"', $id), 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ContainerException(sprintf(
|
|
||||||
'Could not instantiate class "%s". Class was not found.',
|
|
||||||
$id,
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
throw new ContainerException(sprintf(
|
|
||||||
'Invalid type for definition with id "%s"',
|
|
||||||
$id,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the container contains a given identifier.
|
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function has($id): bool
|
|
||||||
{
|
|
||||||
if (!is_string($id)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'First argument of %s::get() must be string',
|
|
||||||
self::class,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_key_exists($id, $this->definitions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Container;
|
|
||||||
|
|
||||||
use Faker\Core;
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class ContainerBuilder
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array<string, callable|object|string>
|
|
||||||
*/
|
|
||||||
private array $definitions = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param callable|object|string $definition
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function add(string $id, $definition): self
|
|
||||||
{
|
|
||||||
if (!is_string($definition) && !is_callable($definition) && !is_object($definition)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'First argument to "%s::add()" must be a string, callable or object.',
|
|
||||||
self::class,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->definitions[$id] = $definition;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function build(): ContainerInterface
|
|
||||||
{
|
|
||||||
return new Container($this->definitions);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function defaultExtensions(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
Extension\BarcodeExtension::class => Core\Barcode::class,
|
|
||||||
Extension\BloodExtension::class => Core\Blood::class,
|
|
||||||
Extension\ColorExtension::class => Core\Color::class,
|
|
||||||
Extension\DateTimeExtension::class => Core\DateTime::class,
|
|
||||||
Extension\FileExtension::class => Core\File::class,
|
|
||||||
Extension\NumberExtension::class => Core\Number::class,
|
|
||||||
Extension\UuidExtension::class => Core\Uuid::class,
|
|
||||||
Extension\VersionExtension::class => Core\Version::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function withDefaultExtensions(): self
|
|
||||||
{
|
|
||||||
$instance = new self();
|
|
||||||
|
|
||||||
foreach (self::defaultExtensions() as $id => $definition) {
|
|
||||||
$instance->add($id, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Container;
|
|
||||||
|
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class ContainerException extends \RuntimeException implements ContainerExceptionInterface
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Container;
|
|
||||||
|
|
||||||
use Psr\Container\ContainerInterface as BaseContainerInterface;
|
|
||||||
|
|
||||||
interface ContainerInterface extends BaseContainerInterface
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Container;
|
|
||||||
|
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class NotInContainerException extends \RuntimeException implements NotFoundExceptionInterface
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Calculator;
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Barcode implements Extension\BarcodeExtension
|
|
||||||
{
|
|
||||||
private Extension\NumberExtension $numberExtension;
|
|
||||||
|
|
||||||
public function __construct(?Extension\NumberExtension $numberExtension = null)
|
|
||||||
{
|
|
||||||
$this->numberExtension = $numberExtension ?: new Number();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function ean(int $length = 13): string
|
|
||||||
{
|
|
||||||
$code = Extension\Helper::numerify(str_repeat('#', $length - 1));
|
|
||||||
|
|
||||||
return sprintf('%s%s', $code, Calculator\Ean::checksum($code));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ean13(): string
|
|
||||||
{
|
|
||||||
return $this->ean();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ean8(): string
|
|
||||||
{
|
|
||||||
return $this->ean(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isbn10(): string
|
|
||||||
{
|
|
||||||
$code = Extension\Helper::numerify(str_repeat('#', 9));
|
|
||||||
|
|
||||||
return sprintf('%s%s', $code, Calculator\Isbn::checksum($code));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isbn13(): string
|
|
||||||
{
|
|
||||||
$code = '97' . $this->numberExtension->numberBetween(8, 9) . Extension\Helper::numerify(str_repeat('#', 9));
|
|
||||||
|
|
||||||
return sprintf('%s%s', $code, Calculator\Ean::checksum($code));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Blood implements Extension\BloodExtension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private array $bloodTypes = ['A', 'AB', 'B', 'O'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private array $bloodRhFactors = ['+', '-'];
|
|
||||||
|
|
||||||
public function bloodType(): string
|
|
||||||
{
|
|
||||||
return Extension\Helper::randomElement($this->bloodTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function bloodRh(): string
|
|
||||||
{
|
|
||||||
return Extension\Helper::randomElement($this->bloodRhFactors);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function bloodGroup(): string
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'%s%s',
|
|
||||||
$this->bloodType(),
|
|
||||||
$this->bloodRh(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-177
@@ -1,177 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
use Faker\Extension\Helper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Color implements Extension\ColorExtension
|
|
||||||
{
|
|
||||||
private Extension\NumberExtension $numberExtension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private array $safeColorNames = [
|
|
||||||
'black', 'maroon', 'green', 'navy', 'olive',
|
|
||||||
'purple', 'teal', 'lime', 'blue', 'silver',
|
|
||||||
'gray', 'yellow', 'fuchsia', 'aqua', 'white',
|
|
||||||
];
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private array $allColorNames = [
|
|
||||||
'AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine',
|
|
||||||
'Azure', 'Beige', 'Bisque', 'Black', 'BlanchedAlmond',
|
|
||||||
'Blue', 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue',
|
|
||||||
'Chartreuse', 'Chocolate', 'Coral', 'CornflowerBlue',
|
|
||||||
'Cornsilk', 'Crimson', 'Cyan', 'DarkBlue', 'DarkCyan',
|
|
||||||
'DarkGoldenRod', 'DarkGray', 'DarkGreen', 'DarkKhaki',
|
|
||||||
'DarkMagenta', 'DarkOliveGreen', 'Darkorange', 'DarkOrchid',
|
|
||||||
'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue',
|
|
||||||
'DarkSlateGray', 'DarkTurquoise', 'DarkViolet', 'DeepPink',
|
|
||||||
'DeepSkyBlue', 'DimGray', 'DimGrey', 'DodgerBlue', 'FireBrick',
|
|
||||||
'FloralWhite', 'ForestGreen', 'Fuchsia', 'Gainsboro', 'GhostWhite',
|
|
||||||
'Gold', 'GoldenRod', 'Gray', 'Green', 'GreenYellow', 'HoneyDew',
|
|
||||||
'HotPink', 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender',
|
|
||||||
'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue', 'LightCoral',
|
|
||||||
'LightCyan', 'LightGoldenRodYellow', 'LightGray', 'LightGreen', 'LightPink',
|
|
||||||
'LightSalmon', 'LightSeaGreen', 'LightSkyBlue', 'LightSlateGray', 'LightSteelBlue',
|
|
||||||
'LightYellow', 'Lime', 'LimeGreen', 'Linen', 'Magenta', 'Maroon', 'MediumAquaMarine',
|
|
||||||
'MediumBlue', 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue',
|
|
||||||
'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed', 'MidnightBlue',
|
|
||||||
'MintCream', 'MistyRose', 'Moccasin', 'NavajoWhite', 'Navy', 'OldLace', 'Olive',
|
|
||||||
'OliveDrab', 'Orange', 'OrangeRed', 'Orchid', 'PaleGoldenRod', 'PaleGreen',
|
|
||||||
'PaleTurquoise', 'PaleVioletRed', 'PapayaWhip', 'PeachPuff', 'Peru', 'Pink', 'Plum',
|
|
||||||
'PowderBlue', 'Purple', 'Red', 'RosyBrown', 'RoyalBlue', 'SaddleBrown', 'Salmon',
|
|
||||||
'SandyBrown', 'SeaGreen', 'SeaShell', 'Sienna', 'Silver', 'SkyBlue', 'SlateBlue',
|
|
||||||
'SlateGray', 'Snow', 'SpringGreen', 'SteelBlue', 'Tan', 'Teal', 'Thistle', 'Tomato',
|
|
||||||
'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(?Extension\NumberExtension $numberExtension = null)
|
|
||||||
{
|
|
||||||
$this->numberExtension = $numberExtension ?: new Number();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '#fa3cc2'
|
|
||||||
*/
|
|
||||||
public function hexColor(): string
|
|
||||||
{
|
|
||||||
return '#' . str_pad(dechex($this->numberExtension->numberBetween(1, 16777215)), 6, '0', STR_PAD_LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '#ff0044'
|
|
||||||
*/
|
|
||||||
public function safeHexColor(): string
|
|
||||||
{
|
|
||||||
$color = str_pad(dechex($this->numberExtension->numberBetween(0, 255)), 3, '0', STR_PAD_LEFT);
|
|
||||||
|
|
||||||
return sprintf(
|
|
||||||
'#%s%s%s%s%s%s',
|
|
||||||
$color[0],
|
|
||||||
$color[0],
|
|
||||||
$color[1],
|
|
||||||
$color[1],
|
|
||||||
$color[2],
|
|
||||||
$color[2],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'array(0,255,122)'
|
|
||||||
*
|
|
||||||
* @return int[]
|
|
||||||
*/
|
|
||||||
public function rgbColorAsArray(): array
|
|
||||||
{
|
|
||||||
$color = $this->hexColor();
|
|
||||||
|
|
||||||
return [
|
|
||||||
hexdec(substr($color, 1, 2)),
|
|
||||||
hexdec(substr($color, 3, 2)),
|
|
||||||
hexdec(substr($color, 5, 2)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '0,255,122'
|
|
||||||
*/
|
|
||||||
public function rgbColor(): string
|
|
||||||
{
|
|
||||||
return implode(',', $this->rgbColorAsArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'rgb(0,255,122)'
|
|
||||||
*/
|
|
||||||
public function rgbCssColor(): string
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'rgb(%s)',
|
|
||||||
$this->rgbColor(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'rgba(0,255,122,0.8)'
|
|
||||||
*/
|
|
||||||
public function rgbaCssColor(): string
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'rgba(%s,%s)',
|
|
||||||
$this->rgbColor(),
|
|
||||||
$this->numberExtension->randomFloat(1, 0, 1),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'blue'
|
|
||||||
*/
|
|
||||||
public function safeColorName(): string
|
|
||||||
{
|
|
||||||
return Helper::randomElement($this->safeColorNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'NavajoWhite'
|
|
||||||
*/
|
|
||||||
public function colorName(): string
|
|
||||||
{
|
|
||||||
return Helper::randomElement($this->allColorNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '340,50,20'
|
|
||||||
*/
|
|
||||||
public function hslColor(): string
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'%s,%s,%s',
|
|
||||||
$this->numberExtension->numberBetween(0, 360),
|
|
||||||
$this->numberExtension->numberBetween(0, 100),
|
|
||||||
$this->numberExtension->numberBetween(0, 100),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example array(340, 50, 20)
|
|
||||||
*
|
|
||||||
* @return int[]
|
|
||||||
*/
|
|
||||||
public function hslColorAsArray(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
$this->numberExtension->numberBetween(0, 360),
|
|
||||||
$this->numberExtension->numberBetween(0, 100),
|
|
||||||
$this->numberExtension->numberBetween(0, 100),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Coordinates implements Extension\Extension
|
|
||||||
{
|
|
||||||
private Extension\NumberExtension $numberExtension;
|
|
||||||
|
|
||||||
public function __construct(?Extension\NumberExtension $numberExtension = null)
|
|
||||||
{
|
|
||||||
$this->numberExtension = $numberExtension ?: new Number();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '77.147489'
|
|
||||||
*
|
|
||||||
* @return float Uses signed degrees format (returns a float number between -90 and 90)
|
|
||||||
*/
|
|
||||||
public function latitude(float $min = -90.0, float $max = 90.0): float
|
|
||||||
{
|
|
||||||
if ($min < -90 || $max < -90) {
|
|
||||||
throw new \LogicException('Latitude cannot be less that -90.0');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($min > 90 || $max > 90) {
|
|
||||||
throw new \LogicException('Latitude cannot be greater that 90.0');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->randomFloat(6, $min, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '86.211205'
|
|
||||||
*
|
|
||||||
* @return float Uses signed degrees format (returns a float number between -180 and 180)
|
|
||||||
*/
|
|
||||||
public function longitude(float $min = -180.0, float $max = 180.0): float
|
|
||||||
{
|
|
||||||
if ($min < -180 || $max < -180) {
|
|
||||||
throw new \LogicException('Longitude cannot be less that -180.0');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($min > 180 || $max > 180) {
|
|
||||||
throw new \LogicException('Longitude cannot be greater that 180.0');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->randomFloat(6, $min, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example array('77.147489', '86.211205')
|
|
||||||
*
|
|
||||||
* @return array{latitude: float, longitude: float}
|
|
||||||
*/
|
|
||||||
public function localCoordinates(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'latitude' => $this->latitude(),
|
|
||||||
'longitude' => $this->longitude(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function randomFloat(int $nbMaxDecimals, float $min, float $max): float
|
|
||||||
{
|
|
||||||
if ($min > $max) {
|
|
||||||
throw new \LogicException('Invalid coordinates boundaries');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->numberExtension->randomFloat($nbMaxDecimals, $min, $max);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-217
@@ -1,217 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension\DateTimeExtension;
|
|
||||||
use Faker\Extension\GeneratorAwareExtension;
|
|
||||||
use Faker\Extension\GeneratorAwareExtensionTrait;
|
|
||||||
use Faker\Extension\Helper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*
|
|
||||||
* @since 1.20.0
|
|
||||||
*/
|
|
||||||
final class DateTime implements DateTimeExtension, GeneratorAwareExtension
|
|
||||||
{
|
|
||||||
use GeneratorAwareExtensionTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private array $centuries = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX', 'XXI'];
|
|
||||||
|
|
||||||
private ?string $defaultTimezone = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the POSIX-timestamp of a DateTime, int or string.
|
|
||||||
*
|
|
||||||
* @param \DateTime|float|int|string $until
|
|
||||||
*
|
|
||||||
* @return false|int
|
|
||||||
*/
|
|
||||||
private function getTimestamp($until = 'now')
|
|
||||||
{
|
|
||||||
if (is_numeric($until)) {
|
|
||||||
return (int) $until;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($until instanceof \DateTime) {
|
|
||||||
return $until->getTimestamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtotime(empty($until) ? 'now' : $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a DateTime created based on a POSIX-timestamp.
|
|
||||||
*
|
|
||||||
* @param int $timestamp the UNIX / POSIX-compatible timestamp
|
|
||||||
*/
|
|
||||||
private function getTimestampDateTime(int $timestamp): \DateTime
|
|
||||||
{
|
|
||||||
return new \DateTime('@' . $timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function resolveTimezone(?string $timezone): string
|
|
||||||
{
|
|
||||||
if ($timezone !== null) {
|
|
||||||
return $timezone;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null === $this->defaultTimezone ? date_default_timezone_get() : $this->defaultTimezone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal method to set the timezone on a DateTime object.
|
|
||||||
*/
|
|
||||||
private function setTimezone(\DateTime $dateTime, ?string $timezone): \DateTime
|
|
||||||
{
|
|
||||||
$timezone = $this->resolveTimezone($timezone);
|
|
||||||
|
|
||||||
return $dateTime->setTimezone(new \DateTimeZone($timezone));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTime($until = 'now', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
return $this->setTimezone(
|
|
||||||
$this->getTimestampDateTime($this->unixTime($until)),
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeAD($until = 'now', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
$min = (PHP_INT_SIZE > 4) ? -62135597361 : -PHP_INT_MAX;
|
|
||||||
|
|
||||||
return $this->setTimezone(
|
|
||||||
$this->getTimestampDateTime($this->generator->numberBetween($min, $this->getTimestamp($until))),
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeBetween($from = '-30 years', $until = 'now', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
$start = $this->getTimestamp($from);
|
|
||||||
$end = $this->getTimestamp($until);
|
|
||||||
|
|
||||||
if ($start > $end) {
|
|
||||||
throw new \InvalidArgumentException('"$from" must be anterior to "$until".');
|
|
||||||
}
|
|
||||||
|
|
||||||
$timestamp = $this->generator->numberBetween($start, $end);
|
|
||||||
|
|
||||||
return $this->setTimezone(
|
|
||||||
$this->getTimestampDateTime($timestamp),
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
$intervalObject = \DateInterval::createFromDateString($interval);
|
|
||||||
$datetime = $from instanceof \DateTime ? $from : new \DateTime($from);
|
|
||||||
|
|
||||||
$other = (clone $datetime)->add($intervalObject);
|
|
||||||
|
|
||||||
$begin = min($datetime, $other);
|
|
||||||
$end = $datetime === $begin ? $other : $datetime;
|
|
||||||
|
|
||||||
return $this->dateTimeBetween($begin, $end, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeThisWeek($until = 'sunday this week', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
return $this->dateTimeBetween('monday this week', $until, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeThisMonth($until = 'last day of this month', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
return $this->dateTimeBetween('first day of this month', $until, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeThisYear($until = 'last day of december', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
return $this->dateTimeBetween('first day of january', $until, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeThisDecade($until = 'now', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
$year = floor(date('Y') / 10) * 10;
|
|
||||||
|
|
||||||
return $this->dateTimeBetween("first day of january $year", $until, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dateTimeThisCentury($until = 'now', ?string $timezone = null): \DateTime
|
|
||||||
{
|
|
||||||
$year = floor(date('Y') / 100) * 100;
|
|
||||||
|
|
||||||
return $this->dateTimeBetween("first day of january $year", $until, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function date(string $format = 'Y-m-d', $until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->dateTime($until)->format($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function time(string $format = 'H:i:s', $until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date($format, $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unixTime($until = 'now'): int
|
|
||||||
{
|
|
||||||
return $this->generator->numberBetween(0, $this->getTimestamp($until));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function iso8601($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date(\DateTime::ISO8601, $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function amPm($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date('a', $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dayOfMonth($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date('d', $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dayOfWeek($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date('l', $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function month($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date('m', $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function monthName($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date('F', $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function year($until = 'now'): string
|
|
||||||
{
|
|
||||||
return $this->date('Y', $until);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function century(): string
|
|
||||||
{
|
|
||||||
return Helper::randomElement($this->centuries);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function timezone(?string $countryCode = null): string
|
|
||||||
{
|
|
||||||
if ($countryCode) {
|
|
||||||
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);
|
|
||||||
} else {
|
|
||||||
$timezones = \DateTimeZone::listIdentifiers();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Helper::randomElement($timezones);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-564
@@ -1,564 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class File implements Extension\FileExtension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* MIME types from the apache.org file. Some types are truncated.
|
|
||||||
*
|
|
||||||
* @var array Map of MIME types => file extension(s)
|
|
||||||
*
|
|
||||||
* @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
|
||||||
*/
|
|
||||||
private array $mimeTypes = [
|
|
||||||
'application/atom+xml' => 'atom',
|
|
||||||
'application/ecmascript' => 'ecma',
|
|
||||||
'application/emma+xml' => 'emma',
|
|
||||||
'application/epub+zip' => 'epub',
|
|
||||||
'application/java-archive' => 'jar',
|
|
||||||
'application/java-vm' => 'class',
|
|
||||||
'application/javascript' => 'js',
|
|
||||||
'application/json' => 'json',
|
|
||||||
'application/jsonml+json' => 'jsonml',
|
|
||||||
'application/lost+xml' => 'lostxml',
|
|
||||||
'application/mathml+xml' => 'mathml',
|
|
||||||
'application/mets+xml' => 'mets',
|
|
||||||
'application/mods+xml' => 'mods',
|
|
||||||
'application/mp4' => 'mp4s',
|
|
||||||
'application/msword' => ['doc', 'dot'],
|
|
||||||
'application/octet-stream' => [
|
|
||||||
'bin',
|
|
||||||
'dms',
|
|
||||||
'lrf',
|
|
||||||
'mar',
|
|
||||||
'so',
|
|
||||||
'dist',
|
|
||||||
'distz',
|
|
||||||
'pkg',
|
|
||||||
'bpk',
|
|
||||||
'dump',
|
|
||||||
'elc',
|
|
||||||
'deploy',
|
|
||||||
],
|
|
||||||
'application/ogg' => 'ogx',
|
|
||||||
'application/omdoc+xml' => 'omdoc',
|
|
||||||
'application/pdf' => 'pdf',
|
|
||||||
'application/pgp-encrypted' => 'pgp',
|
|
||||||
'application/pgp-signature' => ['asc', 'sig'],
|
|
||||||
'application/pkix-pkipath' => 'pkipath',
|
|
||||||
'application/pkixcmp' => 'pki',
|
|
||||||
'application/pls+xml' => 'pls',
|
|
||||||
'application/postscript' => ['ai', 'eps', 'ps'],
|
|
||||||
'application/pskc+xml' => 'pskcxml',
|
|
||||||
'application/rdf+xml' => 'rdf',
|
|
||||||
'application/reginfo+xml' => 'rif',
|
|
||||||
'application/rss+xml' => 'rss',
|
|
||||||
'application/rtf' => 'rtf',
|
|
||||||
'application/sbml+xml' => 'sbml',
|
|
||||||
'application/vnd.adobe.air-application-installer-package+zip' => 'air',
|
|
||||||
'application/vnd.adobe.xdp+xml' => 'xdp',
|
|
||||||
'application/vnd.adobe.xfdf' => 'xfdf',
|
|
||||||
'application/vnd.ahead.space' => 'ahead',
|
|
||||||
'application/vnd.dart' => 'dart',
|
|
||||||
'application/vnd.data-vision.rdz' => 'rdz',
|
|
||||||
'application/vnd.dece.data' => ['uvf', 'uvvf', 'uvd', 'uvvd'],
|
|
||||||
'application/vnd.dece.ttml+xml' => ['uvt', 'uvvt'],
|
|
||||||
'application/vnd.dece.unspecified' => ['uvx', 'uvvx'],
|
|
||||||
'application/vnd.dece.zip' => ['uvz', 'uvvz'],
|
|
||||||
'application/vnd.denovo.fcselayout-link' => 'fe_launch',
|
|
||||||
'application/vnd.dna' => 'dna',
|
|
||||||
'application/vnd.dolby.mlp' => 'mlp',
|
|
||||||
'application/vnd.dpgraph' => 'dpg',
|
|
||||||
'application/vnd.dreamfactory' => 'dfac',
|
|
||||||
'application/vnd.ds-keypoint' => 'kpxx',
|
|
||||||
'application/vnd.dvb.ait' => 'ait',
|
|
||||||
'application/vnd.dvb.service' => 'svc',
|
|
||||||
'application/vnd.dynageo' => 'geo',
|
|
||||||
'application/vnd.ecowin.chart' => 'mag',
|
|
||||||
'application/vnd.enliven' => 'nml',
|
|
||||||
'application/vnd.epson.esf' => 'esf',
|
|
||||||
'application/vnd.epson.msf' => 'msf',
|
|
||||||
'application/vnd.epson.quickanime' => 'qam',
|
|
||||||
'application/vnd.epson.salt' => 'slt',
|
|
||||||
'application/vnd.epson.ssf' => 'ssf',
|
|
||||||
'application/vnd.ezpix-album' => 'ez2',
|
|
||||||
'application/vnd.ezpix-package' => 'ez3',
|
|
||||||
'application/vnd.fdf' => 'fdf',
|
|
||||||
'application/vnd.fdsn.mseed' => 'mseed',
|
|
||||||
'application/vnd.fdsn.seed' => ['seed', 'dataless'],
|
|
||||||
'application/vnd.flographit' => 'gph',
|
|
||||||
'application/vnd.fluxtime.clip' => 'ftc',
|
|
||||||
'application/vnd.hal+xml' => 'hal',
|
|
||||||
'application/vnd.hydrostatix.sof-data' => 'sfd-hdstx',
|
|
||||||
'application/vnd.ibm.minipay' => 'mpy',
|
|
||||||
'application/vnd.ibm.secure-container' => 'sc',
|
|
||||||
'application/vnd.iccprofile' => ['icc', 'icm'],
|
|
||||||
'application/vnd.igloader' => 'igl',
|
|
||||||
'application/vnd.immervision-ivp' => 'ivp',
|
|
||||||
'application/vnd.kde.karbon' => 'karbon',
|
|
||||||
'application/vnd.kde.kchart' => 'chrt',
|
|
||||||
'application/vnd.kde.kformula' => 'kfo',
|
|
||||||
'application/vnd.kde.kivio' => 'flw',
|
|
||||||
'application/vnd.kde.kontour' => 'kon',
|
|
||||||
'application/vnd.kde.kpresenter' => ['kpr', 'kpt'],
|
|
||||||
'application/vnd.kde.kspread' => 'ksp',
|
|
||||||
'application/vnd.kde.kword' => ['kwd', 'kwt'],
|
|
||||||
'application/vnd.kenameaapp' => 'htke',
|
|
||||||
'application/vnd.kidspiration' => 'kia',
|
|
||||||
'application/vnd.kinar' => ['kne', 'knp'],
|
|
||||||
'application/vnd.koan' => ['skp', 'skd', 'skt', 'skm'],
|
|
||||||
'application/vnd.kodak-descriptor' => 'sse',
|
|
||||||
'application/vnd.las.las+xml' => 'lasxml',
|
|
||||||
'application/vnd.llamagraphics.life-balance.desktop' => 'lbd',
|
|
||||||
'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe',
|
|
||||||
'application/vnd.lotus-1-2-3' => '123',
|
|
||||||
'application/vnd.lotus-approach' => 'apr',
|
|
||||||
'application/vnd.lotus-freelance' => 'pre',
|
|
||||||
'application/vnd.lotus-notes' => 'nsf',
|
|
||||||
'application/vnd.lotus-organizer' => 'org',
|
|
||||||
'application/vnd.lotus-screencam' => 'scm',
|
|
||||||
'application/vnd.mozilla.xul+xml' => 'xul',
|
|
||||||
'application/vnd.ms-artgalry' => 'cil',
|
|
||||||
'application/vnd.ms-cab-compressed' => 'cab',
|
|
||||||
'application/vnd.ms-excel' => [
|
|
||||||
'xls',
|
|
||||||
'xlm',
|
|
||||||
'xla',
|
|
||||||
'xlc',
|
|
||||||
'xlt',
|
|
||||||
'xlw',
|
|
||||||
],
|
|
||||||
'application/vnd.ms-excel.addin.macroenabled.12' => 'xlam',
|
|
||||||
'application/vnd.ms-excel.sheet.binary.macroenabled.12' => 'xlsb',
|
|
||||||
'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm',
|
|
||||||
'application/vnd.ms-excel.template.macroenabled.12' => 'xltm',
|
|
||||||
'application/vnd.ms-fontobject' => 'eot',
|
|
||||||
'application/vnd.ms-htmlhelp' => 'chm',
|
|
||||||
'application/vnd.ms-ims' => 'ims',
|
|
||||||
'application/vnd.ms-lrm' => 'lrm',
|
|
||||||
'application/vnd.ms-officetheme' => 'thmx',
|
|
||||||
'application/vnd.ms-pki.seccat' => 'cat',
|
|
||||||
'application/vnd.ms-pki.stl' => 'stl',
|
|
||||||
'application/vnd.ms-powerpoint' => ['ppt', 'pps', 'pot'],
|
|
||||||
'application/vnd.ms-powerpoint.addin.macroenabled.12' => 'ppam',
|
|
||||||
'application/vnd.ms-powerpoint.presentation.macroenabled.12' => 'pptm',
|
|
||||||
'application/vnd.ms-powerpoint.slide.macroenabled.12' => 'sldm',
|
|
||||||
'application/vnd.ms-powerpoint.slideshow.macroenabled.12' => 'ppsm',
|
|
||||||
'application/vnd.ms-powerpoint.template.macroenabled.12' => 'potm',
|
|
||||||
'application/vnd.ms-project' => ['mpp', 'mpt'],
|
|
||||||
'application/vnd.ms-word.document.macroenabled.12' => 'docm',
|
|
||||||
'application/vnd.ms-word.template.macroenabled.12' => 'dotm',
|
|
||||||
'application/vnd.ms-works' => ['wps', 'wks', 'wcm', 'wdb'],
|
|
||||||
'application/vnd.ms-wpl' => 'wpl',
|
|
||||||
'application/vnd.ms-xpsdocument' => 'xps',
|
|
||||||
'application/vnd.mseq' => 'mseq',
|
|
||||||
'application/vnd.musician' => 'mus',
|
|
||||||
'application/vnd.oasis.opendocument.chart' => 'odc',
|
|
||||||
'application/vnd.oasis.opendocument.chart-template' => 'otc',
|
|
||||||
'application/vnd.oasis.opendocument.database' => 'odb',
|
|
||||||
'application/vnd.oasis.opendocument.formula' => 'odf',
|
|
||||||
'application/vnd.oasis.opendocument.formula-template' => 'odft',
|
|
||||||
'application/vnd.oasis.opendocument.graphics' => 'odg',
|
|
||||||
'application/vnd.oasis.opendocument.graphics-template' => 'otg',
|
|
||||||
'application/vnd.oasis.opendocument.image' => 'odi',
|
|
||||||
'application/vnd.oasis.opendocument.image-template' => 'oti',
|
|
||||||
'application/vnd.oasis.opendocument.presentation' => 'odp',
|
|
||||||
'application/vnd.oasis.opendocument.presentation-template' => 'otp',
|
|
||||||
'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
|
|
||||||
'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
|
|
||||||
'application/vnd.oasis.opendocument.text' => 'odt',
|
|
||||||
'application/vnd.oasis.opendocument.text-master' => 'odm',
|
|
||||||
'application/vnd.oasis.opendocument.text-template' => 'ott',
|
|
||||||
'application/vnd.oasis.opendocument.text-web' => 'oth',
|
|
||||||
'application/vnd.olpc-sugar' => 'xo',
|
|
||||||
'application/vnd.oma.dd2+xml' => 'dd2',
|
|
||||||
'application/vnd.openofficeorg.extension' => 'oxt',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slide' => 'sldx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'potx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'xltx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx',
|
|
||||||
'application/vnd.pvi.ptid1' => 'ptid',
|
|
||||||
'application/vnd.quark.quarkxpress' => [
|
|
||||||
'qxd',
|
|
||||||
'qxt',
|
|
||||||
'qwd',
|
|
||||||
'qwt',
|
|
||||||
'qxl',
|
|
||||||
'qxb',
|
|
||||||
],
|
|
||||||
'application/vnd.realvnc.bed' => 'bed',
|
|
||||||
'application/vnd.recordare.musicxml' => 'mxl',
|
|
||||||
'application/vnd.recordare.musicxml+xml' => 'musicxml',
|
|
||||||
'application/vnd.rig.cryptonote' => 'cryptonote',
|
|
||||||
'application/vnd.rim.cod' => 'cod',
|
|
||||||
'application/vnd.rn-realmedia' => 'rm',
|
|
||||||
'application/vnd.rn-realmedia-vbr' => 'rmvb',
|
|
||||||
'application/vnd.route66.link66+xml' => 'link66',
|
|
||||||
'application/vnd.sailingtracker.track' => 'st',
|
|
||||||
'application/vnd.seemail' => 'see',
|
|
||||||
'application/vnd.sema' => 'sema',
|
|
||||||
'application/vnd.semd' => 'semd',
|
|
||||||
'application/vnd.semf' => 'semf',
|
|
||||||
'application/vnd.shana.informed.formdata' => 'ifm',
|
|
||||||
'application/vnd.shana.informed.formtemplate' => 'itp',
|
|
||||||
'application/vnd.shana.informed.interchange' => 'iif',
|
|
||||||
'application/vnd.shana.informed.package' => 'ipk',
|
|
||||||
'application/vnd.simtech-mindmapper' => ['twd', 'twds'],
|
|
||||||
'application/vnd.smaf' => 'mmf',
|
|
||||||
'application/vnd.stepmania.stepchart' => 'sm',
|
|
||||||
'application/vnd.sun.xml.calc' => 'sxc',
|
|
||||||
'application/vnd.sun.xml.calc.template' => 'stc',
|
|
||||||
'application/vnd.sun.xml.draw' => 'sxd',
|
|
||||||
'application/vnd.sun.xml.draw.template' => 'std',
|
|
||||||
'application/vnd.sun.xml.impress' => 'sxi',
|
|
||||||
'application/vnd.sun.xml.impress.template' => 'sti',
|
|
||||||
'application/vnd.sun.xml.math' => 'sxm',
|
|
||||||
'application/vnd.sun.xml.writer' => 'sxw',
|
|
||||||
'application/vnd.sun.xml.writer.global' => 'sxg',
|
|
||||||
'application/vnd.sun.xml.writer.template' => 'stw',
|
|
||||||
'application/vnd.sus-calendar' => ['sus', 'susp'],
|
|
||||||
'application/vnd.svd' => 'svd',
|
|
||||||
'application/vnd.symbian.install' => ['sis', 'sisx'],
|
|
||||||
'application/vnd.syncml+xml' => 'xsm',
|
|
||||||
'application/vnd.syncml.dm+wbxml' => 'bdm',
|
|
||||||
'application/vnd.syncml.dm+xml' => 'xdm',
|
|
||||||
'application/vnd.tao.intent-module-archive' => 'tao',
|
|
||||||
'application/vnd.tcpdump.pcap' => ['pcap', 'cap', 'dmp'],
|
|
||||||
'application/vnd.tmobile-livetv' => 'tmo',
|
|
||||||
'application/vnd.trid.tpt' => 'tpt',
|
|
||||||
'application/vnd.triscape.mxs' => 'mxs',
|
|
||||||
'application/vnd.trueapp' => 'tra',
|
|
||||||
'application/vnd.ufdl' => ['ufd', 'ufdl'],
|
|
||||||
'application/vnd.uiq.theme' => 'utz',
|
|
||||||
'application/vnd.umajin' => 'umj',
|
|
||||||
'application/vnd.unity' => 'unityweb',
|
|
||||||
'application/vnd.uoml+xml' => 'uoml',
|
|
||||||
'application/vnd.vcx' => 'vcx',
|
|
||||||
'application/vnd.visio' => ['vsd', 'vst', 'vss', 'vsw'],
|
|
||||||
'application/vnd.visionary' => 'vis',
|
|
||||||
'application/vnd.vsf' => 'vsf',
|
|
||||||
'application/vnd.wap.wbxml' => 'wbxml',
|
|
||||||
'application/vnd.wap.wmlc' => 'wmlc',
|
|
||||||
'application/vnd.wap.wmlscriptc' => 'wmlsc',
|
|
||||||
'application/vnd.webturbo' => 'wtb',
|
|
||||||
'application/vnd.wolfram.player' => 'nbp',
|
|
||||||
'application/vnd.wordperfect' => 'wpd',
|
|
||||||
'application/vnd.wqd' => 'wqd',
|
|
||||||
'application/vnd.wt.stf' => 'stf',
|
|
||||||
'application/vnd.xara' => 'xar',
|
|
||||||
'application/vnd.xfdl' => 'xfdl',
|
|
||||||
'application/voicexml+xml' => 'vxml',
|
|
||||||
'application/widget' => 'wgt',
|
|
||||||
'application/winhlp' => 'hlp',
|
|
||||||
'application/wsdl+xml' => 'wsdl',
|
|
||||||
'application/wspolicy+xml' => 'wspolicy',
|
|
||||||
'application/x-7z-compressed' => '7z',
|
|
||||||
'application/x-bittorrent' => 'torrent',
|
|
||||||
'application/x-blorb' => ['blb', 'blorb'],
|
|
||||||
'application/x-bzip' => 'bz',
|
|
||||||
'application/x-cdlink' => 'vcd',
|
|
||||||
'application/x-cfs-compressed' => 'cfs',
|
|
||||||
'application/x-chat' => 'chat',
|
|
||||||
'application/x-chess-pgn' => 'pgn',
|
|
||||||
'application/x-conference' => 'nsc',
|
|
||||||
'application/x-cpio' => 'cpio',
|
|
||||||
'application/x-csh' => 'csh',
|
|
||||||
'application/x-debian-package' => ['deb', 'udeb'],
|
|
||||||
'application/x-dgc-compressed' => 'dgc',
|
|
||||||
'application/x-director' => [
|
|
||||||
'dir',
|
|
||||||
'dcr',
|
|
||||||
'dxr',
|
|
||||||
'cst',
|
|
||||||
'cct',
|
|
||||||
'cxt',
|
|
||||||
'w3d',
|
|
||||||
'fgd',
|
|
||||||
'swa',
|
|
||||||
],
|
|
||||||
'application/x-font-ttf' => ['ttf', 'ttc'],
|
|
||||||
'application/x-font-type1' => ['pfa', 'pfb', 'pfm', 'afm'],
|
|
||||||
'application/x-font-woff' => 'woff',
|
|
||||||
'application/x-freearc' => 'arc',
|
|
||||||
'application/x-futuresplash' => 'spl',
|
|
||||||
'application/x-gca-compressed' => 'gca',
|
|
||||||
'application/x-glulx' => 'ulx',
|
|
||||||
'application/x-gnumeric' => 'gnumeric',
|
|
||||||
'application/x-gramps-xml' => 'gramps',
|
|
||||||
'application/x-gtar' => 'gtar',
|
|
||||||
'application/x-hdf' => 'hdf',
|
|
||||||
'application/x-install-instructions' => 'install',
|
|
||||||
'application/x-iso9660-image' => 'iso',
|
|
||||||
'application/x-java-jnlp-file' => 'jnlp',
|
|
||||||
'application/x-latex' => 'latex',
|
|
||||||
'application/x-lzh-compressed' => ['lzh', 'lha'],
|
|
||||||
'application/x-mie' => 'mie',
|
|
||||||
'application/x-mobipocket-ebook' => ['prc', 'mobi'],
|
|
||||||
'application/x-ms-application' => 'application',
|
|
||||||
'application/x-ms-shortcut' => 'lnk',
|
|
||||||
'application/x-ms-wmd' => 'wmd',
|
|
||||||
'application/x-ms-wmz' => 'wmz',
|
|
||||||
'application/x-ms-xbap' => 'xbap',
|
|
||||||
'application/x-msaccess' => 'mdb',
|
|
||||||
'application/x-msbinder' => 'obd',
|
|
||||||
'application/x-mscardfile' => 'crd',
|
|
||||||
'application/x-msclip' => 'clp',
|
|
||||||
'application/x-msdownload' => ['exe', 'dll', 'com', 'bat', 'msi'],
|
|
||||||
'application/x-msmediaview' => [
|
|
||||||
'mvb',
|
|
||||||
'm13',
|
|
||||||
'm14',
|
|
||||||
],
|
|
||||||
'application/x-msmetafile' => ['wmf', 'wmz', 'emf', 'emz'],
|
|
||||||
'application/x-rar-compressed' => 'rar',
|
|
||||||
'application/x-research-info-systems' => 'ris',
|
|
||||||
'application/x-sh' => 'sh',
|
|
||||||
'application/x-shar' => 'shar',
|
|
||||||
'application/x-shockwave-flash' => 'swf',
|
|
||||||
'application/x-silverlight-app' => 'xap',
|
|
||||||
'application/x-sql' => 'sql',
|
|
||||||
'application/x-stuffit' => 'sit',
|
|
||||||
'application/x-stuffitx' => 'sitx',
|
|
||||||
'application/x-subrip' => 'srt',
|
|
||||||
'application/x-sv4cpio' => 'sv4cpio',
|
|
||||||
'application/x-sv4crc' => 'sv4crc',
|
|
||||||
'application/x-t3vm-image' => 't3',
|
|
||||||
'application/x-tads' => 'gam',
|
|
||||||
'application/x-tar' => 'tar',
|
|
||||||
'application/x-tcl' => 'tcl',
|
|
||||||
'application/x-tex' => 'tex',
|
|
||||||
'application/x-tex-tfm' => 'tfm',
|
|
||||||
'application/x-texinfo' => ['texinfo', 'texi'],
|
|
||||||
'application/x-tgif' => 'obj',
|
|
||||||
'application/x-ustar' => 'ustar',
|
|
||||||
'application/x-wais-source' => 'src',
|
|
||||||
'application/x-x509-ca-cert' => ['der', 'crt'],
|
|
||||||
'application/x-xfig' => 'fig',
|
|
||||||
'application/x-xliff+xml' => 'xlf',
|
|
||||||
'application/x-xpinstall' => 'xpi',
|
|
||||||
'application/x-xz' => 'xz',
|
|
||||||
'application/x-zmachine' => 'z1',
|
|
||||||
'application/xaml+xml' => 'xaml',
|
|
||||||
'application/xcap-diff+xml' => 'xdf',
|
|
||||||
'application/xenc+xml' => 'xenc',
|
|
||||||
'application/xhtml+xml' => ['xhtml', 'xht'],
|
|
||||||
'application/xml' => ['xml', 'xsl'],
|
|
||||||
'application/xml-dtd' => 'dtd',
|
|
||||||
'application/xop+xml' => 'xop',
|
|
||||||
'application/xproc+xml' => 'xpl',
|
|
||||||
'application/xslt+xml' => 'xslt',
|
|
||||||
'application/xspf+xml' => 'xspf',
|
|
||||||
'application/xv+xml' => ['mxml', 'xhvml', 'xvml', 'xvm'],
|
|
||||||
'application/yang' => 'yang',
|
|
||||||
'application/yin+xml' => 'yin',
|
|
||||||
'application/zip' => 'zip',
|
|
||||||
'audio/adpcm' => 'adp',
|
|
||||||
'audio/basic' => ['au', 'snd'],
|
|
||||||
'audio/midi' => ['mid', 'midi', 'kar', 'rmi'],
|
|
||||||
'audio/mp4' => 'mp4a',
|
|
||||||
'audio/mpeg' => [
|
|
||||||
'mpga',
|
|
||||||
'mp2',
|
|
||||||
'mp2a',
|
|
||||||
'mp3',
|
|
||||||
'm2a',
|
|
||||||
'm3a',
|
|
||||||
],
|
|
||||||
'audio/ogg' => ['oga', 'ogg', 'spx'],
|
|
||||||
'audio/vnd.dece.audio' => ['uva', 'uvva'],
|
|
||||||
'audio/vnd.rip' => 'rip',
|
|
||||||
'audio/webm' => 'weba',
|
|
||||||
'audio/x-aac' => 'aac',
|
|
||||||
'audio/x-aiff' => ['aif', 'aiff', 'aifc'],
|
|
||||||
'audio/x-caf' => 'caf',
|
|
||||||
'audio/x-flac' => 'flac',
|
|
||||||
'audio/x-matroska' => 'mka',
|
|
||||||
'audio/x-mpegurl' => 'm3u',
|
|
||||||
'audio/x-ms-wax' => 'wax',
|
|
||||||
'audio/x-ms-wma' => 'wma',
|
|
||||||
'audio/x-pn-realaudio' => ['ram', 'ra'],
|
|
||||||
'audio/x-pn-realaudio-plugin' => 'rmp',
|
|
||||||
'audio/x-wav' => 'wav',
|
|
||||||
'audio/xm' => 'xm',
|
|
||||||
'image/bmp' => 'bmp',
|
|
||||||
'image/cgm' => 'cgm',
|
|
||||||
'image/g3fax' => 'g3',
|
|
||||||
'image/gif' => 'gif',
|
|
||||||
'image/ief' => 'ief',
|
|
||||||
'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
|
|
||||||
'image/ktx' => 'ktx',
|
|
||||||
'image/png' => 'png',
|
|
||||||
'image/prs.btif' => 'btif',
|
|
||||||
'image/sgi' => 'sgi',
|
|
||||||
'image/svg+xml' => ['svg', 'svgz'],
|
|
||||||
'image/tiff' => ['tiff', 'tif'],
|
|
||||||
'image/vnd.adobe.photoshop' => 'psd',
|
|
||||||
'image/vnd.dece.graphic' => ['uvi', 'uvvi', 'uvg', 'uvvg'],
|
|
||||||
'image/vnd.dvb.subtitle' => 'sub',
|
|
||||||
'image/vnd.djvu' => ['djvu', 'djv'],
|
|
||||||
'image/vnd.dwg' => 'dwg',
|
|
||||||
'image/vnd.dxf' => 'dxf',
|
|
||||||
'image/vnd.fastbidsheet' => 'fbs',
|
|
||||||
'image/vnd.fpx' => 'fpx',
|
|
||||||
'image/vnd.fst' => 'fst',
|
|
||||||
'image/vnd.fujixerox.edmics-mmr' => 'mmr',
|
|
||||||
'image/vnd.fujixerox.edmics-rlc' => 'rlc',
|
|
||||||
'image/vnd.ms-modi' => 'mdi',
|
|
||||||
'image/vnd.ms-photo' => 'wdp',
|
|
||||||
'image/vnd.net-fpx' => 'npx',
|
|
||||||
'image/vnd.wap.wbmp' => 'wbmp',
|
|
||||||
'image/vnd.xiff' => 'xif',
|
|
||||||
'image/webp' => 'webp',
|
|
||||||
'image/x-3ds' => '3ds',
|
|
||||||
'image/x-cmu-raster' => 'ras',
|
|
||||||
'image/x-cmx' => 'cmx',
|
|
||||||
'image/x-freehand' => ['fh', 'fhc', 'fh4', 'fh5', 'fh7'],
|
|
||||||
'image/x-icon' => 'ico',
|
|
||||||
'image/x-mrsid-image' => 'sid',
|
|
||||||
'image/x-pcx' => 'pcx',
|
|
||||||
'image/x-pict' => ['pic', 'pct'],
|
|
||||||
'image/x-portable-anymap' => 'pnm',
|
|
||||||
'image/x-portable-bitmap' => 'pbm',
|
|
||||||
'image/x-portable-graymap' => 'pgm',
|
|
||||||
'image/x-portable-pixmap' => 'ppm',
|
|
||||||
'image/x-rgb' => 'rgb',
|
|
||||||
'image/x-tga' => 'tga',
|
|
||||||
'image/x-xbitmap' => 'xbm',
|
|
||||||
'image/x-xpixmap' => 'xpm',
|
|
||||||
'image/x-xwindowdump' => 'xwd',
|
|
||||||
'message/rfc822' => ['eml', 'mime'],
|
|
||||||
'model/iges' => ['igs', 'iges'],
|
|
||||||
'model/mesh' => ['msh', 'mesh', 'silo'],
|
|
||||||
'model/vnd.collada+xml' => 'dae',
|
|
||||||
'model/vnd.dwf' => 'dwf',
|
|
||||||
'model/vnd.gdl' => 'gdl',
|
|
||||||
'model/vnd.gtw' => 'gtw',
|
|
||||||
'model/vnd.mts' => 'mts',
|
|
||||||
'model/vnd.vtu' => 'vtu',
|
|
||||||
'model/vrml' => ['wrl', 'vrml'],
|
|
||||||
'model/x3d+binary' => 'x3db',
|
|
||||||
'model/x3d+vrml' => 'x3dv',
|
|
||||||
'model/x3d+xml' => 'x3d',
|
|
||||||
'text/cache-manifest' => 'appcache',
|
|
||||||
'text/calendar' => ['ics', 'ifb'],
|
|
||||||
'text/css' => 'css',
|
|
||||||
'text/csv' => 'csv',
|
|
||||||
'text/html' => ['html', 'htm'],
|
|
||||||
'text/n3' => 'n3',
|
|
||||||
'text/plain' => [
|
|
||||||
'txt',
|
|
||||||
'text',
|
|
||||||
'conf',
|
|
||||||
'def',
|
|
||||||
'list',
|
|
||||||
'log',
|
|
||||||
'in',
|
|
||||||
],
|
|
||||||
'text/prs.lines.tag' => 'dsc',
|
|
||||||
'text/richtext' => 'rtx',
|
|
||||||
'text/sgml' => ['sgml', 'sgm'],
|
|
||||||
'text/tab-separated-values' => 'tsv',
|
|
||||||
'text/troff' => [
|
|
||||||
't',
|
|
||||||
'tr',
|
|
||||||
'roff',
|
|
||||||
'man',
|
|
||||||
'me',
|
|
||||||
'ms',
|
|
||||||
],
|
|
||||||
'text/turtle' => 'ttl',
|
|
||||||
'text/uri-list' => ['uri', 'uris', 'urls'],
|
|
||||||
'text/vcard' => 'vcard',
|
|
||||||
'text/vnd.curl' => 'curl',
|
|
||||||
'text/vnd.curl.dcurl' => 'dcurl',
|
|
||||||
'text/vnd.curl.scurl' => 'scurl',
|
|
||||||
'text/vnd.curl.mcurl' => 'mcurl',
|
|
||||||
'text/vnd.dvb.subtitle' => 'sub',
|
|
||||||
'text/vnd.fly' => 'fly',
|
|
||||||
'text/vnd.fmi.flexstor' => 'flx',
|
|
||||||
'text/vnd.graphviz' => 'gv',
|
|
||||||
'text/vnd.in3d.3dml' => '3dml',
|
|
||||||
'text/vnd.in3d.spot' => 'spot',
|
|
||||||
'text/vnd.sun.j2me.app-descriptor' => 'jad',
|
|
||||||
'text/vnd.wap.wml' => 'wml',
|
|
||||||
'text/vnd.wap.wmlscript' => 'wmls',
|
|
||||||
'text/x-asm' => ['s', 'asm'],
|
|
||||||
'text/x-fortran' => ['f', 'for', 'f77', 'f90'],
|
|
||||||
'text/x-java-source' => 'java',
|
|
||||||
'text/x-opml' => 'opml',
|
|
||||||
'text/x-pascal' => ['p', 'pas'],
|
|
||||||
'text/x-nfo' => 'nfo',
|
|
||||||
'text/x-setext' => 'etx',
|
|
||||||
'text/x-sfv' => 'sfv',
|
|
||||||
'text/x-uuencode' => 'uu',
|
|
||||||
'text/x-vcalendar' => 'vcs',
|
|
||||||
'text/x-vcard' => 'vcf',
|
|
||||||
'video/3gpp' => '3gp',
|
|
||||||
'video/3gpp2' => '3g2',
|
|
||||||
'video/h261' => 'h261',
|
|
||||||
'video/h263' => 'h263',
|
|
||||||
'video/h264' => 'h264',
|
|
||||||
'video/jpeg' => 'jpgv',
|
|
||||||
'video/jpm' => ['jpm', 'jpgm'],
|
|
||||||
'video/mj2' => 'mj2',
|
|
||||||
'video/mp4' => 'mp4',
|
|
||||||
'video/mpeg' => ['mpeg', 'mpg', 'mpe', 'm1v', 'm2v'],
|
|
||||||
'video/ogg' => 'ogv',
|
|
||||||
'video/quicktime' => ['qt', 'mov'],
|
|
||||||
'video/vnd.dece.hd' => ['uvh', 'uvvh'],
|
|
||||||
'video/vnd.dece.mobile' => ['uvm', 'uvvm'],
|
|
||||||
'video/vnd.dece.pd' => ['uvp', 'uvvp'],
|
|
||||||
'video/vnd.dece.sd' => ['uvs', 'uvvs'],
|
|
||||||
'video/vnd.dece.video' => ['uvv', 'uvvv'],
|
|
||||||
'video/vnd.dvb.file' => 'dvb',
|
|
||||||
'video/vnd.fvt' => 'fvt',
|
|
||||||
'video/vnd.mpegurl' => ['mxu', 'm4u'],
|
|
||||||
'video/vnd.ms-playready.media.pyv' => 'pyv',
|
|
||||||
'video/vnd.uvvu.mp4' => ['uvu', 'uvvu'],
|
|
||||||
'video/vnd.vivo' => 'viv',
|
|
||||||
'video/webm' => 'webm',
|
|
||||||
'video/x-f4v' => 'f4v',
|
|
||||||
'video/x-fli' => 'fli',
|
|
||||||
'video/x-flv' => 'flv',
|
|
||||||
'video/x-m4v' => 'm4v',
|
|
||||||
'video/x-matroska' => ['mkv', 'mk3d', 'mks'],
|
|
||||||
'video/x-mng' => 'mng',
|
|
||||||
'video/x-ms-asf' => ['asf', 'asx'],
|
|
||||||
'video/x-ms-vob' => 'vob',
|
|
||||||
'video/x-ms-wm' => 'wm',
|
|
||||||
'video/x-ms-wmv' => 'wmv',
|
|
||||||
'video/x-ms-wmx' => 'wmx',
|
|
||||||
'video/x-ms-wvx' => 'wvx',
|
|
||||||
'video/x-msvideo' => 'avi',
|
|
||||||
'video/x-sgi-movie' => 'movie',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function mimeType(): string
|
|
||||||
{
|
|
||||||
return array_rand($this->mimeTypes, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function extension(): string
|
|
||||||
{
|
|
||||||
$extension = $this->mimeTypes[array_rand($this->mimeTypes, 1)];
|
|
||||||
|
|
||||||
return is_array($extension) ? $extension[array_rand($extension, 1)] : $extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function filePath(): string
|
|
||||||
{
|
|
||||||
return tempnam(sys_get_temp_dir(), 'faker');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-83
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Number implements Extension\NumberExtension
|
|
||||||
{
|
|
||||||
public function numberBetween(int $min = 0, int $max = 2147483647): int
|
|
||||||
{
|
|
||||||
$int1 = min($min, $max);
|
|
||||||
$int2 = max($min, $max);
|
|
||||||
|
|
||||||
return mt_rand($int1, $int2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomDigit(): int
|
|
||||||
{
|
|
||||||
return $this->numberBetween(0, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomDigitNot(int $except): int
|
|
||||||
{
|
|
||||||
$result = $this->numberBetween(0, 8);
|
|
||||||
|
|
||||||
if ($result >= $except) {
|
|
||||||
++$result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomDigitNotZero(): int
|
|
||||||
{
|
|
||||||
return $this->numberBetween(1, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomFloat(?int $nbMaxDecimals = null, float $min = 0, ?float $max = null): float
|
|
||||||
{
|
|
||||||
if (null === $nbMaxDecimals) {
|
|
||||||
$nbMaxDecimals = $this->randomDigit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $max) {
|
|
||||||
$max = $this->randomNumber();
|
|
||||||
|
|
||||||
if ($min > $max) {
|
|
||||||
$max = $min;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($min > $max) {
|
|
||||||
$tmp = $min;
|
|
||||||
$min = $max;
|
|
||||||
$max = $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return round($min + $this->numberBetween() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function randomNumber(?int $nbDigits = null, bool $strict = false): int
|
|
||||||
{
|
|
||||||
if (null === $nbDigits) {
|
|
||||||
$nbDigits = $this->randomDigitNotZero();
|
|
||||||
}
|
|
||||||
$max = 10 ** $nbDigits - 1;
|
|
||||||
|
|
||||||
if ($max > mt_getrandmax()) {
|
|
||||||
throw new \InvalidArgumentException('randomNumber() can only generate numbers up to mt_getrandmax()');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($strict) {
|
|
||||||
return $this->numberBetween(10 ** ($nbDigits - 1), $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->numberBetween(0, $max);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Uuid implements Extension\UuidExtension
|
|
||||||
{
|
|
||||||
private Extension\NumberExtension $numberExtension;
|
|
||||||
|
|
||||||
public function __construct(?Extension\NumberExtension $numberExtension = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->numberExtension = $numberExtension ?: new Number();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function uuid3(): string
|
|
||||||
{
|
|
||||||
// fix for compatibility with 32bit architecture; each mt_rand call is restricted to 32bit
|
|
||||||
// two such calls will cause 64bits of randomness regardless of architecture
|
|
||||||
$seed = $this->numberExtension->numberBetween(0, 2147483647) . '#' . $this->numberExtension->numberBetween(0, 2147483647);
|
|
||||||
|
|
||||||
// Hash the seed and convert to a byte array
|
|
||||||
$val = md5($seed, true);
|
|
||||||
$byte = array_values(unpack('C16', $val));
|
|
||||||
|
|
||||||
// extract fields from byte array
|
|
||||||
$tLo = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) | $byte[3];
|
|
||||||
$tMi = ($byte[4] << 8) | $byte[5];
|
|
||||||
$tHi = ($byte[6] << 8) | $byte[7];
|
|
||||||
$csLo = $byte[9];
|
|
||||||
$csHi = $byte[8] & 0x3f | (1 << 7);
|
|
||||||
|
|
||||||
// correct byte order for big edian architecture
|
|
||||||
if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {
|
|
||||||
$tLo = (($tLo & 0x000000ff) << 24) | (($tLo & 0x0000ff00) << 8)
|
|
||||||
| (($tLo & 0x00ff0000) >> 8) | (($tLo & 0xff000000) >> 24);
|
|
||||||
$tMi = (($tMi & 0x00ff) << 8) | (($tMi & 0xff00) >> 8);
|
|
||||||
$tHi = (($tHi & 0x00ff) << 8) | (($tHi & 0xff00) >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply version number
|
|
||||||
$tHi &= 0x0fff;
|
|
||||||
$tHi |= (3 << 12);
|
|
||||||
|
|
||||||
// cast to string
|
|
||||||
return sprintf(
|
|
||||||
'%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x',
|
|
||||||
$tLo,
|
|
||||||
$tMi,
|
|
||||||
$tHi,
|
|
||||||
$csHi,
|
|
||||||
$csLo,
|
|
||||||
$byte[10],
|
|
||||||
$byte[11],
|
|
||||||
$byte[12],
|
|
||||||
$byte[13],
|
|
||||||
$byte[14],
|
|
||||||
$byte[15],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Core;
|
|
||||||
|
|
||||||
use Faker\Extension;
|
|
||||||
use Faker\Provider\DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Version implements Extension\VersionExtension
|
|
||||||
{
|
|
||||||
private Extension\NumberExtension $numberExtension;
|
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private array $semverCommonPreReleaseIdentifiers = ['alpha', 'beta', 'rc'];
|
|
||||||
|
|
||||||
public function __construct(?Extension\NumberExtension $numberExtension = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->numberExtension = $numberExtension ?: new Number();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents v2.0.0 of the semantic versioning: https://semver.org/spec/v2.0.0.html
|
|
||||||
*/
|
|
||||||
public function semver(bool $preRelease = false, bool $build = false): string
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'%d.%d.%d%s%s',
|
|
||||||
$this->numberExtension->numberBetween(0, 9),
|
|
||||||
$this->numberExtension->numberBetween(0, 99),
|
|
||||||
$this->numberExtension->numberBetween(0, 99),
|
|
||||||
$preRelease && $this->numberExtension->numberBetween(0, 1) === 1 ? '-' . $this->semverPreReleaseIdentifier() : '',
|
|
||||||
$build && $this->numberExtension->numberBetween(0, 1) === 1 ? '+' . $this->semverBuildIdentifier() : '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common pre-release identifier
|
|
||||||
*/
|
|
||||||
private function semverPreReleaseIdentifier(): string
|
|
||||||
{
|
|
||||||
$ident = Extension\Helper::randomElement($this->semverCommonPreReleaseIdentifiers);
|
|
||||||
|
|
||||||
if ($this->numberExtension->numberBetween(0, 1) !== 1) {
|
|
||||||
return $ident;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ident . '.' . $this->numberExtension->numberBetween(1, 99);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common random build identifier
|
|
||||||
*/
|
|
||||||
private function semverBuildIdentifier(): string
|
|
||||||
{
|
|
||||||
if ($this->numberExtension->numberBetween(0, 1) === 1) {
|
|
||||||
// short git revision syntax: https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection
|
|
||||||
return substr(sha1(Extension\Helper::lexify('??????')), 0, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
// date syntax
|
|
||||||
return DateTime::date('YmdHis');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This generator returns a default value for all called properties
|
|
||||||
* and methods.
|
|
||||||
*
|
|
||||||
* @mixin Generator
|
|
||||||
*
|
|
||||||
* @deprecated Use ChanceGenerator instead
|
|
||||||
*/
|
|
||||||
class DefaultGenerator
|
|
||||||
{
|
|
||||||
protected $default;
|
|
||||||
|
|
||||||
public function __construct($default = null)
|
|
||||||
{
|
|
||||||
trigger_deprecation('fakerphp/faker', '1.16', 'Class "%s" is deprecated, use "%s" instead.', __CLASS__, ChanceGenerator::class);
|
|
||||||
|
|
||||||
$this->default = $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ext()
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $attribute
|
|
||||||
*
|
|
||||||
* @deprecated Use a method instead.
|
|
||||||
*/
|
|
||||||
public function __get($attribute)
|
|
||||||
{
|
|
||||||
trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute);
|
|
||||||
|
|
||||||
return $this->default;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $method
|
|
||||||
* @param array $attributes
|
|
||||||
*/
|
|
||||||
public function __call($method, $attributes)
|
|
||||||
{
|
|
||||||
return $this->default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker;
|
|
||||||
|
|
||||||
class Documentor
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getFormatters()
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$providers = array_reverse($this->generator->getProviders());
|
|
||||||
$providers[] = new Provider\Base($this->generator);
|
|
||||||
|
|
||||||
foreach ($providers as $provider) {
|
|
||||||
$providerClass = get_class($provider);
|
|
||||||
$formatters[$providerClass] = [];
|
|
||||||
$refl = new \ReflectionObject($provider);
|
|
||||||
|
|
||||||
foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflmethod) {
|
|
||||||
if ($reflmethod->getDeclaringClass()->getName() == 'Faker\Provider\Base' && $providerClass != 'Faker\Provider\Base') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$methodName = $reflmethod->name;
|
|
||||||
|
|
||||||
if ($reflmethod->isConstructor()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$parameters = [];
|
|
||||||
|
|
||||||
foreach ($reflmethod->getParameters() as $reflparameter) {
|
|
||||||
$parameter = '$' . $reflparameter->getName();
|
|
||||||
|
|
||||||
if ($reflparameter->isDefaultValueAvailable()) {
|
|
||||||
$parameter .= ' = ' . var_export($reflparameter->getDefaultValue(), true);
|
|
||||||
}
|
|
||||||
$parameters[] = $parameter;
|
|
||||||
}
|
|
||||||
$parameters = $parameters ? '(' . implode(', ', $parameters) . ')' : '';
|
|
||||||
|
|
||||||
try {
|
|
||||||
$example = $this->generator->format($methodName);
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
$example = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($example)) {
|
|
||||||
$example = "array('" . implode("', '", $example) . "')";
|
|
||||||
} elseif ($example instanceof \DateTime) {
|
|
||||||
$example = "DateTime('" . $example->format('Y-m-d H:i:s') . "')";
|
|
||||||
} elseif ($example instanceof Generator || $example instanceof UniqueGenerator) { // modifier
|
|
||||||
$example = '';
|
|
||||||
} else {
|
|
||||||
$example = var_export($example, true);
|
|
||||||
}
|
|
||||||
$formatters[$providerClass][$methodName . $parameters] = $example;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface AddressExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @example '791 Crist Parks, Sashabury, IL 86039-9874'
|
|
||||||
*/
|
|
||||||
public function address(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Randomly return a real city name.
|
|
||||||
*/
|
|
||||||
public function city(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 86039-9874
|
|
||||||
*/
|
|
||||||
public function postcode(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Crist Parks'
|
|
||||||
*/
|
|
||||||
public function streetName(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '791 Crist Parks'
|
|
||||||
*/
|
|
||||||
public function streetAddress(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Randomly return a building number.
|
|
||||||
*/
|
|
||||||
public function buildingNumber(): string;
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface BarcodeExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get a random EAN13 barcode.
|
|
||||||
*
|
|
||||||
* @example '4006381333931'
|
|
||||||
*/
|
|
||||||
public function ean13(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random EAN8 barcode.
|
|
||||||
*
|
|
||||||
* @example '73513537'
|
|
||||||
*/
|
|
||||||
public function ean8(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random ISBN-10 code
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
|
||||||
*
|
|
||||||
* @example '4881416324'
|
|
||||||
*/
|
|
||||||
public function isbn10(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random ISBN-13 code
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
|
||||||
*
|
|
||||||
* @example '9790404436093'
|
|
||||||
*/
|
|
||||||
public function isbn13(): string;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface BloodExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get an actual blood type
|
|
||||||
*
|
|
||||||
* @example 'AB'
|
|
||||||
*/
|
|
||||||
public function bloodType(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random resis value
|
|
||||||
*
|
|
||||||
* @example '+'
|
|
||||||
*/
|
|
||||||
public function bloodRh(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a full blood group
|
|
||||||
*
|
|
||||||
* @example 'AB+'
|
|
||||||
*/
|
|
||||||
public function bloodGroup(): string;
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface ColorExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @example '#fa3cc2'
|
|
||||||
*/
|
|
||||||
public function hexColor(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '#ff0044'
|
|
||||||
*/
|
|
||||||
public function safeHexColor(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'array(0,255,122)'
|
|
||||||
*
|
|
||||||
* @return int[]
|
|
||||||
*/
|
|
||||||
public function rgbColorAsArray(): array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '0,255,122'
|
|
||||||
*/
|
|
||||||
public function rgbColor(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'rgb(0,255,122)'
|
|
||||||
*/
|
|
||||||
public function rgbCssColor(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'rgba(0,255,122,0.8)'
|
|
||||||
*/
|
|
||||||
public function rgbaCssColor(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'blue'
|
|
||||||
*/
|
|
||||||
public function safeColorName(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'NavajoWhite'
|
|
||||||
*/
|
|
||||||
public function colorName(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '340,50,20'
|
|
||||||
*/
|
|
||||||
public function hslColor(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example array(340, 50, 20)
|
|
||||||
*
|
|
||||||
* @return int[]
|
|
||||||
*/
|
|
||||||
public function hslColorAsArray(): array;
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface CompanyExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @example 'Acme Ltd'
|
|
||||||
*/
|
|
||||||
public function company(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Ltd'
|
|
||||||
*/
|
|
||||||
public function companySuffix(): string;
|
|
||||||
|
|
||||||
public function jobTitle(): string;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface CountryExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @example 'Japan'
|
|
||||||
*/
|
|
||||||
public function country(): string;
|
|
||||||
}
|
|
||||||
@@ -1,242 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FakerPHP extension for Date-related randomization.
|
|
||||||
*
|
|
||||||
* Functions accepting a date string use the `strtotime()` function internally.
|
|
||||||
*
|
|
||||||
* @experimental
|
|
||||||
*
|
|
||||||
* @since 1.20.0
|
|
||||||
*/
|
|
||||||
interface DateTimeExtension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get a DateTime object between January 1, 1970, and `$until` (defaults to "now").
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*
|
|
||||||
* @example DateTime('2005-08-16 20:39:21')
|
|
||||||
*/
|
|
||||||
public function dateTime($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a DateTime object for a date between January 1, 0001, and now.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @example DateTime('1265-03-22 21:15:52')
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeAD($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a DateTime object a random date between `$from` and `$until`.
|
|
||||||
* Accepts date strings that can be recognized by `strtotime()`.
|
|
||||||
*
|
|
||||||
* @param \DateTime|string $from defaults to 30 years ago
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeBetween($from = '-30 years', $until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a DateTime object based on a random date between `$from` and an interval.
|
|
||||||
* Accepts date string that can be recognized by `strtotime()`.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $from defaults to 30 years ago
|
|
||||||
* @param string $interval defaults to 5 days after
|
|
||||||
* @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere inside the current week.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeThisWeek($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere inside the current month.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeThisMonth($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere inside the current year.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeThisYear($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere inside the current decade.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeThisDecade($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere inside the current century.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
* @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`.
|
|
||||||
*
|
|
||||||
* @see \DateTimeZone
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public function dateTimeThisCentury($until = 'now', ?string $timezone = null): \DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date string between January 1, 1970, and `$until`.
|
|
||||||
*
|
|
||||||
* @param string $format DateTime format
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @see https://www.php.net/manual/en/datetime.format.php
|
|
||||||
*/
|
|
||||||
public function date(string $format = 'Y-m-d', $until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a time string (24h format by default).
|
|
||||||
*
|
|
||||||
* @param string $format DateTime format
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @see https://www.php.net/manual/en/datetime.format.php
|
|
||||||
*/
|
|
||||||
public function time(string $format = 'H:i:s', $until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a UNIX (POSIX-compatible) timestamp between January 1, 1970, and `$until`.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*/
|
|
||||||
public function unixTime($until = 'now'): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date string according to the ISO-8601 standard.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*/
|
|
||||||
public function iso8601($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string containing either "am" or "pm".
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @example 'am'
|
|
||||||
*/
|
|
||||||
public function amPm($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a localized random day of the month.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @example '16'
|
|
||||||
*/
|
|
||||||
public function dayOfMonth($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a localized random day of the week.
|
|
||||||
*
|
|
||||||
* Uses internal DateTime formatting, hence PHP's internal locale will be used (change using `setlocale()`).
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @example 'Tuesday'
|
|
||||||
*
|
|
||||||
* @see setlocale
|
|
||||||
* @see https://www.php.net/manual/en/function.setlocale.php Set a different output language
|
|
||||||
*/
|
|
||||||
public function dayOfWeek($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random month (numbered).
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @example '7'
|
|
||||||
*/
|
|
||||||
public function month($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random month.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @see setlocale
|
|
||||||
* @see https://www.php.net/manual/en/function.setlocale.php Set a different output language
|
|
||||||
*
|
|
||||||
* @example 'September'
|
|
||||||
*/
|
|
||||||
public function monthName($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random year between 1970 and `$until`.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $until maximum timestamp, defaults to "now"
|
|
||||||
*
|
|
||||||
* @example '1987'
|
|
||||||
*/
|
|
||||||
public function year($until = 'now'): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random century, formatted as Roman numerals.
|
|
||||||
*
|
|
||||||
* @example 'XVII'
|
|
||||||
*/
|
|
||||||
public function century(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random timezone, uses `\DateTimeZone::listIdentifiers()` internally.
|
|
||||||
*
|
|
||||||
* @param string|null $countryCode two-letter ISO 3166-1 compatible country code
|
|
||||||
*
|
|
||||||
* @example 'Europe/Rome'
|
|
||||||
*/
|
|
||||||
public function timezone(?string $countryCode = null): string;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An extension is the only way to add new functionality to Faker.
|
|
||||||
*
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface Extension
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class ExtensionNotFound extends \LogicException
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface FileExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get a random MIME type
|
|
||||||
*
|
|
||||||
* @example 'video/avi'
|
|
||||||
*/
|
|
||||||
public function mimeType(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random file extension (without a dot)
|
|
||||||
*
|
|
||||||
* @example avi
|
|
||||||
*/
|
|
||||||
public function extension(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a full path to a new real file on the system.
|
|
||||||
*/
|
|
||||||
public function filePath(): string;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface GeneratorAwareExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* This method MUST be implemented in such a way as to retain the
|
|
||||||
* immutability of the extension, and MUST return an instance that has the
|
|
||||||
* new Generator.
|
|
||||||
*/
|
|
||||||
public function withGenerator(Generator $generator): Extension;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A helper trait to be used with GeneratorAwareExtension.
|
|
||||||
*/
|
|
||||||
trait GeneratorAwareExtensionTrait
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Generator|null
|
|
||||||
*/
|
|
||||||
private $generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return static
|
|
||||||
*/
|
|
||||||
public function withGenerator(Generator $generator): Extension
|
|
||||||
{
|
|
||||||
$instance = clone $this;
|
|
||||||
|
|
||||||
$instance->generator = $generator;
|
|
||||||
|
|
||||||
return $instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class with some methods that may make building extensions easier.
|
|
||||||
*
|
|
||||||
* @experimental This class is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
final class Helper
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns a random element from a passed array.
|
|
||||||
*/
|
|
||||||
public static function randomElement(array $array)
|
|
||||||
{
|
|
||||||
if ($array === []) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array[array_rand($array, 1)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all hash sign ('#') occurrences with a random number
|
|
||||||
* Replaces all percentage sign ('%') occurrences with a non-zero number.
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*/
|
|
||||||
public static function numerify(string $string): string
|
|
||||||
{
|
|
||||||
// instead of using randomDigit() several times, which is slow,
|
|
||||||
// count the number of hashes and generate once a large number
|
|
||||||
$toReplace = [];
|
|
||||||
|
|
||||||
if (($pos = strpos($string, '#')) !== false) {
|
|
||||||
for ($i = $pos, $last = strrpos($string, '#', $pos) + 1; $i < $last; ++$i) {
|
|
||||||
if ($string[$i] === '#') {
|
|
||||||
$toReplace[] = $i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($nbReplacements = count($toReplace)) {
|
|
||||||
$maxAtOnce = strlen((string) mt_getrandmax()) - 1;
|
|
||||||
$numbers = '';
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
while ($i < $nbReplacements) {
|
|
||||||
$size = min($nbReplacements - $i, $maxAtOnce);
|
|
||||||
$numbers .= str_pad((string) mt_rand(0, 10 ** $size - 1), $size, '0', STR_PAD_LEFT);
|
|
||||||
$i += $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 0; $i < $nbReplacements; ++$i) {
|
|
||||||
$string[$toReplace[$i]] = $numbers[$i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::replaceWildcard($string, '%', static function () {
|
|
||||||
return mt_rand(1, 9);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all question mark ('?') occurrences with a random letter.
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*/
|
|
||||||
public static function lexify(string $string): string
|
|
||||||
{
|
|
||||||
return self::replaceWildcard($string, '?', static function () {
|
|
||||||
return chr(mt_rand(97, 122));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces hash signs ('#') and question marks ('?') with random numbers and letters
|
|
||||||
* An asterisk ('*') is replaced with either a random number or a random letter.
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*/
|
|
||||||
public static function bothify(string $string): string
|
|
||||||
{
|
|
||||||
$string = self::replaceWildcard($string, '*', static function () {
|
|
||||||
return mt_rand(0, 1) === 1 ? '#' : '?';
|
|
||||||
});
|
|
||||||
|
|
||||||
return self::lexify(self::numerify($string));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function replaceWildcard(string $string, string $wildcard, callable $callback): string
|
|
||||||
{
|
|
||||||
if (($pos = strpos($string, $wildcard)) === false) {
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = $pos, $last = strrpos($string, $wildcard, $pos) + 1; $i < $last; ++$i) {
|
|
||||||
if ($string[$i] === $wildcard) {
|
|
||||||
$string[$i] = call_user_func($callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface NumberExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns a random number between $int1 and $int2 (any order)
|
|
||||||
*
|
|
||||||
* @param int $min default to 0
|
|
||||||
* @param int $max defaults to 32 bit max integer, ie 2147483647
|
|
||||||
*
|
|
||||||
* @example 79907610
|
|
||||||
*/
|
|
||||||
public function numberBetween(int $min, int $max): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between 0 and 9
|
|
||||||
*/
|
|
||||||
public function randomDigit(): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a random digit, which cannot be $except
|
|
||||||
*/
|
|
||||||
public function randomDigitNot(int $except): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between 1 and 9
|
|
||||||
*/
|
|
||||||
public function randomDigitNotZero(): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random float number
|
|
||||||
*
|
|
||||||
* @example 48.8932
|
|
||||||
*/
|
|
||||||
public function randomFloat(?int $nbMaxDecimals, float $min, ?float $max): float;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random integer with 0 to $nbDigits digits.
|
|
||||||
*
|
|
||||||
* The maximum value returned is mt_getrandmax()
|
|
||||||
*
|
|
||||||
* @param int|null $nbDigits Defaults to a random number between 1 and 9
|
|
||||||
* @param bool $strict Whether the returned number should have exactly $nbDigits
|
|
||||||
*
|
|
||||||
* @example 79907610
|
|
||||||
*/
|
|
||||||
public function randomNumber(?int $nbDigits, bool $strict): int;
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface PersonExtension extends Extension
|
|
||||||
{
|
|
||||||
public const GENDER_FEMALE = 'female';
|
|
||||||
public const GENDER_MALE = 'male';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $gender 'male', 'female' or null for any
|
|
||||||
*
|
|
||||||
* @example 'John Doe'
|
|
||||||
*/
|
|
||||||
public function name(?string $gender = null): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $gender 'male', 'female' or null for any
|
|
||||||
*
|
|
||||||
* @example 'John'
|
|
||||||
*/
|
|
||||||
public function firstName(?string $gender = null): string;
|
|
||||||
|
|
||||||
public function firstNameMale(): string;
|
|
||||||
|
|
||||||
public function firstNameFemale(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Doe'
|
|
||||||
*/
|
|
||||||
public function lastName(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Mrs.'
|
|
||||||
*
|
|
||||||
* @param string|null $gender 'male', 'female' or null for any
|
|
||||||
*/
|
|
||||||
public function title(?string $gender = null): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Mr.'
|
|
||||||
*/
|
|
||||||
public function titleMale(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Mrs.'
|
|
||||||
*/
|
|
||||||
public function titleFemale(): string;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface PhoneNumberExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @example '555-123-546'
|
|
||||||
*/
|
|
||||||
public function phoneNumber(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example +27113456789
|
|
||||||
*/
|
|
||||||
public function e164PhoneNumber(): string;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface UuidExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Generate name based md5 UUID (version 3).
|
|
||||||
*
|
|
||||||
* @example '7e57d004-2b97-0e7a-b45f-5387367791cd'
|
|
||||||
*/
|
|
||||||
public function uuid3(): string;
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Extension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental This interface is experimental and does not fall under our BC promise
|
|
||||||
*/
|
|
||||||
interface VersionExtension extends Extension
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get a version number in semantic versioning syntax 2.0.0. (https://semver.org/spec/v2.0.0.html)
|
|
||||||
*
|
|
||||||
* @param bool $preRelease Pre release parts may be randomly included
|
|
||||||
* @param bool $build Build parts may be randomly included
|
|
||||||
*
|
|
||||||
* @example 1.0.0
|
|
||||||
* @example 1.0.0-alpha.1
|
|
||||||
* @example 1.0.0-alpha.1+b71f04d
|
|
||||||
*/
|
|
||||||
public function semver(bool $preRelease = false, bool $build = false): string;
|
|
||||||
}
|
|
||||||
-71
@@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker;
|
|
||||||
|
|
||||||
class Factory
|
|
||||||
{
|
|
||||||
public const DEFAULT_LOCALE = 'en_US';
|
|
||||||
|
|
||||||
protected static $defaultProviders = ['Address', 'Barcode', 'Biased', 'Color', 'Company', 'DateTime', 'File', 'HtmlLorem', 'Image', 'Internet', 'Lorem', 'Medical', 'Miscellaneous', 'Payment', 'Person', 'PhoneNumber', 'Text', 'UserAgent', 'Uuid'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new generator
|
|
||||||
*
|
|
||||||
* @param string $locale
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public static function create($locale = self::DEFAULT_LOCALE)
|
|
||||||
{
|
|
||||||
$generator = new Generator();
|
|
||||||
|
|
||||||
foreach (static::$defaultProviders as $provider) {
|
|
||||||
$providerClassName = self::getProviderClassname($provider, $locale);
|
|
||||||
$generator->addProvider(new $providerClassName($generator));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $provider
|
|
||||||
* @param string $locale
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected static function getProviderClassname($provider, $locale = '')
|
|
||||||
{
|
|
||||||
if ($providerClass = self::findProviderClassname($provider, $locale)) {
|
|
||||||
return $providerClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback to default locale
|
|
||||||
if ($providerClass = self::findProviderClassname($provider, static::DEFAULT_LOCALE)) {
|
|
||||||
return $providerClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback to no locale
|
|
||||||
if ($providerClass = self::findProviderClassname($provider)) {
|
|
||||||
return $providerClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf('Unable to find provider "%s" with locale "%s"', $provider, $locale));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $provider
|
|
||||||
* @param string $locale
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
protected static function findProviderClassname($provider, $locale = '')
|
|
||||||
{
|
|
||||||
$providerClass = 'Faker\\' . ($locale ? sprintf('Provider\%s\%s', $locale, $provider) : sprintf('Provider\%s', $provider));
|
|
||||||
|
|
||||||
if (class_exists($providerClass, true)) {
|
|
||||||
return $providerClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-985
@@ -1,985 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker;
|
|
||||||
|
|
||||||
use Faker\Container\ContainerInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property string $citySuffix
|
|
||||||
*
|
|
||||||
* @method string citySuffix()
|
|
||||||
*
|
|
||||||
* @property string $streetSuffix
|
|
||||||
*
|
|
||||||
* @method string streetSuffix()
|
|
||||||
*
|
|
||||||
* @property string $buildingNumber
|
|
||||||
*
|
|
||||||
* @method string buildingNumber()
|
|
||||||
*
|
|
||||||
* @property string $city
|
|
||||||
*
|
|
||||||
* @method string city()
|
|
||||||
*
|
|
||||||
* @property string $streetName
|
|
||||||
*
|
|
||||||
* @method string streetName()
|
|
||||||
*
|
|
||||||
* @property string $streetAddress
|
|
||||||
*
|
|
||||||
* @method string streetAddress()
|
|
||||||
*
|
|
||||||
* @property string $postcode
|
|
||||||
*
|
|
||||||
* @method string postcode()
|
|
||||||
*
|
|
||||||
* @property string $address
|
|
||||||
*
|
|
||||||
* @method string address()
|
|
||||||
*
|
|
||||||
* @property string $country
|
|
||||||
*
|
|
||||||
* @method string country()
|
|
||||||
*
|
|
||||||
* @property float $latitude
|
|
||||||
*
|
|
||||||
* @method float latitude($min = -90, $max = 90)
|
|
||||||
*
|
|
||||||
* @property float $longitude
|
|
||||||
*
|
|
||||||
* @method float longitude($min = -180, $max = 180)
|
|
||||||
*
|
|
||||||
* @property float[] $localCoordinates
|
|
||||||
*
|
|
||||||
* @method float[] localCoordinates()
|
|
||||||
*
|
|
||||||
* @property int $randomDigitNotNull
|
|
||||||
*
|
|
||||||
* @method int randomDigitNotNull()
|
|
||||||
*
|
|
||||||
* @property mixed $passthrough
|
|
||||||
*
|
|
||||||
* @method mixed passthrough($value)
|
|
||||||
*
|
|
||||||
* @property string $randomLetter
|
|
||||||
*
|
|
||||||
* @method string randomLetter()
|
|
||||||
*
|
|
||||||
* @property string $randomAscii
|
|
||||||
*
|
|
||||||
* @method string randomAscii()
|
|
||||||
*
|
|
||||||
* @property array $randomElements
|
|
||||||
*
|
|
||||||
* @method array randomElements($array = ['a', 'b', 'c'], $count = 1, $allowDuplicates = false)
|
|
||||||
*
|
|
||||||
* @property mixed $randomElement
|
|
||||||
*
|
|
||||||
* @method mixed randomElement($array = ['a', 'b', 'c'])
|
|
||||||
*
|
|
||||||
* @property int|string|null $randomKey
|
|
||||||
*
|
|
||||||
* @method int|string|null randomKey($array = [])
|
|
||||||
*
|
|
||||||
* @property array|string $shuffle
|
|
||||||
*
|
|
||||||
* @method array|string shuffle($arg = '')
|
|
||||||
*
|
|
||||||
* @property array $shuffleArray
|
|
||||||
*
|
|
||||||
* @method array shuffleArray($array = [])
|
|
||||||
*
|
|
||||||
* @property string $shuffleString
|
|
||||||
*
|
|
||||||
* @method string shuffleString($string = '', $encoding = 'UTF-8')
|
|
||||||
*
|
|
||||||
* @property string $numerify
|
|
||||||
*
|
|
||||||
* @method string numerify($string = '###')
|
|
||||||
*
|
|
||||||
* @property string $lexify
|
|
||||||
*
|
|
||||||
* @method string lexify($string = '????')
|
|
||||||
*
|
|
||||||
* @property string $bothify
|
|
||||||
*
|
|
||||||
* @method string bothify($string = '## ??')
|
|
||||||
*
|
|
||||||
* @property string $asciify
|
|
||||||
*
|
|
||||||
* @method string asciify($string = '****')
|
|
||||||
*
|
|
||||||
* @property string $regexify
|
|
||||||
*
|
|
||||||
* @method string regexify($regex = '')
|
|
||||||
*
|
|
||||||
* @property string $toLower
|
|
||||||
*
|
|
||||||
* @method string toLower($string = '')
|
|
||||||
*
|
|
||||||
* @property string $toUpper
|
|
||||||
*
|
|
||||||
* @method string toUpper($string = '')
|
|
||||||
*
|
|
||||||
* @property int $biasedNumberBetween
|
|
||||||
*
|
|
||||||
* @method int biasedNumberBetween($min = 0, $max = 100, $function = 'sqrt')
|
|
||||||
*
|
|
||||||
* @property string $hexColor
|
|
||||||
*
|
|
||||||
* @method string hexColor()
|
|
||||||
*
|
|
||||||
* @property string $safeHexColor
|
|
||||||
*
|
|
||||||
* @method string safeHexColor()
|
|
||||||
*
|
|
||||||
* @property array $rgbColorAsArray
|
|
||||||
*
|
|
||||||
* @method array rgbColorAsArray()
|
|
||||||
*
|
|
||||||
* @property string $rgbColor
|
|
||||||
*
|
|
||||||
* @method string rgbColor()
|
|
||||||
*
|
|
||||||
* @property string $rgbCssColor
|
|
||||||
*
|
|
||||||
* @method string rgbCssColor()
|
|
||||||
*
|
|
||||||
* @property string $rgbaCssColor
|
|
||||||
*
|
|
||||||
* @method string rgbaCssColor()
|
|
||||||
*
|
|
||||||
* @property string $safeColorName
|
|
||||||
*
|
|
||||||
* @method string safeColorName()
|
|
||||||
*
|
|
||||||
* @property string $colorName
|
|
||||||
*
|
|
||||||
* @method string colorName()
|
|
||||||
*
|
|
||||||
* @property string $hslColor
|
|
||||||
*
|
|
||||||
* @method string hslColor()
|
|
||||||
*
|
|
||||||
* @property array $hslColorAsArray
|
|
||||||
*
|
|
||||||
* @method array hslColorAsArray()
|
|
||||||
*
|
|
||||||
* @property string $company
|
|
||||||
*
|
|
||||||
* @method string company()
|
|
||||||
*
|
|
||||||
* @property string $companySuffix
|
|
||||||
*
|
|
||||||
* @method string companySuffix()
|
|
||||||
*
|
|
||||||
* @property string $jobTitle
|
|
||||||
*
|
|
||||||
* @method string jobTitle()
|
|
||||||
*
|
|
||||||
* @property int $unixTime
|
|
||||||
*
|
|
||||||
* @method int unixTime($max = 'now')
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTime
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTime($max = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeAD
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeAD($max = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property string $iso8601
|
|
||||||
*
|
|
||||||
* @method string iso8601($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $date
|
|
||||||
*
|
|
||||||
* @method string date($format = 'Y-m-d', $max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $time
|
|
||||||
*
|
|
||||||
* @method string time($format = 'H:i:s', $max = 'now')
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeBetween
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeInInterval
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeInInterval($date = '-30 years', $interval = '+5 days', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeThisCentury
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeThisCentury($max = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeThisDecade
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeThisDecade($max = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeThisYear
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeThisYear($max = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property \DateTime $dateTimeThisMonth
|
|
||||||
*
|
|
||||||
* @method \DateTime dateTimeThisMonth($max = 'now', $timezone = null)
|
|
||||||
*
|
|
||||||
* @property string $amPm
|
|
||||||
*
|
|
||||||
* @method string amPm($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $dayOfMonth
|
|
||||||
*
|
|
||||||
* @method string dayOfMonth($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $dayOfWeek
|
|
||||||
*
|
|
||||||
* @method string dayOfWeek($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $month
|
|
||||||
*
|
|
||||||
* @method string month($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $monthName
|
|
||||||
*
|
|
||||||
* @method string monthName($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $year
|
|
||||||
*
|
|
||||||
* @method string year($max = 'now')
|
|
||||||
*
|
|
||||||
* @property string $century
|
|
||||||
*
|
|
||||||
* @method string century()
|
|
||||||
*
|
|
||||||
* @property string $timezone
|
|
||||||
*
|
|
||||||
* @method string timezone($countryCode = null)
|
|
||||||
*
|
|
||||||
* @property void $setDefaultTimezone
|
|
||||||
*
|
|
||||||
* @method void setDefaultTimezone($timezone = null)
|
|
||||||
*
|
|
||||||
* @property string $getDefaultTimezone
|
|
||||||
*
|
|
||||||
* @method string getDefaultTimezone()
|
|
||||||
*
|
|
||||||
* @property string $file
|
|
||||||
*
|
|
||||||
* @method string file($sourceDirectory = '/tmp', $targetDirectory = '/tmp', $fullPath = true)
|
|
||||||
*
|
|
||||||
* @property string $randomHtml
|
|
||||||
*
|
|
||||||
* @method string randomHtml($maxDepth = 4, $maxWidth = 4)
|
|
||||||
*
|
|
||||||
* @property string $imageUrl
|
|
||||||
*
|
|
||||||
* @method string imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null, $gray = false, string $format = 'png')
|
|
||||||
*
|
|
||||||
* @property string $image
|
|
||||||
*
|
|
||||||
* @method string image($dir = null, $width = 640, $height = 480, $category = null, $fullPath = true, $randomize = true, $word = null, $gray = false, string $format = 'png')
|
|
||||||
*
|
|
||||||
* @property string $email
|
|
||||||
*
|
|
||||||
* @method string email()
|
|
||||||
*
|
|
||||||
* @property string $safeEmail
|
|
||||||
*
|
|
||||||
* @method string safeEmail()
|
|
||||||
*
|
|
||||||
* @property string $freeEmail
|
|
||||||
*
|
|
||||||
* @method string freeEmail()
|
|
||||||
*
|
|
||||||
* @property string $companyEmail
|
|
||||||
*
|
|
||||||
* @method string companyEmail()
|
|
||||||
*
|
|
||||||
* @property string $freeEmailDomain
|
|
||||||
*
|
|
||||||
* @method string freeEmailDomain()
|
|
||||||
*
|
|
||||||
* @property string $safeEmailDomain
|
|
||||||
*
|
|
||||||
* @method string safeEmailDomain()
|
|
||||||
*
|
|
||||||
* @property string $userName
|
|
||||||
*
|
|
||||||
* @method string userName()
|
|
||||||
*
|
|
||||||
* @property string $password
|
|
||||||
*
|
|
||||||
* @method string password($minLength = 6, $maxLength = 20)
|
|
||||||
*
|
|
||||||
* @property string $domainName
|
|
||||||
*
|
|
||||||
* @method string domainName()
|
|
||||||
*
|
|
||||||
* @property string $domainWord
|
|
||||||
*
|
|
||||||
* @method string domainWord()
|
|
||||||
*
|
|
||||||
* @property string $tld
|
|
||||||
*
|
|
||||||
* @method string tld()
|
|
||||||
*
|
|
||||||
* @property string $url
|
|
||||||
*
|
|
||||||
* @method string url()
|
|
||||||
*
|
|
||||||
* @property string $slug
|
|
||||||
*
|
|
||||||
* @method string slug($nbWords = 6, $variableNbWords = true)
|
|
||||||
*
|
|
||||||
* @property string $ipv4
|
|
||||||
*
|
|
||||||
* @method string ipv4()
|
|
||||||
*
|
|
||||||
* @property string $ipv6
|
|
||||||
*
|
|
||||||
* @method string ipv6()
|
|
||||||
*
|
|
||||||
* @property string $localIpv4
|
|
||||||
*
|
|
||||||
* @method string localIpv4()
|
|
||||||
*
|
|
||||||
* @property string $macAddress
|
|
||||||
*
|
|
||||||
* @method string macAddress()
|
|
||||||
*
|
|
||||||
* @property string $word
|
|
||||||
*
|
|
||||||
* @method string word()
|
|
||||||
*
|
|
||||||
* @property array|string $words
|
|
||||||
*
|
|
||||||
* @method array|string words($nb = 3, $asText = false)
|
|
||||||
*
|
|
||||||
* @property string $sentence
|
|
||||||
*
|
|
||||||
* @method string sentence($nbWords = 6, $variableNbWords = true)
|
|
||||||
*
|
|
||||||
* @property array|string $sentences
|
|
||||||
*
|
|
||||||
* @method array|string sentences($nb = 3, $asText = false)
|
|
||||||
*
|
|
||||||
* @property string $paragraph
|
|
||||||
*
|
|
||||||
* @method string paragraph($nbSentences = 3, $variableNbSentences = true)
|
|
||||||
*
|
|
||||||
* @property array|string $paragraphs
|
|
||||||
*
|
|
||||||
* @method array|string paragraphs($nb = 3, $asText = false)
|
|
||||||
*
|
|
||||||
* @property string $text
|
|
||||||
*
|
|
||||||
* @method string text($maxNbChars = 200)
|
|
||||||
*
|
|
||||||
* @property bool $boolean
|
|
||||||
*
|
|
||||||
* @method bool boolean($chanceOfGettingTrue = 50)
|
|
||||||
*
|
|
||||||
* @property string $md5
|
|
||||||
*
|
|
||||||
* @method string md5()
|
|
||||||
*
|
|
||||||
* @property string $sha1
|
|
||||||
*
|
|
||||||
* @method string sha1()
|
|
||||||
*
|
|
||||||
* @property string $sha256
|
|
||||||
*
|
|
||||||
* @method string sha256()
|
|
||||||
*
|
|
||||||
* @property string $locale
|
|
||||||
*
|
|
||||||
* @method string locale()
|
|
||||||
*
|
|
||||||
* @property string $countryCode
|
|
||||||
*
|
|
||||||
* @method string countryCode()
|
|
||||||
*
|
|
||||||
* @property string $countryISOAlpha3
|
|
||||||
*
|
|
||||||
* @method string countryISOAlpha3()
|
|
||||||
*
|
|
||||||
* @property string $languageCode
|
|
||||||
*
|
|
||||||
* @method string languageCode()
|
|
||||||
*
|
|
||||||
* @property string $currencyCode
|
|
||||||
*
|
|
||||||
* @method string currencyCode()
|
|
||||||
*
|
|
||||||
* @property string $emoji
|
|
||||||
*
|
|
||||||
* @method string emoji()
|
|
||||||
*
|
|
||||||
* @property string $creditCardType
|
|
||||||
*
|
|
||||||
* @method string creditCardType()
|
|
||||||
*
|
|
||||||
* @property string $creditCardNumber
|
|
||||||
*
|
|
||||||
* @method string creditCardNumber($type = null, $formatted = false, $separator = '-')
|
|
||||||
*
|
|
||||||
* @property \DateTime $creditCardExpirationDate
|
|
||||||
*
|
|
||||||
* @method \DateTime creditCardExpirationDate($valid = true)
|
|
||||||
*
|
|
||||||
* @property string $creditCardExpirationDateString
|
|
||||||
*
|
|
||||||
* @method string creditCardExpirationDateString($valid = true, $expirationDateFormat = null)
|
|
||||||
*
|
|
||||||
* @property array $creditCardDetails
|
|
||||||
*
|
|
||||||
* @method array creditCardDetails($valid = true)
|
|
||||||
*
|
|
||||||
* @property string $iban
|
|
||||||
*
|
|
||||||
* @method string iban($countryCode = null, $prefix = '', $length = null)
|
|
||||||
*
|
|
||||||
* @property string $swiftBicNumber
|
|
||||||
*
|
|
||||||
* @method string swiftBicNumber()
|
|
||||||
*
|
|
||||||
* @property string $name
|
|
||||||
*
|
|
||||||
* @method string name($gender = null)
|
|
||||||
*
|
|
||||||
* @property string $firstName
|
|
||||||
*
|
|
||||||
* @method string firstName($gender = null)
|
|
||||||
*
|
|
||||||
* @property string $firstNameMale
|
|
||||||
*
|
|
||||||
* @method string firstNameMale()
|
|
||||||
*
|
|
||||||
* @property string $firstNameFemale
|
|
||||||
*
|
|
||||||
* @method string firstNameFemale()
|
|
||||||
*
|
|
||||||
* @property string $lastName
|
|
||||||
*
|
|
||||||
* @method string lastName($gender = null)
|
|
||||||
*
|
|
||||||
* @property string $title
|
|
||||||
*
|
|
||||||
* @method string title($gender = null)
|
|
||||||
*
|
|
||||||
* @property string $titleMale
|
|
||||||
*
|
|
||||||
* @method string titleMale()
|
|
||||||
*
|
|
||||||
* @property string $titleFemale
|
|
||||||
*
|
|
||||||
* @method string titleFemale()
|
|
||||||
*
|
|
||||||
* @property string $phoneNumber
|
|
||||||
*
|
|
||||||
* @method string phoneNumber()
|
|
||||||
*
|
|
||||||
* @property string $e164PhoneNumber
|
|
||||||
*
|
|
||||||
* @method string e164PhoneNumber()
|
|
||||||
*
|
|
||||||
* @property int $imei
|
|
||||||
*
|
|
||||||
* @method int imei()
|
|
||||||
*
|
|
||||||
* @property string $realText
|
|
||||||
*
|
|
||||||
* @method string realText($maxNbChars = 200, $indexSize = 2)
|
|
||||||
*
|
|
||||||
* @property string $realTextBetween
|
|
||||||
*
|
|
||||||
* @method string realTextBetween($minNbChars = 160, $maxNbChars = 200, $indexSize = 2)
|
|
||||||
*
|
|
||||||
* @property string $macProcessor
|
|
||||||
*
|
|
||||||
* @method string macProcessor()
|
|
||||||
*
|
|
||||||
* @property string $linuxProcessor
|
|
||||||
*
|
|
||||||
* @method string linuxProcessor()
|
|
||||||
*
|
|
||||||
* @property string $userAgent
|
|
||||||
*
|
|
||||||
* @method string userAgent()
|
|
||||||
*
|
|
||||||
* @property string $chrome
|
|
||||||
*
|
|
||||||
* @method string chrome()
|
|
||||||
*
|
|
||||||
* @property string $msedge
|
|
||||||
*
|
|
||||||
* @method string msedge()
|
|
||||||
*
|
|
||||||
* @property string $firefox
|
|
||||||
*
|
|
||||||
* @method string firefox()
|
|
||||||
*
|
|
||||||
* @property string $safari
|
|
||||||
*
|
|
||||||
* @method string safari()
|
|
||||||
*
|
|
||||||
* @property string $opera
|
|
||||||
*
|
|
||||||
* @method string opera()
|
|
||||||
*
|
|
||||||
* @property string $internetExplorer
|
|
||||||
*
|
|
||||||
* @method string internetExplorer()
|
|
||||||
*
|
|
||||||
* @property string $windowsPlatformToken
|
|
||||||
*
|
|
||||||
* @method string windowsPlatformToken()
|
|
||||||
*
|
|
||||||
* @property string $macPlatformToken
|
|
||||||
*
|
|
||||||
* @method string macPlatformToken()
|
|
||||||
*
|
|
||||||
* @property string $iosMobileToken
|
|
||||||
*
|
|
||||||
* @method string iosMobileToken()
|
|
||||||
*
|
|
||||||
* @property string $linuxPlatformToken
|
|
||||||
*
|
|
||||||
* @method string linuxPlatformToken()
|
|
||||||
*
|
|
||||||
* @property string $uuid
|
|
||||||
*
|
|
||||||
* @method string uuid()
|
|
||||||
*/
|
|
||||||
class Generator
|
|
||||||
{
|
|
||||||
protected $providers = [];
|
|
||||||
protected $formatters = [];
|
|
||||||
|
|
||||||
private $container;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var UniqueGenerator
|
|
||||||
*/
|
|
||||||
private $uniqueGenerator;
|
|
||||||
|
|
||||||
public function __construct(?ContainerInterface $container = null)
|
|
||||||
{
|
|
||||||
$this->container = $container ?: Container\ContainerBuilder::withDefaultExtensions()->build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @template T of Extension\Extension
|
|
||||||
*
|
|
||||||
* @param class-string<T> $id
|
|
||||||
*
|
|
||||||
* @throws Extension\ExtensionNotFound
|
|
||||||
*
|
|
||||||
* @return T
|
|
||||||
*/
|
|
||||||
public function ext(string $id): Extension\Extension
|
|
||||||
{
|
|
||||||
if (!$this->container->has($id)) {
|
|
||||||
throw new Extension\ExtensionNotFound(sprintf(
|
|
||||||
'No Faker extension with id "%s" was loaded.',
|
|
||||||
$id,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$extension = $this->container->get($id);
|
|
||||||
|
|
||||||
if ($extension instanceof Extension\GeneratorAwareExtension) {
|
|
||||||
$extension = $extension->withGenerator($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addProvider($provider)
|
|
||||||
{
|
|
||||||
array_unshift($this->providers, $provider);
|
|
||||||
|
|
||||||
$this->formatters = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getProviders()
|
|
||||||
{
|
|
||||||
return $this->providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* With the unique generator you are guaranteed to never get the same two
|
|
||||||
* values.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* // will never return twice the same value
|
|
||||||
* $faker->unique()->randomElement(array(1, 2, 3));
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param bool $reset If set to true, resets the list of existing values
|
|
||||||
* @param int $maxRetries Maximum number of retries to find a unique value,
|
|
||||||
* After which an OverflowException is thrown.
|
|
||||||
*
|
|
||||||
* @throws \OverflowException When no unique value can be found by iterating $maxRetries times
|
|
||||||
*
|
|
||||||
* @return self A proxy class returning only non-existing values
|
|
||||||
*/
|
|
||||||
public function unique($reset = false, $maxRetries = 10000)
|
|
||||||
{
|
|
||||||
if ($reset || $this->uniqueGenerator === null) {
|
|
||||||
$this->uniqueGenerator = new UniqueGenerator($this, $maxRetries);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->uniqueGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a value only some percentage of the time.
|
|
||||||
*
|
|
||||||
* @param float $weight A probability between 0 and 1, 0 means that we always get the default value.
|
|
||||||
*
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function optional(float $weight = 0.5, $default = null)
|
|
||||||
{
|
|
||||||
if ($weight > 1) {
|
|
||||||
trigger_deprecation('fakerphp/faker', '1.16', 'First argument ($weight) to method "optional()" must be between 0 and 1. You passed %f, we assume you meant %f.', $weight, $weight / 100);
|
|
||||||
$weight = $weight / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ChanceGenerator($this, $weight, $default);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To make sure the value meet some criteria, pass a callable that verifies the
|
|
||||||
* output. If the validator fails, the generator will try again.
|
|
||||||
*
|
|
||||||
* The value validity is determined by a function passed as first argument.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* $values = array();
|
|
||||||
* $evenValidator = function ($digit) {
|
|
||||||
* return $digit % 2 === 0;
|
|
||||||
* };
|
|
||||||
* for ($i=0; $i < 10; $i++) {
|
|
||||||
* $values []= $faker->valid($evenValidator)->randomDigit;
|
|
||||||
* }
|
|
||||||
* print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param ?\Closure $validator A function returning true for valid values
|
|
||||||
* @param int $maxRetries Maximum number of retries to find a valid value,
|
|
||||||
* After which an OverflowException is thrown.
|
|
||||||
*
|
|
||||||
* @throws \OverflowException When no valid value can be found by iterating $maxRetries times
|
|
||||||
*
|
|
||||||
* @return self A proxy class returning only valid values
|
|
||||||
*/
|
|
||||||
public function valid(?\Closure $validator = null, int $maxRetries = 10000)
|
|
||||||
{
|
|
||||||
return new ValidGenerator($this, $validator, $maxRetries);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function seed($seed = null)
|
|
||||||
{
|
|
||||||
if ($seed === null) {
|
|
||||||
mt_srand();
|
|
||||||
} else {
|
|
||||||
mt_srand((int) $seed, self::mode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://www.php.net/manual/en/migration83.deprecated.php#migration83.deprecated.random
|
|
||||||
*/
|
|
||||||
private static function mode(): int
|
|
||||||
{
|
|
||||||
if (PHP_VERSION_ID < 80300) {
|
|
||||||
return MT_RAND_PHP;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MT_RAND_MT19937;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function format($format, $arguments = [])
|
|
||||||
{
|
|
||||||
return call_user_func_array($this->getFormatter($format), $arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $format
|
|
||||||
*
|
|
||||||
* @return callable
|
|
||||||
*/
|
|
||||||
public function getFormatter($format)
|
|
||||||
{
|
|
||||||
if (isset($this->formatters[$format])) {
|
|
||||||
return $this->formatters[$format];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method_exists($this, $format)) {
|
|
||||||
$this->formatters[$format] = [$this, $format];
|
|
||||||
|
|
||||||
return $this->formatters[$format];
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Faker\Core\Barcode->ean13"
|
|
||||||
if (preg_match('|^([a-zA-Z0-9\\\]+)->([a-zA-Z0-9]+)$|', $format, $matches)) {
|
|
||||||
$this->formatters[$format] = [$this->ext($matches[1]), $matches[2]];
|
|
||||||
|
|
||||||
return $this->formatters[$format];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->providers as $provider) {
|
|
||||||
if (method_exists($provider, $format)) {
|
|
||||||
$this->formatters[$format] = [$provider, $format];
|
|
||||||
|
|
||||||
return $this->formatters[$format];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf('Unknown format "%s"', $format));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces tokens ('{{ tokenName }}') with the result from the token method call
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function parse($string)
|
|
||||||
{
|
|
||||||
$callback = function ($matches) {
|
|
||||||
return $this->format($matches[1]);
|
|
||||||
};
|
|
||||||
|
|
||||||
return preg_replace_callback('/{{\s?(\w+|[\w\\\]+->\w+?)\s?}}/u', $callback, $string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random MIME type
|
|
||||||
*
|
|
||||||
* @example 'video/avi'
|
|
||||||
*/
|
|
||||||
public function mimeType()
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\FileExtension::class)->mimeType();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random file extension (without a dot)
|
|
||||||
*
|
|
||||||
* @example avi
|
|
||||||
*/
|
|
||||||
public function fileExtension()
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\FileExtension::class)->extension();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a full path to a new real file on the system.
|
|
||||||
*/
|
|
||||||
public function filePath()
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\FileExtension::class)->filePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an actual blood type
|
|
||||||
*
|
|
||||||
* @example 'AB'
|
|
||||||
*/
|
|
||||||
public function bloodType(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BloodExtension::class)->bloodType();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random resis value
|
|
||||||
*
|
|
||||||
* @example '+'
|
|
||||||
*/
|
|
||||||
public function bloodRh(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BloodExtension::class)->bloodRh();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a full blood group
|
|
||||||
*
|
|
||||||
* @example 'AB+'
|
|
||||||
*/
|
|
||||||
public function bloodGroup(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BloodExtension::class)->bloodGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random EAN13 barcode.
|
|
||||||
*
|
|
||||||
* @example '4006381333931'
|
|
||||||
*/
|
|
||||||
public function ean13(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BarcodeExtension::class)->ean13();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random EAN8 barcode.
|
|
||||||
*
|
|
||||||
* @example '73513537'
|
|
||||||
*/
|
|
||||||
public function ean8(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BarcodeExtension::class)->ean8();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random ISBN-10 code
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
|
||||||
*
|
|
||||||
* @example '4881416324'
|
|
||||||
*/
|
|
||||||
public function isbn10(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BarcodeExtension::class)->isbn10();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random ISBN-13 code
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
|
||||||
*
|
|
||||||
* @example '9790404436093'
|
|
||||||
*/
|
|
||||||
public function isbn13(): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\BarcodeExtension::class)->isbn13();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between $int1 and $int2 (any order)
|
|
||||||
*
|
|
||||||
* @example 79907610
|
|
||||||
*/
|
|
||||||
public function numberBetween($int1 = 0, $int2 = 2147483647): int
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\NumberExtension::class)->numberBetween((int) $int1, (int) $int2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between 0 and 9
|
|
||||||
*/
|
|
||||||
public function randomDigit(): int
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\NumberExtension::class)->randomDigit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a random digit, which cannot be $except
|
|
||||||
*/
|
|
||||||
public function randomDigitNot($except): int
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\NumberExtension::class)->randomDigitNot((int) $except);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between 1 and 9
|
|
||||||
*/
|
|
||||||
public function randomDigitNotZero(): int
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\NumberExtension::class)->randomDigitNotZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random float number
|
|
||||||
*
|
|
||||||
* @example 48.8932
|
|
||||||
*/
|
|
||||||
public function randomFloat($nbMaxDecimals = null, $min = 0, $max = null): float
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\NumberExtension::class)->randomFloat(
|
|
||||||
$nbMaxDecimals !== null ? (int) $nbMaxDecimals : null,
|
|
||||||
(float) $min,
|
|
||||||
$max !== null ? (float) $max : null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random integer with 0 to $nbDigits digits.
|
|
||||||
*
|
|
||||||
* The maximum value returned is mt_getrandmax()
|
|
||||||
*
|
|
||||||
* @param int|null $nbDigits Defaults to a random number between 1 and 9
|
|
||||||
* @param bool $strict Whether the returned number should have exactly $nbDigits
|
|
||||||
*
|
|
||||||
* @example 79907610
|
|
||||||
*/
|
|
||||||
public function randomNumber($nbDigits = null, $strict = false): int
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\NumberExtension::class)->randomNumber(
|
|
||||||
$nbDigits !== null ? (int) $nbDigits : null,
|
|
||||||
(bool) $strict,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a version number in semantic versioning syntax 2.0.0. (https://semver.org/spec/v2.0.0.html)
|
|
||||||
*
|
|
||||||
* @param bool $preRelease Pre release parts may be randomly included
|
|
||||||
* @param bool $build Build parts may be randomly included
|
|
||||||
*
|
|
||||||
* @example 1.0.0
|
|
||||||
* @example 1.0.0-alpha.1
|
|
||||||
* @example 1.0.0-alpha.1+b71f04d
|
|
||||||
*/
|
|
||||||
public function semver(bool $preRelease = false, bool $build = false): string
|
|
||||||
{
|
|
||||||
return $this->ext(Extension\VersionExtension::class)->semver($preRelease, $build);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
protected function callFormatWithMatches($matches)
|
|
||||||
{
|
|
||||||
trigger_deprecation('fakerphp/faker', '1.14', 'Protected method "callFormatWithMatches()" is deprecated and will be removed.');
|
|
||||||
|
|
||||||
return $this->format($matches[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $attribute
|
|
||||||
*
|
|
||||||
* @deprecated Use a method instead.
|
|
||||||
*/
|
|
||||||
public function __get($attribute)
|
|
||||||
{
|
|
||||||
trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute);
|
|
||||||
|
|
||||||
return $this->format($attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $method
|
|
||||||
* @param array $attributes
|
|
||||||
*/
|
|
||||||
public function __call($method, $attributes)
|
|
||||||
{
|
|
||||||
return $this->format($method, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
$this->seed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __wakeup()
|
|
||||||
{
|
|
||||||
$this->formatters = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-180
@@ -1,180 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Guesser;
|
|
||||||
|
|
||||||
use Faker\Provider\Base;
|
|
||||||
|
|
||||||
class Name
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param int|null $size Length of field, if known
|
|
||||||
*
|
|
||||||
* @return callable|null
|
|
||||||
*/
|
|
||||||
public function guessFormat($name, $size = null)
|
|
||||||
{
|
|
||||||
$name = Base::toLower($name);
|
|
||||||
$generator = $this->generator;
|
|
||||||
|
|
||||||
if (preg_match('/^is[_A-Z]/', $name)) {
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match('/(_a|A)t$/', $name)) {
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->dateTime();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (str_replace('_', '', $name)) {
|
|
||||||
case 'firstname':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->firstName();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'lastname':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->lastName();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'username':
|
|
||||||
case 'login':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->userName();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'email':
|
|
||||||
case 'emailaddress':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->email();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'phonenumber':
|
|
||||||
case 'phone':
|
|
||||||
case 'telephone':
|
|
||||||
case 'telnumber':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->phoneNumber();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'address':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->address();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'city':
|
|
||||||
case 'town':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->city();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'streetaddress':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->streetAddress();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'postcode':
|
|
||||||
case 'zipcode':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->postcode();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'state':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->state();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'county':
|
|
||||||
if ($this->generator->locale == 'en_US') {
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return sprintf('%s County', $generator->city());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->state();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'country':
|
|
||||||
switch ($size) {
|
|
||||||
case 2:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->countryCode();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->countryISOAlpha3();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->locale();
|
|
||||||
};
|
|
||||||
|
|
||||||
default:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->country();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'locale':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->locale();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'currency':
|
|
||||||
case 'currencycode':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->currencyCode();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'url':
|
|
||||||
case 'website':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->url();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'company':
|
|
||||||
case 'companyname':
|
|
||||||
case 'employer':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->company();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'title':
|
|
||||||
if ($size !== null && $size <= 10) {
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->title();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->sentence();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'body':
|
|
||||||
case 'summary':
|
|
||||||
case 'article':
|
|
||||||
case 'description':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\CakePHP;
|
|
||||||
|
|
||||||
class ColumnTypeGuesser
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Closure|null
|
|
||||||
*/
|
|
||||||
public function guessFormat($column, $table)
|
|
||||||
{
|
|
||||||
$generator = $this->generator;
|
|
||||||
$schema = $table->schema();
|
|
||||||
|
|
||||||
switch ($schema->columnType($column)) {
|
|
||||||
case 'boolean':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'integer':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 2147483647);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'biginteger':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, PHP_INT_MAX);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'decimal':
|
|
||||||
case 'float':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->randomFloat();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'uuid':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->uuid();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'string':
|
|
||||||
if (method_exists($schema, 'getColumn')) {
|
|
||||||
$columnData = $schema->getColumn($column);
|
|
||||||
} else {
|
|
||||||
$columnData = $schema->column($column);
|
|
||||||
}
|
|
||||||
$length = $columnData['length'];
|
|
||||||
|
|
||||||
return static function () use ($generator, $length) {
|
|
||||||
return $generator->text($length);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'text':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'date':
|
|
||||||
case 'datetime':
|
|
||||||
case 'timestamp':
|
|
||||||
case 'time':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->datetime();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'binary':
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\CakePHP;
|
|
||||||
|
|
||||||
use Cake\ORM\TableRegistry;
|
|
||||||
|
|
||||||
class EntityPopulator
|
|
||||||
{
|
|
||||||
protected $class;
|
|
||||||
protected $connectionName;
|
|
||||||
protected $columnFormatters = [];
|
|
||||||
protected $modifiers = [];
|
|
||||||
|
|
||||||
public function __construct($class)
|
|
||||||
{
|
|
||||||
$this->class = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function __get($name)
|
|
||||||
{
|
|
||||||
return $this->{$name};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function __set($name, $value)
|
|
||||||
{
|
|
||||||
$this->{$name} = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeColumnFormattersWith($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeModifiersWith($modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = array_merge($this->modifiers, $modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessColumnFormatters($populator)
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$class = $this->class;
|
|
||||||
$table = $this->getTable($class);
|
|
||||||
$schema = $table->schema();
|
|
||||||
$pk = $schema->primaryKey();
|
|
||||||
$guessers = $populator->getGuessers() + ['ColumnTypeGuesser' => new ColumnTypeGuesser($populator->getGenerator())];
|
|
||||||
$isForeignKey = static function ($column) use ($table) {
|
|
||||||
foreach ($table->associations()->type('BelongsTo') as $assoc) {
|
|
||||||
if ($column == $assoc->foreignKey()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach ($schema->columns() as $column) {
|
|
||||||
if ($column == $pk[0] || $isForeignKey($column)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($guessers as $guesser) {
|
|
||||||
if ($formatter = $guesser->guessFormat($column, $table)) {
|
|
||||||
$formatters[$column] = $formatter;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessModifiers()
|
|
||||||
{
|
|
||||||
$modifiers = [];
|
|
||||||
$table = $this->getTable($this->class);
|
|
||||||
|
|
||||||
$belongsTo = $table->associations()->type('BelongsTo');
|
|
||||||
|
|
||||||
foreach ($belongsTo as $assoc) {
|
|
||||||
$modifiers['belongsTo' . $assoc->name()] = function ($data, $insertedEntities) use ($assoc) {
|
|
||||||
$table = $assoc->target();
|
|
||||||
$foreignModel = $table->alias();
|
|
||||||
|
|
||||||
$foreignKeys = [];
|
|
||||||
|
|
||||||
if (!empty($insertedEntities[$foreignModel])) {
|
|
||||||
$foreignKeys = $insertedEntities[$foreignModel];
|
|
||||||
} else {
|
|
||||||
$foreignKeys = $table->find('all')
|
|
||||||
->select(['id'])
|
|
||||||
->map(static function ($row) {
|
|
||||||
return $row->id;
|
|
||||||
})
|
|
||||||
->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($foreignKeys)) {
|
|
||||||
throw new \Exception(sprintf('%s belongsTo %s, which seems empty at this point.', $this->getTable($this->class)->table(), $assoc->table()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$foreignKey = $foreignKeys[array_rand($foreignKeys)];
|
|
||||||
$data[$assoc->foreignKey()] = $foreignKey;
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO check if TreeBehavior attached to modify lft/rgt cols
|
|
||||||
|
|
||||||
return $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $options
|
|
||||||
*/
|
|
||||||
public function execute($class, $insertedEntities, $options = [])
|
|
||||||
{
|
|
||||||
$table = $this->getTable($class);
|
|
||||||
$entity = $table->newEntity();
|
|
||||||
|
|
||||||
foreach ($this->columnFormatters as $column => $format) {
|
|
||||||
if (null !== $format) {
|
|
||||||
$entity->{$column} = is_callable($format) ? $format($insertedEntities, $table) : $format;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->modifiers as $modifier) {
|
|
||||||
$entity = $modifier($entity, $insertedEntities);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$entity = $table->save($entity, $options)) {
|
|
||||||
throw new \RuntimeException("Failed saving $class record");
|
|
||||||
}
|
|
||||||
|
|
||||||
$pk = $table->primaryKey();
|
|
||||||
|
|
||||||
if (is_string($pk)) {
|
|
||||||
return $entity->{$pk};
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entity->{$pk[0]};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setConnection($name)
|
|
||||||
{
|
|
||||||
$this->connectionName = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getTable($class)
|
|
||||||
{
|
|
||||||
$options = [];
|
|
||||||
|
|
||||||
if (!empty($this->connectionName)) {
|
|
||||||
$options['connection'] = $this->connectionName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TableRegistry::get($class, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\CakePHP;
|
|
||||||
|
|
||||||
class Populator
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
protected $entities = [];
|
|
||||||
protected $quantities = [];
|
|
||||||
protected $guessers = [];
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Faker\Generator
|
|
||||||
*/
|
|
||||||
public function getGenerator()
|
|
||||||
{
|
|
||||||
return $this->generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getGuessers()
|
|
||||||
{
|
|
||||||
return $this->guessers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function removeGuesser($name)
|
|
||||||
{
|
|
||||||
if ($this->guessers[$name]) {
|
|
||||||
unset($this->guessers[$name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function addGuesser($class)
|
|
||||||
{
|
|
||||||
if (!is_object($class)) {
|
|
||||||
$class = new $class($this->generator);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!method_exists($class, 'guessFormat')) {
|
|
||||||
throw new \Exception('Missing required custom guesser method: ' . get_class($class) . '::guessFormat()');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->guessers[get_class($class)] = $class;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $customColumnFormatters
|
|
||||||
* @param array $customModifiers
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function addEntity($entity, $number, $customColumnFormatters = [], $customModifiers = [])
|
|
||||||
{
|
|
||||||
if (!$entity instanceof EntityPopulator) {
|
|
||||||
$entity = new EntityPopulator($entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
$entity->columnFormatters = $entity->guessColumnFormatters($this);
|
|
||||||
|
|
||||||
if ($customColumnFormatters) {
|
|
||||||
$entity->mergeColumnFormattersWith($customColumnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
$entity->modifiers = $entity->guessModifiers($this);
|
|
||||||
|
|
||||||
if ($customModifiers) {
|
|
||||||
$entity->mergeModifiersWith($customModifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
$class = $entity->class;
|
|
||||||
$this->entities[$class] = $entity;
|
|
||||||
$this->quantities[$class] = $number;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $options
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function execute($options = [])
|
|
||||||
{
|
|
||||||
$insertedEntities = [];
|
|
||||||
|
|
||||||
foreach ($this->quantities as $class => $number) {
|
|
||||||
for ($i = 0; $i < $number; ++$i) {
|
|
||||||
$insertedEntities[$class][] = $this->entities[$class]->execute($class, $insertedEntities, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $insertedEntities;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Doctrine;
|
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
|
||||||
use Faker\Generator;
|
|
||||||
|
|
||||||
require_once 'backward-compatibility.php';
|
|
||||||
|
|
||||||
class ColumnTypeGuesser
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Closure|null
|
|
||||||
*/
|
|
||||||
public function guessFormat($fieldName, ClassMetadata $class)
|
|
||||||
{
|
|
||||||
$generator = $this->generator;
|
|
||||||
$type = $class->getTypeOfField($fieldName);
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case 'boolean':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'decimal':
|
|
||||||
$size = $class->fieldMappings[$fieldName]['precision'] ?? 2;
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->randomNumber($size + 2) / 100;
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'smallint':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 65535);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'integer':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 2147483647);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'bigint':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, PHP_INT_MAX);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'float':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->randomFloat();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'string':
|
|
||||||
$size = $class->fieldMappings[$fieldName]['length'] ?? 255;
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->text($size);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'text':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'datetime':
|
|
||||||
case 'date':
|
|
||||||
case 'time':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->datetime();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'datetime_immutable':
|
|
||||||
case 'date_immutable':
|
|
||||||
case 'time_immutable':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return \DateTimeImmutable::createFromMutable($generator->datetime);
|
|
||||||
};
|
|
||||||
|
|
||||||
default:
|
|
||||||
// no smart way to guess what the user expects here
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Doctrine;
|
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
|
||||||
|
|
||||||
require_once 'backward-compatibility.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a table through a Doctrine Entity class.
|
|
||||||
*/
|
|
||||||
class EntityPopulator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var ClassMetadata
|
|
||||||
*/
|
|
||||||
protected $class;
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $columnFormatters = [];
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $modifiers = [];
|
|
||||||
|
|
||||||
public function __construct(ClassMetadata $class)
|
|
||||||
{
|
|
||||||
$this->class = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getClass()
|
|
||||||
{
|
|
||||||
return $this->class->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColumnFormatters($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = $columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getColumnFormatters()
|
|
||||||
{
|
|
||||||
return $this->columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeColumnFormattersWith($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setModifiers(array $modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getModifiers()
|
|
||||||
{
|
|
||||||
return $this->modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeModifiersWith(array $modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = array_merge($this->modifiers, $modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessColumnFormatters(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$nameGuesser = new \Faker\Guesser\Name($generator);
|
|
||||||
$columnTypeGuesser = new ColumnTypeGuesser($generator);
|
|
||||||
|
|
||||||
foreach ($this->class->getFieldNames() as $fieldName) {
|
|
||||||
if ($this->class->isIdentifier($fieldName) || !$this->class->hasField($fieldName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$size = $this->class->fieldMappings[$fieldName]['length'] ?? null;
|
|
||||||
|
|
||||||
if ($formatter = $nameGuesser->guessFormat($fieldName, $size)) {
|
|
||||||
$formatters[$fieldName] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
|
|
||||||
$formatters[$fieldName] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->class->getAssociationNames() as $assocName) {
|
|
||||||
if ($this->class->isCollectionValuedAssociation($assocName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$relatedClass = $this->class->getAssociationTargetClass($assocName);
|
|
||||||
|
|
||||||
$unique = $optional = false;
|
|
||||||
|
|
||||||
if ($this->class instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
|
|
||||||
$mappings = $this->class->getAssociationMappings();
|
|
||||||
|
|
||||||
foreach ($mappings as $mapping) {
|
|
||||||
if ($mapping['targetEntity'] == $relatedClass) {
|
|
||||||
if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadata::ONE_TO_ONE) {
|
|
||||||
$unique = true;
|
|
||||||
$optional = $mapping['joinColumns'][0]['nullable'] ?? false;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($this->class instanceof \Doctrine\ODM\MongoDB\Mapping\ClassMetadata) {
|
|
||||||
$mappings = $this->class->associationMappings;
|
|
||||||
|
|
||||||
foreach ($mappings as $mapping) {
|
|
||||||
if ($mapping['targetDocument'] == $relatedClass) {
|
|
||||||
if ($mapping['type'] == \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::ONE && $mapping['association'] == \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::REFERENCE_ONE) {
|
|
||||||
$unique = true;
|
|
||||||
$optional = $mapping['nullable'] ?? false;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$index = 0;
|
|
||||||
$formatters[$assocName] = static function ($inserted) use ($relatedClass, &$index, $unique, $optional, $generator) {
|
|
||||||
if (isset($inserted[$relatedClass])) {
|
|
||||||
if ($unique) {
|
|
||||||
$related = null;
|
|
||||||
|
|
||||||
if (isset($inserted[$relatedClass][$index]) || !$optional) {
|
|
||||||
$related = $inserted[$relatedClass][$index];
|
|
||||||
}
|
|
||||||
|
|
||||||
++$index;
|
|
||||||
|
|
||||||
return $related;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $generator->randomElement($inserted[$relatedClass]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert one new record using the Entity class.
|
|
||||||
*
|
|
||||||
* @param bool $generateId
|
|
||||||
*
|
|
||||||
* @return EntityPopulator
|
|
||||||
*/
|
|
||||||
public function execute(ObjectManager $manager, $insertedEntities, $generateId = false)
|
|
||||||
{
|
|
||||||
$obj = $this->class->newInstance();
|
|
||||||
|
|
||||||
$this->fillColumns($obj, $insertedEntities);
|
|
||||||
$this->callMethods($obj, $insertedEntities);
|
|
||||||
|
|
||||||
if ($generateId) {
|
|
||||||
$idsName = $this->class->getIdentifier();
|
|
||||||
|
|
||||||
foreach ($idsName as $idName) {
|
|
||||||
$id = $this->generateId($obj, $idName, $manager);
|
|
||||||
$this->class->reflFields[$idName]->setValue($obj, $id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->persist($obj);
|
|
||||||
|
|
||||||
return $obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function fillColumns($obj, $insertedEntities): void
|
|
||||||
{
|
|
||||||
foreach ($this->columnFormatters as $field => $format) {
|
|
||||||
if (null !== $format) {
|
|
||||||
// Add some extended debugging information to any errors thrown by the formatter
|
|
||||||
try {
|
|
||||||
$value = is_callable($format) ? $format($insertedEntities, $obj) : $format;
|
|
||||||
} catch (\InvalidArgumentException $ex) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'Failed to generate a value for %s::%s: %s',
|
|
||||||
get_class($obj),
|
|
||||||
$field,
|
|
||||||
$ex->getMessage(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
// Try a standard setter if it's available, otherwise fall back on reflection
|
|
||||||
$setter = sprintf('set%s', ucfirst($field));
|
|
||||||
|
|
||||||
if (is_callable([$obj, $setter])) {
|
|
||||||
$obj->$setter($value);
|
|
||||||
} else {
|
|
||||||
$this->class->reflFields[$field]->setValue($obj, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function callMethods($obj, $insertedEntities): void
|
|
||||||
{
|
|
||||||
foreach ($this->getModifiers() as $modifier) {
|
|
||||||
$modifier($obj, $insertedEntities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
private function generateId($obj, $column, ObjectManager $manager)
|
|
||||||
{
|
|
||||||
$repository = $manager->getRepository(get_class($obj));
|
|
||||||
$result = $repository->createQueryBuilder('e')
|
|
||||||
->select(sprintf('e.%s', $column))
|
|
||||||
->getQuery()
|
|
||||||
->execute();
|
|
||||||
$ids = array_map('current', $result->toArray());
|
|
||||||
|
|
||||||
do {
|
|
||||||
$id = mt_rand();
|
|
||||||
} while (in_array($id, $ids, false));
|
|
||||||
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Doctrine;
|
|
||||||
|
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
|
||||||
use Faker\Generator;
|
|
||||||
|
|
||||||
require_once 'backward-compatibility.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a database using the Doctrine ORM or ODM.
|
|
||||||
* A Populator can populate several tables using ActiveRecord classes.
|
|
||||||
*/
|
|
||||||
class Populator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $batchSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Generator
|
|
||||||
*/
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ObjectManager|null
|
|
||||||
*/
|
|
||||||
protected $manager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $entities = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $quantities = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $generateId = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populator constructor.
|
|
||||||
*
|
|
||||||
* @param int $batchSize
|
|
||||||
*/
|
|
||||||
public function __construct(Generator $generator, ?ObjectManager $manager = null, $batchSize = 1000)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
$this->manager = $manager;
|
|
||||||
$this->batchSize = $batchSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an order for the generation of $number records for $entity.
|
|
||||||
*
|
|
||||||
* @param mixed $entity A Doctrine classname, or a \Faker\ORM\Doctrine\EntityPopulator instance
|
|
||||||
* @param int $number The number of entities to populate
|
|
||||||
*/
|
|
||||||
public function addEntity($entity, $number, $customColumnFormatters = [], $customModifiers = [], $generateId = false)
|
|
||||||
{
|
|
||||||
if (!$entity instanceof \Faker\ORM\Doctrine\EntityPopulator) {
|
|
||||||
if (null === $this->manager) {
|
|
||||||
throw new \InvalidArgumentException('No entity manager passed to Doctrine Populator.');
|
|
||||||
}
|
|
||||||
$entity = new \Faker\ORM\Doctrine\EntityPopulator($this->manager->getClassMetadata($entity));
|
|
||||||
}
|
|
||||||
$entity->setColumnFormatters($entity->guessColumnFormatters($this->generator));
|
|
||||||
|
|
||||||
if ($customColumnFormatters) {
|
|
||||||
$entity->mergeColumnFormattersWith($customColumnFormatters);
|
|
||||||
}
|
|
||||||
$entity->mergeModifiersWith($customModifiers);
|
|
||||||
$this->generateId[$entity->getClass()] = $generateId;
|
|
||||||
|
|
||||||
$class = $entity->getClass();
|
|
||||||
$this->entities[$class] = $entity;
|
|
||||||
$this->quantities[$class] = $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the database using all the Entity classes previously added.
|
|
||||||
*
|
|
||||||
* Please note that large amounts of data will result in more memory usage since the the Populator will return
|
|
||||||
* all newly created primary keys after executing.
|
|
||||||
*
|
|
||||||
* @param ObjectManager|null $entityManager A Doctrine connection object
|
|
||||||
*
|
|
||||||
* @return array A list of the inserted PKs
|
|
||||||
*/
|
|
||||||
public function execute($entityManager = null)
|
|
||||||
{
|
|
||||||
if (null === $entityManager) {
|
|
||||||
$entityManager = $this->manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $entityManager) {
|
|
||||||
throw new \InvalidArgumentException('No entity manager passed to Doctrine Populator.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$insertedEntities = [];
|
|
||||||
|
|
||||||
foreach ($this->quantities as $class => $number) {
|
|
||||||
$generateId = $this->generateId[$class];
|
|
||||||
|
|
||||||
for ($i = 0; $i < $number; ++$i) {
|
|
||||||
$insertedEntities[$class][] = $this->entities[$class]->execute(
|
|
||||||
$entityManager,
|
|
||||||
$insertedEntities,
|
|
||||||
$generateId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (count($insertedEntities) % $this->batchSize === 0) {
|
|
||||||
$entityManager->flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$entityManager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $insertedEntities;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
if (!class_exists('Doctrine\Common\Persistence\Mapping\ClassMetadata')) {
|
|
||||||
class_alias(\Doctrine\Persistence\Mapping\ClassMetadata::class, 'Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!class_exists('Doctrine\Common\Persistence\ObjectManager')) {
|
|
||||||
class_alias(\Doctrine\Persistence\ObjectManager::class, 'Doctrine\Common\Persistence\ObjectManager');
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Mandango;
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
|
|
||||||
class ColumnTypeGuesser
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Generator
|
|
||||||
*/
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Closure|null
|
|
||||||
*/
|
|
||||||
public function guessFormat($field)
|
|
||||||
{
|
|
||||||
$generator = $this->generator;
|
|
||||||
|
|
||||||
switch ($field['type']) {
|
|
||||||
case 'boolean':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'integer':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 4294967295);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'float':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->randomFloat();
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'string':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text(255);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'date':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->dateTime;
|
|
||||||
};
|
|
||||||
|
|
||||||
default:
|
|
||||||
// no smart way to guess what the user expects here
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Mandango;
|
|
||||||
|
|
||||||
use Faker\Provider\Base;
|
|
||||||
use Mandango\Mandango;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a table through a Mandango ActiveRecord class.
|
|
||||||
*/
|
|
||||||
class EntityPopulator
|
|
||||||
{
|
|
||||||
protected $class;
|
|
||||||
protected $columnFormatters = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $class A Mandango ActiveRecord classname
|
|
||||||
*/
|
|
||||||
public function __construct($class)
|
|
||||||
{
|
|
||||||
$this->class = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getClass()
|
|
||||||
{
|
|
||||||
return $this->class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColumnFormatters($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = $columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getColumnFormatters()
|
|
||||||
{
|
|
||||||
return $this->columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeColumnFormattersWith($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessColumnFormatters(\Faker\Generator $generator, Mandango $mandango)
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$nameGuesser = new \Faker\Guesser\Name($generator);
|
|
||||||
$columnTypeGuesser = new \Faker\ORM\Mandango\ColumnTypeGuesser($generator);
|
|
||||||
|
|
||||||
$metadata = $mandango->getMetadata($this->class);
|
|
||||||
|
|
||||||
// fields
|
|
||||||
foreach ($metadata['fields'] as $fieldName => $field) {
|
|
||||||
if ($formatter = $nameGuesser->guessFormat($fieldName)) {
|
|
||||||
$formatters[$fieldName] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $columnTypeGuesser->guessFormat($field)) {
|
|
||||||
$formatters[$fieldName] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// references
|
|
||||||
foreach (array_merge($metadata['referencesOne'], $metadata['referencesMany']) as $referenceName => $reference) {
|
|
||||||
if (!isset($reference['class'])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$referenceClass = $reference['class'];
|
|
||||||
|
|
||||||
$formatters[$referenceName] = static function ($insertedEntities) use ($referenceClass) {
|
|
||||||
if (isset($insertedEntities[$referenceClass])) {
|
|
||||||
return Base::randomElement($insertedEntities[$referenceClass]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert one new record using the Entity class.
|
|
||||||
*/
|
|
||||||
public function execute(Mandango $mandango, $insertedEntities)
|
|
||||||
{
|
|
||||||
$metadata = $mandango->getMetadata($this->class);
|
|
||||||
|
|
||||||
$obj = $mandango->create($this->class);
|
|
||||||
|
|
||||||
foreach ($this->columnFormatters as $column => $format) {
|
|
||||||
if (null !== $format) {
|
|
||||||
$value = is_callable($format) ? $format($insertedEntities, $obj) : $format;
|
|
||||||
|
|
||||||
if (isset($metadata['fields'][$column])
|
|
||||||
|| isset($metadata['referencesOne'][$column])) {
|
|
||||||
$obj->set($column, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($metadata['referencesMany'][$column])) {
|
|
||||||
$adder = 'add' . ucfirst($column);
|
|
||||||
$obj->$adder($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$mandango->persist($obj);
|
|
||||||
|
|
||||||
return $obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Mandango;
|
|
||||||
|
|
||||||
use Mandango\Mandango;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a database using Mandango.
|
|
||||||
* A Populator can populate several tables using ActiveRecord classes.
|
|
||||||
*/
|
|
||||||
class Populator
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
protected $mandango;
|
|
||||||
protected $entities = [];
|
|
||||||
protected $quantities = [];
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator, Mandango $mandango)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
$this->mandango = $mandango;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an order for the generation of $number records for $entity.
|
|
||||||
*
|
|
||||||
* @param mixed $entity A Propel ActiveRecord classname, or a \Faker\ORM\Propel\EntityPopulator instance
|
|
||||||
* @param int $number The number of entities to populate
|
|
||||||
*/
|
|
||||||
public function addEntity($entity, $number, $customColumnFormatters = [])
|
|
||||||
{
|
|
||||||
if (!$entity instanceof \Faker\ORM\Mandango\EntityPopulator) {
|
|
||||||
$entity = new \Faker\ORM\Mandango\EntityPopulator($entity);
|
|
||||||
}
|
|
||||||
$entity->setColumnFormatters($entity->guessColumnFormatters($this->generator, $this->mandango));
|
|
||||||
|
|
||||||
if ($customColumnFormatters) {
|
|
||||||
$entity->mergeColumnFormattersWith($customColumnFormatters);
|
|
||||||
}
|
|
||||||
$class = $entity->getClass();
|
|
||||||
$this->entities[$class] = $entity;
|
|
||||||
$this->quantities[$class] = $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the database using all the Entity classes previously added.
|
|
||||||
*
|
|
||||||
* @return array A list of the inserted entities.
|
|
||||||
*/
|
|
||||||
public function execute()
|
|
||||||
{
|
|
||||||
$insertedEntities = [];
|
|
||||||
|
|
||||||
foreach ($this->quantities as $class => $number) {
|
|
||||||
for ($i = 0; $i < $number; ++$i) {
|
|
||||||
$insertedEntities[$class][] = $this->entities[$class]->execute($this->mandango, $insertedEntities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->mandango->flush();
|
|
||||||
|
|
||||||
return $insertedEntities;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Propel;
|
|
||||||
|
|
||||||
class ColumnTypeGuesser
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Closure|null
|
|
||||||
*/
|
|
||||||
public function guessFormat(\ColumnMap $column)
|
|
||||||
{
|
|
||||||
$generator = $this->generator;
|
|
||||||
|
|
||||||
if ($column->isTemporal()) {
|
|
||||||
if ($column->isEpochTemporal()) {
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->dateTime;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->dateTimeAD;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
$type = $column->getType();
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case \PropelColumnTypes::BOOLEAN:
|
|
||||||
case \PropelColumnTypes::BOOLEAN_EMU:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::NUMERIC:
|
|
||||||
case \PropelColumnTypes::DECIMAL:
|
|
||||||
$size = $column->getSize();
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->randomNumber($size + 2) / 100;
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::TINYINT:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 127);
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::SMALLINT:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 32767);
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::INTEGER:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 2147483647);
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::BIGINT:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, PHP_INT_MAX);
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::FLOAT:
|
|
||||||
case \PropelColumnTypes::DOUBLE:
|
|
||||||
case \PropelColumnTypes::REAL:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->randomFloat();
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::CHAR:
|
|
||||||
case \PropelColumnTypes::VARCHAR:
|
|
||||||
case \PropelColumnTypes::BINARY:
|
|
||||||
case \PropelColumnTypes::VARBINARY:
|
|
||||||
$size = $column->getSize();
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->text($size);
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::LONGVARCHAR:
|
|
||||||
case \PropelColumnTypes::LONGVARBINARY:
|
|
||||||
case \PropelColumnTypes::CLOB:
|
|
||||||
case \PropelColumnTypes::CLOB_EMU:
|
|
||||||
case \PropelColumnTypes::BLOB:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text;
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::ENUM:
|
|
||||||
$valueSet = $column->getValueSet();
|
|
||||||
|
|
||||||
return static function () use ($generator, $valueSet) {
|
|
||||||
return $generator->randomElement($valueSet);
|
|
||||||
};
|
|
||||||
|
|
||||||
case \PropelColumnTypes::OBJECT:
|
|
||||||
case \PropelColumnTypes::PHP_ARRAY:
|
|
||||||
default:
|
|
||||||
// no smart way to guess what the user expects here
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,204 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Propel;
|
|
||||||
|
|
||||||
use Faker\Provider\Base;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a table through a Propel ActiveRecord class.
|
|
||||||
*/
|
|
||||||
class EntityPopulator
|
|
||||||
{
|
|
||||||
protected $class;
|
|
||||||
protected $columnFormatters = [];
|
|
||||||
protected $modifiers = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $class A Propel ActiveRecord classname
|
|
||||||
*/
|
|
||||||
public function __construct($class)
|
|
||||||
{
|
|
||||||
$this->class = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getClass()
|
|
||||||
{
|
|
||||||
return $this->class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColumnFormatters($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = $columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getColumnFormatters()
|
|
||||||
{
|
|
||||||
return $this->columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeColumnFormattersWith($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessColumnFormatters(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$class = $this->class;
|
|
||||||
$peerClass = $class::PEER;
|
|
||||||
$tableMap = $peerClass::getTableMap();
|
|
||||||
$nameGuesser = new \Faker\Guesser\Name($generator);
|
|
||||||
$columnTypeGuesser = new \Faker\ORM\Propel\ColumnTypeGuesser($generator);
|
|
||||||
|
|
||||||
foreach ($tableMap->getColumns() as $columnMap) {
|
|
||||||
// skip behavior columns, handled by modifiers
|
|
||||||
if ($this->isColumnBehavior($columnMap)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($columnMap->isForeignKey()) {
|
|
||||||
$relatedClass = $columnMap->getRelation()->getForeignTable()->getClassname();
|
|
||||||
$formatters[$columnMap->getPhpName()] = static function ($inserted) use ($relatedClass, $generator) {
|
|
||||||
return isset($inserted[$relatedClass]) ? $generator->randomElement($inserted[$relatedClass]) : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($columnMap->isPrimaryKey()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $nameGuesser->guessFormat($columnMap->getPhpName(), $columnMap->getSize())) {
|
|
||||||
$formatters[$columnMap->getPhpName()] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $columnTypeGuesser->guessFormat($columnMap)) {
|
|
||||||
$formatters[$columnMap->getPhpName()] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isColumnBehavior(\ColumnMap $columnMap)
|
|
||||||
{
|
|
||||||
foreach ($columnMap->getTable()->getBehaviors() as $name => $params) {
|
|
||||||
$columnName = Base::toLower($columnMap->getName());
|
|
||||||
|
|
||||||
switch ($name) {
|
|
||||||
case 'nested_set':
|
|
||||||
$columnNames = [$params['left_column'], $params['right_column'], $params['level_column']];
|
|
||||||
|
|
||||||
if (in_array($columnName, $columnNames, false)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'timestampable':
|
|
||||||
$columnNames = [$params['create_column'], $params['update_column']];
|
|
||||||
|
|
||||||
if (in_array($columnName, $columnNames, false)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setModifiers($modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getModifiers()
|
|
||||||
{
|
|
||||||
return $this->modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeModifiersWith($modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = array_merge($this->modifiers, $modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessModifiers(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$modifiers = [];
|
|
||||||
$class = $this->class;
|
|
||||||
$peerClass = $class::PEER;
|
|
||||||
$tableMap = $peerClass::getTableMap();
|
|
||||||
|
|
||||||
foreach ($tableMap->getBehaviors() as $name => $params) {
|
|
||||||
switch ($name) {
|
|
||||||
case 'nested_set':
|
|
||||||
$modifiers['nested_set'] = static function ($obj, $inserted) use ($class, $generator): void {
|
|
||||||
if (isset($inserted[$class])) {
|
|
||||||
$queryClass = $class . 'Query';
|
|
||||||
$parent = $queryClass::create()->findPk($generator->randomElement($inserted[$class]));
|
|
||||||
$obj->insertAsLastChildOf($parent);
|
|
||||||
} else {
|
|
||||||
$obj->makeRoot();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sortable':
|
|
||||||
$modifiers['sortable'] = static function ($obj, $inserted) use ($class, $generator): void {
|
|
||||||
$obj->insertAtRank($generator->numberBetween(1, count($inserted[$class] ?? []) + 1));
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert one new record using the Entity class.
|
|
||||||
*/
|
|
||||||
public function execute($con, $insertedEntities)
|
|
||||||
{
|
|
||||||
$obj = new $this->class();
|
|
||||||
|
|
||||||
foreach ($this->getColumnFormatters() as $column => $format) {
|
|
||||||
if (null !== $format) {
|
|
||||||
$obj->setByName($column, is_callable($format) ? $format($insertedEntities, $obj) : $format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->getModifiers() as $modifier) {
|
|
||||||
$modifier($obj, $insertedEntities);
|
|
||||||
}
|
|
||||||
$obj->save($con);
|
|
||||||
|
|
||||||
return $obj->getPrimaryKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Propel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a database using the Propel ORM.
|
|
||||||
* A Populator can populate several tables using ActiveRecord classes.
|
|
||||||
*/
|
|
||||||
class Populator
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
protected $entities = [];
|
|
||||||
protected $quantities = [];
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an order for the generation of $number records for $entity.
|
|
||||||
*
|
|
||||||
* @param mixed $entity A Propel ActiveRecord classname, or a \Faker\ORM\Propel\EntityPopulator instance
|
|
||||||
* @param int $number The number of entities to populate
|
|
||||||
*/
|
|
||||||
public function addEntity($entity, $number, $customColumnFormatters = [], $customModifiers = [])
|
|
||||||
{
|
|
||||||
if (!$entity instanceof \Faker\ORM\Propel\EntityPopulator) {
|
|
||||||
$entity = new \Faker\ORM\Propel\EntityPopulator($entity);
|
|
||||||
}
|
|
||||||
$entity->setColumnFormatters($entity->guessColumnFormatters($this->generator));
|
|
||||||
|
|
||||||
if ($customColumnFormatters) {
|
|
||||||
$entity->mergeColumnFormattersWith($customColumnFormatters);
|
|
||||||
}
|
|
||||||
$entity->setModifiers($entity->guessModifiers($this->generator));
|
|
||||||
|
|
||||||
if ($customModifiers) {
|
|
||||||
$entity->mergeModifiersWith($customModifiers);
|
|
||||||
}
|
|
||||||
$class = $entity->getClass();
|
|
||||||
$this->entities[$class] = $entity;
|
|
||||||
$this->quantities[$class] = $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the database using all the Entity classes previously added.
|
|
||||||
*
|
|
||||||
* @param PropelPDO $con A Propel connection object
|
|
||||||
*
|
|
||||||
* @return array A list of the inserted PKs
|
|
||||||
*/
|
|
||||||
public function execute($con = null)
|
|
||||||
{
|
|
||||||
if (null === $con) {
|
|
||||||
$con = $this->getConnection();
|
|
||||||
}
|
|
||||||
$isInstancePoolingEnabled = \Propel::isInstancePoolingEnabled();
|
|
||||||
\Propel::disableInstancePooling();
|
|
||||||
$insertedEntities = [];
|
|
||||||
$con->beginTransaction();
|
|
||||||
|
|
||||||
foreach ($this->quantities as $class => $number) {
|
|
||||||
for ($i = 0; $i < $number; ++$i) {
|
|
||||||
$insertedEntities[$class][] = $this->entities[$class]->execute($con, $insertedEntities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$con->commit();
|
|
||||||
|
|
||||||
if ($isInstancePoolingEnabled) {
|
|
||||||
\Propel::enableInstancePooling();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $insertedEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getConnection()
|
|
||||||
{
|
|
||||||
// use the first connection available
|
|
||||||
$class = key($this->entities);
|
|
||||||
|
|
||||||
if (!$class) {
|
|
||||||
throw new \RuntimeException('No class found from entities. Did you add entities to the Populator ?');
|
|
||||||
}
|
|
||||||
|
|
||||||
$peer = $class::PEER;
|
|
||||||
|
|
||||||
return \Propel::getConnection($peer::DATABASE_NAME, \Propel::CONNECTION_WRITE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Propel2;
|
|
||||||
|
|
||||||
use Propel\Generator\Model\PropelTypes;
|
|
||||||
use Propel\Runtime\Map\ColumnMap;
|
|
||||||
|
|
||||||
class ColumnTypeGuesser
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Closure|null
|
|
||||||
*/
|
|
||||||
public function guessFormat(ColumnMap $column)
|
|
||||||
{
|
|
||||||
$generator = $this->generator;
|
|
||||||
|
|
||||||
if ($column->isTemporal()) {
|
|
||||||
if ($column->getType() == PropelTypes::BU_DATE || $column->getType() == PropelTypes::BU_TIMESTAMP) {
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->dateTime;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->dateTimeAD;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
$type = $column->getType();
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case PropelTypes::BOOLEAN:
|
|
||||||
case PropelTypes::BOOLEAN_EMU:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::NUMERIC:
|
|
||||||
case PropelTypes::DECIMAL:
|
|
||||||
$size = $column->getSize();
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->randomNumber($size + 2) / 100;
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::TINYINT:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 127);
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::SMALLINT:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 32767);
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::INTEGER:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 2147483647);
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::BIGINT:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, PHP_INT_MAX);
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::FLOAT:
|
|
||||||
case PropelTypes::DOUBLE:
|
|
||||||
case PropelTypes::REAL:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->randomFloat();
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::CHAR:
|
|
||||||
case PropelTypes::VARCHAR:
|
|
||||||
case PropelTypes::BINARY:
|
|
||||||
case PropelTypes::VARBINARY:
|
|
||||||
$size = $column->getSize();
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->text($size);
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::LONGVARCHAR:
|
|
||||||
case PropelTypes::LONGVARBINARY:
|
|
||||||
case PropelTypes::CLOB:
|
|
||||||
case PropelTypes::CLOB_EMU:
|
|
||||||
case PropelTypes::BLOB:
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text;
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::ENUM:
|
|
||||||
$valueSet = $column->getValueSet();
|
|
||||||
|
|
||||||
return static function () use ($generator, $valueSet) {
|
|
||||||
return $generator->randomElement($valueSet);
|
|
||||||
};
|
|
||||||
|
|
||||||
case PropelTypes::OBJECT:
|
|
||||||
case PropelTypes::PHP_ARRAY:
|
|
||||||
default:
|
|
||||||
// no smart way to guess what the user expects here
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Propel2;
|
|
||||||
|
|
||||||
use Faker\Provider\Base;
|
|
||||||
use Propel\Runtime\Map\ColumnMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a table through a Propel ActiveRecord class.
|
|
||||||
*/
|
|
||||||
class EntityPopulator
|
|
||||||
{
|
|
||||||
protected $class;
|
|
||||||
protected $columnFormatters = [];
|
|
||||||
protected $modifiers = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $class A Propel ActiveRecord classname
|
|
||||||
*/
|
|
||||||
public function __construct($class)
|
|
||||||
{
|
|
||||||
$this->class = $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getClass()
|
|
||||||
{
|
|
||||||
return $this->class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColumnFormatters($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = $columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getColumnFormatters()
|
|
||||||
{
|
|
||||||
return $this->columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeColumnFormattersWith($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessColumnFormatters(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$class = $this->class;
|
|
||||||
$peerClass = $class::TABLE_MAP;
|
|
||||||
$tableMap = $peerClass::getTableMap();
|
|
||||||
$nameGuesser = new \Faker\Guesser\Name($generator);
|
|
||||||
$columnTypeGuesser = new \Faker\ORM\Propel2\ColumnTypeGuesser($generator);
|
|
||||||
|
|
||||||
foreach ($tableMap->getColumns() as $columnMap) {
|
|
||||||
// skip behavior columns, handled by modifiers
|
|
||||||
if ($this->isColumnBehavior($columnMap)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($columnMap->isForeignKey()) {
|
|
||||||
$relatedClass = $columnMap->getRelation()->getForeignTable()->getClassname();
|
|
||||||
$formatters[$columnMap->getPhpName()] = static function ($inserted) use ($relatedClass, $generator) {
|
|
||||||
$relatedClass = trim($relatedClass, '\\');
|
|
||||||
|
|
||||||
return isset($inserted[$relatedClass]) ? $generator->randomElement($inserted[$relatedClass]) : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($columnMap->isPrimaryKey()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $nameGuesser->guessFormat($columnMap->getPhpName(), $columnMap->getSize())) {
|
|
||||||
$formatters[$columnMap->getPhpName()] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $columnTypeGuesser->guessFormat($columnMap)) {
|
|
||||||
$formatters[$columnMap->getPhpName()] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isColumnBehavior(ColumnMap $columnMap)
|
|
||||||
{
|
|
||||||
foreach ($columnMap->getTable()->getBehaviors() as $name => $params) {
|
|
||||||
$columnName = Base::toLower($columnMap->getName());
|
|
||||||
|
|
||||||
switch ($name) {
|
|
||||||
case 'nested_set':
|
|
||||||
$columnNames = [$params['left_column'], $params['right_column'], $params['level_column']];
|
|
||||||
|
|
||||||
if (in_array($columnName, $columnNames, false)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'timestampable':
|
|
||||||
$columnNames = [$params['create_column'], $params['update_column']];
|
|
||||||
|
|
||||||
if (in_array($columnName, $columnNames, false)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setModifiers($modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getModifiers()
|
|
||||||
{
|
|
||||||
return $this->modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeModifiersWith($modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = array_merge($this->modifiers, $modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessModifiers(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$modifiers = [];
|
|
||||||
$class = $this->class;
|
|
||||||
$peerClass = $class::TABLE_MAP;
|
|
||||||
$tableMap = $peerClass::getTableMap();
|
|
||||||
|
|
||||||
foreach ($tableMap->getBehaviors() as $name => $params) {
|
|
||||||
switch ($name) {
|
|
||||||
case 'nested_set':
|
|
||||||
$modifiers['nested_set'] = static function ($obj, $inserted) use ($class, $generator): void {
|
|
||||||
if (isset($inserted[$class])) {
|
|
||||||
$queryClass = $class . 'Query';
|
|
||||||
$parent = $queryClass::create()->findPk($generator->randomElement($inserted[$class]));
|
|
||||||
$obj->insertAsLastChildOf($parent);
|
|
||||||
} else {
|
|
||||||
$obj->makeRoot();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sortable':
|
|
||||||
$modifiers['sortable'] = static function ($obj, $inserted) use ($class, $generator): void {
|
|
||||||
$obj->insertAtRank($generator->numberBetween(1, count($inserted[$class] ?? []) + 1));
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert one new record using the Entity class.
|
|
||||||
*/
|
|
||||||
public function execute($con, $insertedEntities)
|
|
||||||
{
|
|
||||||
$obj = new $this->class();
|
|
||||||
|
|
||||||
foreach ($this->getColumnFormatters() as $column => $format) {
|
|
||||||
if (null !== $format) {
|
|
||||||
$obj->setByName($column, is_callable($format) ? $format($insertedEntities, $obj) : $format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->getModifiers() as $modifier) {
|
|
||||||
$modifier($obj, $insertedEntities);
|
|
||||||
}
|
|
||||||
$obj->save($con);
|
|
||||||
|
|
||||||
return $obj->getPrimaryKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Propel2;
|
|
||||||
|
|
||||||
use Propel\Runtime\Propel;
|
|
||||||
use Propel\Runtime\ServiceContainer\ServiceContainerInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a database using the Propel ORM.
|
|
||||||
* A Populator can populate several tables using ActiveRecord classes.
|
|
||||||
*/
|
|
||||||
class Populator
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
protected $entities = [];
|
|
||||||
protected $quantities = [];
|
|
||||||
|
|
||||||
public function __construct(\Faker\Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an order for the generation of $number records for $entity.
|
|
||||||
*
|
|
||||||
* @param mixed $entity A Propel ActiveRecord classname, or a \Faker\ORM\Propel2\EntityPopulator instance
|
|
||||||
* @param int $number The number of entities to populate
|
|
||||||
*/
|
|
||||||
public function addEntity($entity, $number, $customColumnFormatters = [], $customModifiers = [])
|
|
||||||
{
|
|
||||||
if (!$entity instanceof \Faker\ORM\Propel2\EntityPopulator) {
|
|
||||||
$entity = new \Faker\ORM\Propel2\EntityPopulator($entity);
|
|
||||||
}
|
|
||||||
$entity->setColumnFormatters($entity->guessColumnFormatters($this->generator));
|
|
||||||
|
|
||||||
if ($customColumnFormatters) {
|
|
||||||
$entity->mergeColumnFormattersWith($customColumnFormatters);
|
|
||||||
}
|
|
||||||
$entity->setModifiers($entity->guessModifiers($this->generator));
|
|
||||||
|
|
||||||
if ($customModifiers) {
|
|
||||||
$entity->mergeModifiersWith($customModifiers);
|
|
||||||
}
|
|
||||||
$class = $entity->getClass();
|
|
||||||
$this->entities[$class] = $entity;
|
|
||||||
$this->quantities[$class] = $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the database using all the Entity classes previously added.
|
|
||||||
*
|
|
||||||
* @param PropelPDO $con A Propel connection object
|
|
||||||
*
|
|
||||||
* @return array A list of the inserted PKs
|
|
||||||
*/
|
|
||||||
public function execute($con = null)
|
|
||||||
{
|
|
||||||
if (null === $con) {
|
|
||||||
$con = $this->getConnection();
|
|
||||||
}
|
|
||||||
$isInstancePoolingEnabled = Propel::isInstancePoolingEnabled();
|
|
||||||
Propel::disableInstancePooling();
|
|
||||||
$insertedEntities = [];
|
|
||||||
$con->beginTransaction();
|
|
||||||
|
|
||||||
foreach ($this->quantities as $class => $number) {
|
|
||||||
for ($i = 0; $i < $number; ++$i) {
|
|
||||||
$insertedEntities[$class][] = $this->entities[$class]->execute($con, $insertedEntities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$con->commit();
|
|
||||||
|
|
||||||
if ($isInstancePoolingEnabled) {
|
|
||||||
Propel::enableInstancePooling();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $insertedEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getConnection()
|
|
||||||
{
|
|
||||||
// use the first connection available
|
|
||||||
$class = key($this->entities);
|
|
||||||
|
|
||||||
if (!$class) {
|
|
||||||
throw new \RuntimeException('No class found from entities. Did you add entities to the Populator ?');
|
|
||||||
}
|
|
||||||
|
|
||||||
$peer = $class::TABLE_MAP;
|
|
||||||
|
|
||||||
return Propel::getConnection($peer::DATABASE_NAME, ServiceContainerInterface::CONNECTION_WRITE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Spot;
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
|
|
||||||
class ColumnTypeGuesser
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ColumnTypeGuesser constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Closure|null
|
|
||||||
*/
|
|
||||||
public function guessFormat(array $field)
|
|
||||||
{
|
|
||||||
$generator = $this->generator;
|
|
||||||
$type = $field['type'];
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case 'boolean':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'decimal':
|
|
||||||
$size = $field['precision'] ?? 2;
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->randomNumber($size + 2) / 100;
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'smallint':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 65535);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'integer':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, 2147483647);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'bigint':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->numberBetween(0, PHP_INT_MAX);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'float':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->randomFloat(null, 0, 4294967295);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'string':
|
|
||||||
$size = $field['length'] ?? 255;
|
|
||||||
|
|
||||||
return static function () use ($generator, $size) {
|
|
||||||
return $generator->text($size);
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'text':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->text;
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'datetime':
|
|
||||||
case 'date':
|
|
||||||
case 'time':
|
|
||||||
return static function () use ($generator) {
|
|
||||||
return $generator->datetime;
|
|
||||||
};
|
|
||||||
|
|
||||||
default:
|
|
||||||
// no smart way to guess what the user expects here
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Spot;
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
use Faker\Guesser\Name;
|
|
||||||
use Spot\Locator;
|
|
||||||
use Spot\Mapper;
|
|
||||||
use Spot\Relation\BelongsTo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a table through a Spot Entity class.
|
|
||||||
*/
|
|
||||||
class EntityPopulator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* When fetching existing data - fetch only few first rows.
|
|
||||||
*/
|
|
||||||
public const RELATED_FETCH_COUNT = 10;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Mapper
|
|
||||||
*/
|
|
||||||
protected $mapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Locator
|
|
||||||
*/
|
|
||||||
protected $locator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $columnFormatters = [];
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $modifiers = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $useExistingData = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $useExistingData
|
|
||||||
*/
|
|
||||||
public function __construct(Mapper $mapper, Locator $locator, $useExistingData = false)
|
|
||||||
{
|
|
||||||
$this->mapper = $mapper;
|
|
||||||
$this->locator = $locator;
|
|
||||||
$this->useExistingData = $useExistingData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMapper()
|
|
||||||
{
|
|
||||||
return $this->mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColumnFormatters($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = $columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getColumnFormatters()
|
|
||||||
{
|
|
||||||
return $this->columnFormatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeColumnFormattersWith($columnFormatters)
|
|
||||||
{
|
|
||||||
$this->columnFormatters = array_merge($this->columnFormatters, $columnFormatters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setModifiers(array $modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = $modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getModifiers()
|
|
||||||
{
|
|
||||||
return $this->modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function mergeModifiersWith(array $modifiers)
|
|
||||||
{
|
|
||||||
$this->modifiers = array_merge($this->modifiers, $modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function guessColumnFormatters(Generator $generator)
|
|
||||||
{
|
|
||||||
$formatters = [];
|
|
||||||
$nameGuesser = new Name($generator);
|
|
||||||
$columnTypeGuesser = new ColumnTypeGuesser($generator);
|
|
||||||
$fields = $this->mapper->fields();
|
|
||||||
|
|
||||||
foreach ($fields as $fieldName => $field) {
|
|
||||||
if ($field['primary'] === true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $nameGuesser->guessFormat($fieldName)) {
|
|
||||||
$formatters[$fieldName] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($formatter = $columnTypeGuesser->guessFormat($field)) {
|
|
||||||
$formatters[$fieldName] = $formatter;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$entityName = $this->mapper->entity();
|
|
||||||
$entity = $this->mapper->build([]);
|
|
||||||
$relations = $entityName::relations($this->mapper, $entity);
|
|
||||||
|
|
||||||
foreach ($relations as $relation) {
|
|
||||||
// We don't need any other relation here.
|
|
||||||
if ($relation instanceof BelongsTo) {
|
|
||||||
$fieldName = $relation->localKey();
|
|
||||||
$entityName = $relation->entityName();
|
|
||||||
$field = $fields[$fieldName];
|
|
||||||
$required = $field['required'];
|
|
||||||
|
|
||||||
$locator = $this->locator;
|
|
||||||
|
|
||||||
$formatters[$fieldName] = function ($inserted) use ($required, $entityName, $locator, $generator) {
|
|
||||||
if (!empty($inserted[$entityName])) {
|
|
||||||
return $generator->randomElement($inserted[$entityName])->get('id');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($required && $this->useExistingData) {
|
|
||||||
// We did not add anything like this, but it's required,
|
|
||||||
// So let's find something existing in DB.
|
|
||||||
$mapper = $locator->mapper($entityName);
|
|
||||||
$records = $mapper->all()->limit(self::RELATED_FETCH_COUNT)->toArray();
|
|
||||||
|
|
||||||
if (empty($records)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $generator->randomElement($records)['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $formatters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert one new record using the Entity class.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function execute($insertedEntities)
|
|
||||||
{
|
|
||||||
$obj = $this->mapper->build([]);
|
|
||||||
|
|
||||||
$this->fillColumns($obj, $insertedEntities);
|
|
||||||
$this->callMethods($obj, $insertedEntities);
|
|
||||||
|
|
||||||
$this->mapper->insert($obj);
|
|
||||||
|
|
||||||
return $obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function fillColumns($obj, $insertedEntities): void
|
|
||||||
{
|
|
||||||
foreach ($this->columnFormatters as $field => $format) {
|
|
||||||
if (null !== $format) {
|
|
||||||
$value = is_callable($format) ? $format($insertedEntities, $obj) : $format;
|
|
||||||
$obj->set($field, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function callMethods($obj, $insertedEntities): void
|
|
||||||
{
|
|
||||||
foreach ($this->getModifiers() as $modifier) {
|
|
||||||
$modifier($obj, $insertedEntities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\ORM\Spot;
|
|
||||||
|
|
||||||
use Spot\Locator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service class for populating a database using the Spot ORM.
|
|
||||||
*/
|
|
||||||
class Populator
|
|
||||||
{
|
|
||||||
protected $generator;
|
|
||||||
protected $locator;
|
|
||||||
protected $entities = [];
|
|
||||||
protected $quantities = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populator constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(\Faker\Generator $generator, ?Locator $locator = null)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
$this->locator = $locator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an order for the generation of $number records for $entity.
|
|
||||||
*
|
|
||||||
* @param string $entityName Name of Entity object to generate
|
|
||||||
* @param int $number The number of entities to populate
|
|
||||||
* @param array $customColumnFormatters
|
|
||||||
* @param array $customModifiers
|
|
||||||
* @param bool $useExistingData Should we use existing rows (e.g. roles) to populate relations?
|
|
||||||
*/
|
|
||||||
public function addEntity(
|
|
||||||
$entityName,
|
|
||||||
$number,
|
|
||||||
$customColumnFormatters = [],
|
|
||||||
$customModifiers = [],
|
|
||||||
$useExistingData = false
|
|
||||||
) {
|
|
||||||
$mapper = $this->locator->mapper($entityName);
|
|
||||||
|
|
||||||
if (null === $mapper) {
|
|
||||||
throw new \InvalidArgumentException('No mapper can be found for entity ' . $entityName);
|
|
||||||
}
|
|
||||||
$entity = new EntityPopulator($mapper, $this->locator, $useExistingData);
|
|
||||||
|
|
||||||
$entity->setColumnFormatters($entity->guessColumnFormatters($this->generator));
|
|
||||||
|
|
||||||
if ($customColumnFormatters) {
|
|
||||||
$entity->mergeColumnFormattersWith($customColumnFormatters);
|
|
||||||
}
|
|
||||||
$entity->mergeModifiersWith($customModifiers);
|
|
||||||
|
|
||||||
$this->entities[$entityName] = $entity;
|
|
||||||
$this->quantities[$entityName] = $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the database using all the Entity classes previously added.
|
|
||||||
*
|
|
||||||
* @param Locator $locator A Spot locator
|
|
||||||
*
|
|
||||||
* @return array A list of the inserted PKs
|
|
||||||
*/
|
|
||||||
public function execute($locator = null)
|
|
||||||
{
|
|
||||||
if (null === $locator) {
|
|
||||||
$locator = $this->locator;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $locator) {
|
|
||||||
throw new \InvalidArgumentException('No entity manager passed to Spot Populator.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$insertedEntities = [];
|
|
||||||
|
|
||||||
foreach ($this->quantities as $entityName => $number) {
|
|
||||||
for ($i = 0; $i < $number; ++$i) {
|
|
||||||
$insertedEntities[$entityName][] = $this->entities[$entityName]->execute(
|
|
||||||
$insertedEntities,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $insertedEntities;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Address extends Base
|
|
||||||
{
|
|
||||||
protected static $citySuffix = ['Ville'];
|
|
||||||
protected static $streetSuffix = ['Street'];
|
|
||||||
protected static $cityFormats = [
|
|
||||||
'{{firstName}}{{citySuffix}}',
|
|
||||||
];
|
|
||||||
protected static $streetNameFormats = [
|
|
||||||
'{{lastName}} {{streetSuffix}}',
|
|
||||||
];
|
|
||||||
protected static $streetAddressFormats = [
|
|
||||||
'{{buildingNumber}} {{streetName}}',
|
|
||||||
];
|
|
||||||
protected static $addressFormats = [
|
|
||||||
'{{streetAddress}} {{postcode}} {{city}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $buildingNumber = ['%#'];
|
|
||||||
protected static $postcode = ['#####'];
|
|
||||||
protected static $country = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'town'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function citySuffix()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$citySuffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Avenue'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function streetSuffix()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$streetSuffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '791'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function buildingNumber()
|
|
||||||
{
|
|
||||||
return static::numerify(static::randomElement(static::$buildingNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Sashabury'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function city()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$cityFormats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Crist Parks'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function streetName()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$streetNameFormats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '791 Crist Parks'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function streetAddress()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$streetAddressFormats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 86039-9874
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function postcode()
|
|
||||||
{
|
|
||||||
return static::toUpper(static::bothify(static::randomElement(static::$postcode)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '791 Crist Parks, Sashabury, IL 86039-9874'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function address()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$addressFormats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Japan'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function country()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$country);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses signed degrees format (returns a float number between -90 and 90)
|
|
||||||
*
|
|
||||||
* @example '77.147489'
|
|
||||||
*
|
|
||||||
* @param float|int $min
|
|
||||||
* @param float|int $max
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public static function latitude($min = -90, $max = 90)
|
|
||||||
{
|
|
||||||
return static::randomFloat(6, $min, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses signed degrees format (returns a float number between -180 and 180)
|
|
||||||
*
|
|
||||||
* @example '86.211205'
|
|
||||||
*
|
|
||||||
* @param float|int $min
|
|
||||||
* @param float|int $max
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public static function longitude($min = -180, $max = 180)
|
|
||||||
{
|
|
||||||
return static::randomFloat(6, $min, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example array('77.147489', '86.211205')
|
|
||||||
*
|
|
||||||
* @return float[]
|
|
||||||
*/
|
|
||||||
public static function localCoordinates()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'latitude' => static::latitude(),
|
|
||||||
'longitude' => static::longitude(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
use Faker\Calculator\Ean;
|
|
||||||
use Faker\Calculator\Isbn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see http://en.wikipedia.org/wiki/EAN-13
|
|
||||||
* @see http://en.wikipedia.org/wiki/ISBN
|
|
||||||
*/
|
|
||||||
class Barcode extends Base
|
|
||||||
{
|
|
||||||
private function ean($length = 13)
|
|
||||||
{
|
|
||||||
$code = static::numerify(str_repeat('#', $length - 1));
|
|
||||||
|
|
||||||
return $code . Ean::checksum($code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility function for computing EAN checksums
|
|
||||||
*
|
|
||||||
* @deprecated Use \Faker\Calculator\Ean::checksum() instead
|
|
||||||
*
|
|
||||||
* @param string $input
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
protected static function eanChecksum($input)
|
|
||||||
{
|
|
||||||
return Ean::checksum($input);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ISBN-10 check digit
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits
|
|
||||||
* @deprecated Use \Faker\Calculator\Isbn::checksum() instead
|
|
||||||
*
|
|
||||||
* @param string $input ISBN without check-digit
|
|
||||||
*
|
|
||||||
* @throws \LengthException When wrong input length passed
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected static function isbnChecksum($input)
|
|
||||||
{
|
|
||||||
return Isbn::checksum($input);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random EAN13 barcode.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '4006381333931'
|
|
||||||
*/
|
|
||||||
public function ean13()
|
|
||||||
{
|
|
||||||
return $this->ean(13);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random EAN8 barcode.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '73513537'
|
|
||||||
*/
|
|
||||||
public function ean8()
|
|
||||||
{
|
|
||||||
return $this->ean(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random ISBN-10 code
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '4881416324'
|
|
||||||
*/
|
|
||||||
public function isbn10()
|
|
||||||
{
|
|
||||||
$code = static::numerify(str_repeat('#', 9));
|
|
||||||
|
|
||||||
return $code . Isbn::checksum($code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random ISBN-13 code
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '9790404436093'
|
|
||||||
*/
|
|
||||||
public function isbn13()
|
|
||||||
{
|
|
||||||
$code = '97' . self::numberBetween(8, 9) . static::numerify(str_repeat('#', 9));
|
|
||||||
|
|
||||||
return $code . Ean::checksum($code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-710
@@ -1,710 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
use Faker\DefaultGenerator;
|
|
||||||
use Faker\Generator;
|
|
||||||
use Faker\UniqueGenerator;
|
|
||||||
use Faker\ValidGenerator;
|
|
||||||
|
|
||||||
class Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Faker\Generator
|
|
||||||
*/
|
|
||||||
protected $generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Faker\UniqueGenerator
|
|
||||||
*/
|
|
||||||
protected $unique;
|
|
||||||
|
|
||||||
public function __construct(Generator $generator)
|
|
||||||
{
|
|
||||||
$this->generator = $generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between 0 and 9
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function randomDigit()
|
|
||||||
{
|
|
||||||
return mt_rand(0, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between 1 and 9
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function randomDigitNotNull()
|
|
||||||
{
|
|
||||||
return mt_rand(1, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a random digit, which cannot be $except
|
|
||||||
*
|
|
||||||
* @param int $except
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function randomDigitNot($except)
|
|
||||||
{
|
|
||||||
$result = self::numberBetween(0, 8);
|
|
||||||
|
|
||||||
if ($result >= $except) {
|
|
||||||
++$result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random integer with 0 to $nbDigits digits.
|
|
||||||
*
|
|
||||||
* The maximum value returned is mt_getrandmax()
|
|
||||||
*
|
|
||||||
* @param int $nbDigits Defaults to a random number between 1 and 9
|
|
||||||
* @param bool $strict Whether the returned number should have exactly $nbDigits
|
|
||||||
*
|
|
||||||
* @example 79907610
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function randomNumber($nbDigits = null, $strict = false)
|
|
||||||
{
|
|
||||||
if (!is_bool($strict)) {
|
|
||||||
throw new \InvalidArgumentException('randomNumber() generates numbers of fixed width. To generate numbers between two boundaries, use numberBetween() instead.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $nbDigits) {
|
|
||||||
$nbDigits = static::randomDigitNotNull();
|
|
||||||
}
|
|
||||||
$max = 10 ** $nbDigits - 1;
|
|
||||||
|
|
||||||
if ($max > mt_getrandmax()) {
|
|
||||||
throw new \InvalidArgumentException('randomNumber() can only generate numbers up to mt_getrandmax()');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($strict) {
|
|
||||||
return mt_rand(10 ** ($nbDigits - 1), $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mt_rand(0, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random float number
|
|
||||||
*
|
|
||||||
* @param int $nbMaxDecimals
|
|
||||||
* @param float|int $min
|
|
||||||
* @param float|int $max
|
|
||||||
*
|
|
||||||
* @example 48.8932
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public static function randomFloat($nbMaxDecimals = null, $min = 0, $max = null)
|
|
||||||
{
|
|
||||||
if (null === $nbMaxDecimals) {
|
|
||||||
$nbMaxDecimals = static::randomDigit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $max) {
|
|
||||||
$max = static::randomNumber();
|
|
||||||
|
|
||||||
if ($min > $max) {
|
|
||||||
$max = $min;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($min > $max) {
|
|
||||||
$tmp = $min;
|
|
||||||
$min = $max;
|
|
||||||
$max = $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random number between $int1 and $int2 (any order)
|
|
||||||
*
|
|
||||||
* @param int $int1 default to 0
|
|
||||||
* @param int $int2 defaults to 32 bit max integer, ie 2147483647
|
|
||||||
*
|
|
||||||
* @example 79907610
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function numberBetween($int1 = 0, $int2 = 2147483647)
|
|
||||||
{
|
|
||||||
$min = $int1 < $int2 ? $int1 : $int2;
|
|
||||||
$max = $int1 < $int2 ? $int2 : $int1;
|
|
||||||
|
|
||||||
return mt_rand($min, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the passed value
|
|
||||||
*/
|
|
||||||
public static function passthrough($value)
|
|
||||||
{
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random letter from a to z
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function randomLetter()
|
|
||||||
{
|
|
||||||
return chr(mt_rand(97, 122));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random ASCII character (excluding accents and special chars)
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function randomAscii()
|
|
||||||
{
|
|
||||||
return chr(mt_rand(33, 126));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns randomly ordered subsequence of $count elements from a provided array
|
|
||||||
*
|
|
||||||
* @todo update default $count to `null` (BC) for next major version
|
|
||||||
*
|
|
||||||
* @param array|class-string|\Traversable $array Array to take elements from. Defaults to a-c
|
|
||||||
* @param int|null $count Number of elements to take. If `null` then returns random number of elements
|
|
||||||
* @param bool $allowDuplicates Allow elements to be picked several times. Defaults to false
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @throws \LengthException When requesting more elements than provided
|
|
||||||
*
|
|
||||||
* @return array New array with $count elements from $array
|
|
||||||
*/
|
|
||||||
public static function randomElements($array = ['a', 'b', 'c'], $count = 1, $allowDuplicates = false)
|
|
||||||
{
|
|
||||||
$elements = $array;
|
|
||||||
|
|
||||||
if (is_string($array) && function_exists('enum_exists') && enum_exists($array)) {
|
|
||||||
$elements = $array::cases();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($array instanceof \Traversable) {
|
|
||||||
$elements = \iterator_to_array($array, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_array($elements)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'Argument for parameter $array needs to be array, an instance of %s, or an instance of %s, got %s instead.',
|
|
||||||
\UnitEnum::class,
|
|
||||||
\Traversable::class,
|
|
||||||
is_object($array) ? get_class($array) : gettype($array),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$numberOfElements = count($elements);
|
|
||||||
|
|
||||||
if (!$allowDuplicates && null !== $count && $numberOfElements < $count) {
|
|
||||||
throw new \LengthException(sprintf(
|
|
||||||
'Cannot get %d elements, only %d in array',
|
|
||||||
$count,
|
|
||||||
$numberOfElements,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $count) {
|
|
||||||
$count = mt_rand(1, $numberOfElements);
|
|
||||||
}
|
|
||||||
|
|
||||||
$randomElements = [];
|
|
||||||
|
|
||||||
$keys = array_keys($elements);
|
|
||||||
$maxIndex = $numberOfElements - 1;
|
|
||||||
$elementHasBeenSelectedAlready = [];
|
|
||||||
$numberOfRandomElements = 0;
|
|
||||||
|
|
||||||
while ($numberOfRandomElements < $count) {
|
|
||||||
$index = mt_rand(0, $maxIndex);
|
|
||||||
|
|
||||||
if (!$allowDuplicates) {
|
|
||||||
if (isset($elementHasBeenSelectedAlready[$index])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$elementHasBeenSelectedAlready[$index] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$key = $keys[$index];
|
|
||||||
|
|
||||||
$randomElements[] = $elements[$key];
|
|
||||||
|
|
||||||
++$numberOfRandomElements;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $randomElements;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random element from a passed array
|
|
||||||
*
|
|
||||||
* @param array|class-string|\Traversable $array
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public static function randomElement($array = ['a', 'b', 'c'])
|
|
||||||
{
|
|
||||||
$elements = $array;
|
|
||||||
|
|
||||||
if (is_string($array) && function_exists('enum_exists') && enum_exists($array)) {
|
|
||||||
$elements = $array::cases();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($array instanceof \Traversable) {
|
|
||||||
$elements = iterator_to_array($array, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($elements === []) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_array($elements)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'Argument for parameter $array needs to be array, an instance of %s, or an instance of %s, got %s instead.',
|
|
||||||
\UnitEnum::class,
|
|
||||||
\Traversable::class,
|
|
||||||
is_object($array) ? get_class($array) : gettype($array),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$randomElements = static::randomElements($elements, 1);
|
|
||||||
|
|
||||||
return $randomElements[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random key from a passed associative array
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
*
|
|
||||||
* @return int|string|null
|
|
||||||
*/
|
|
||||||
public static function randomKey($array = [])
|
|
||||||
{
|
|
||||||
if (!$array) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$keys = array_keys($array);
|
|
||||||
|
|
||||||
return $keys[mt_rand(0, count($keys) - 1)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a shuffled version of the argument.
|
|
||||||
*
|
|
||||||
* This function accepts either an array, or a string.
|
|
||||||
*
|
|
||||||
* @example $faker->shuffle([1, 2, 3]); // [2, 1, 3]
|
|
||||||
* @example $faker->shuffle('hello, world'); // 'rlo,h eold!lw'
|
|
||||||
*
|
|
||||||
* @see shuffleArray()
|
|
||||||
* @see shuffleString()
|
|
||||||
*
|
|
||||||
* @param array|string $arg The set to shuffle
|
|
||||||
*
|
|
||||||
* @return array|string The shuffled set
|
|
||||||
*/
|
|
||||||
public static function shuffle($arg = '')
|
|
||||||
{
|
|
||||||
if (is_array($arg)) {
|
|
||||||
return static::shuffleArray($arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_string($arg)) {
|
|
||||||
return static::shuffleString($arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \InvalidArgumentException('shuffle() only supports strings or arrays');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a shuffled version of the array.
|
|
||||||
*
|
|
||||||
* This function does not mutate the original array. It uses the
|
|
||||||
* Fisher–Yates algorithm, which is unbiased, together with a Mersenne
|
|
||||||
* twister random generator. This function is therefore more random than
|
|
||||||
* PHP's shuffle() function, and it is seedable.
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
||||||
*
|
|
||||||
* @example $faker->shuffleArray([1, 2, 3]); // [2, 1, 3]
|
|
||||||
*
|
|
||||||
* @param array $array The set to shuffle
|
|
||||||
*
|
|
||||||
* @return array The shuffled set
|
|
||||||
*/
|
|
||||||
public static function shuffleArray($array = [])
|
|
||||||
{
|
|
||||||
$shuffledArray = [];
|
|
||||||
$i = 0;
|
|
||||||
reset($array);
|
|
||||||
|
|
||||||
foreach ($array as $key => $value) {
|
|
||||||
if ($i == 0) {
|
|
||||||
$j = 0;
|
|
||||||
} else {
|
|
||||||
$j = mt_rand(0, $i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($j == $i) {
|
|
||||||
$shuffledArray[] = $value;
|
|
||||||
} else {
|
|
||||||
$shuffledArray[] = $shuffledArray[$j];
|
|
||||||
$shuffledArray[$j] = $value;
|
|
||||||
}
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $shuffledArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a shuffled version of the string.
|
|
||||||
*
|
|
||||||
* This function does not mutate the original string. It uses the
|
|
||||||
* Fisher–Yates algorithm, which is unbiased, together with a Mersenne
|
|
||||||
* twister random generator. This function is therefore more random than
|
|
||||||
* PHP's shuffle() function, and it is seedable. Additionally, it is
|
|
||||||
* UTF8 safe if the mb extension is available.
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
||||||
*
|
|
||||||
* @example $faker->shuffleString('hello, world'); // 'rlo,h eold!lw'
|
|
||||||
*
|
|
||||||
* @param string $string The set to shuffle
|
|
||||||
* @param string $encoding The string encoding (defaults to UTF-8)
|
|
||||||
*
|
|
||||||
* @return string The shuffled set
|
|
||||||
*/
|
|
||||||
public static function shuffleString($string = '', $encoding = 'UTF-8')
|
|
||||||
{
|
|
||||||
if (function_exists('mb_strlen')) {
|
|
||||||
// UTF8-safe str_split()
|
|
||||||
$array = [];
|
|
||||||
$strlen = mb_strlen($string, $encoding);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $strlen; ++$i) {
|
|
||||||
$array[] = mb_substr($string, $i, 1, $encoding);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$array = str_split($string, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode('', static::shuffleArray($array));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function replaceWildcard($string, $wildcard, $callback)
|
|
||||||
{
|
|
||||||
if (($pos = strpos($string, $wildcard)) === false) {
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = $pos, $last = strrpos($string, $wildcard, $pos) + 1; $i < $last; ++$i) {
|
|
||||||
if ($string[$i] === $wildcard) {
|
|
||||||
$string[$i] = call_user_func($callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all hash sign ('#') occurrences with a random number
|
|
||||||
* Replaces all percentage sign ('%') occurrences with a not null number
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function numerify($string = '###')
|
|
||||||
{
|
|
||||||
// instead of using randomDigit() several times, which is slow,
|
|
||||||
// count the number of hashes and generate once a large number
|
|
||||||
$toReplace = [];
|
|
||||||
|
|
||||||
if (($pos = strpos($string, '#')) !== false) {
|
|
||||||
for ($i = $pos, $last = strrpos($string, '#', $pos) + 1; $i < $last; ++$i) {
|
|
||||||
if ($string[$i] === '#') {
|
|
||||||
$toReplace[] = $i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($nbReplacements = count($toReplace)) {
|
|
||||||
$maxAtOnce = strlen((string) mt_getrandmax()) - 1;
|
|
||||||
$numbers = '';
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
while ($i < $nbReplacements) {
|
|
||||||
$size = min($nbReplacements - $i, $maxAtOnce);
|
|
||||||
$numbers .= str_pad(static::randomNumber($size), $size, '0', STR_PAD_LEFT);
|
|
||||||
$i += $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 0; $i < $nbReplacements; ++$i) {
|
|
||||||
$string[$toReplace[$i]] = $numbers[$i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$string = self::replaceWildcard($string, '%', [static::class, 'randomDigitNotNull']);
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all question mark ('?') occurrences with a random letter
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function lexify($string = '????')
|
|
||||||
{
|
|
||||||
return self::replaceWildcard($string, '?', [static::class, 'randomLetter']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces hash signs ('#') and question marks ('?') with random numbers and letters
|
|
||||||
* An asterisk ('*') is replaced with either a random number or a random letter
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to be parsed
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function bothify($string = '## ??')
|
|
||||||
{
|
|
||||||
$string = self::replaceWildcard($string, '*', static function () {
|
|
||||||
return mt_rand(0, 1) === 1 ? '#' : '?';
|
|
||||||
});
|
|
||||||
|
|
||||||
return static::lexify(static::numerify($string));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces * signs with random numbers and letters and special characters
|
|
||||||
*
|
|
||||||
* @example $faker->asciify(''********'); // "s5'G!uC3"
|
|
||||||
*
|
|
||||||
* @param string $string String that needs to bet parsed
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function asciify($string = '****')
|
|
||||||
{
|
|
||||||
return preg_replace_callback('/\*/u', [static::class, 'randomAscii'], $string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms a basic regular expression into a random string satisfying the expression.
|
|
||||||
*
|
|
||||||
* @example $faker->regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej
|
|
||||||
*
|
|
||||||
* Regex delimiters '/.../' and begin/end markers '^...$' are ignored.
|
|
||||||
*
|
|
||||||
* Only supports a small subset of the regex syntax. For instance,
|
|
||||||
* unicode, negated classes, unbounded ranges, subpatterns, back references,
|
|
||||||
* assertions, recursive patterns, and comments are not supported. Escaping
|
|
||||||
* support is extremely fragile.
|
|
||||||
*
|
|
||||||
* This method is also VERY slow. Use it only when no other formatter
|
|
||||||
* can generate the fake data you want. For instance, prefer calling
|
|
||||||
* `$faker->email` rather than `regexify` with the previous regular
|
|
||||||
* expression.
|
|
||||||
*
|
|
||||||
* Also note than `bothify` can probably do most of what this method does,
|
|
||||||
* but much faster. For instance, for a dummy email generation, try
|
|
||||||
* `$faker->bothify('?????????@???.???')`.
|
|
||||||
*
|
|
||||||
* @see https://github.com/icomefromthenet/ReverseRegex for a more robust implementation
|
|
||||||
*
|
|
||||||
* @param string $regex A regular expression (delimiters are optional)
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function regexify($regex = '')
|
|
||||||
{
|
|
||||||
// ditch the anchors
|
|
||||||
$regex = preg_replace('/^\/?\^?/', '', $regex);
|
|
||||||
$regex = preg_replace('/\$?\/?$/', '', $regex);
|
|
||||||
// All {2} become {2,2}
|
|
||||||
$regex = preg_replace('/\{(\d+)\}/', '{\1,\1}', $regex);
|
|
||||||
// Single-letter quantifiers (?, *, +) become bracket quantifiers ({0,1}, {0,rand}, {1, rand})
|
|
||||||
$regex = preg_replace('/(?<!\\\)\?/', '{0,1}', $regex);
|
|
||||||
$regex = preg_replace('/(?<!\\\)\*/', '{0,' . static::randomDigitNotNull() . '}', $regex);
|
|
||||||
$regex = preg_replace('/(?<!\\\)\+/', '{1,' . static::randomDigitNotNull() . '}', $regex);
|
|
||||||
// [12]{1,2} becomes [12] or [12][12]
|
|
||||||
$regex = preg_replace_callback('/(\[[^\]]+\])\{(\d+),(\d+)\}/', static function ($matches) {
|
|
||||||
return str_repeat($matches[1], Base::randomElement(range($matches[2], $matches[3])));
|
|
||||||
}, $regex);
|
|
||||||
// (12|34){1,2} becomes (12|34) or (12|34)(12|34)
|
|
||||||
$regex = preg_replace_callback('/(\([^\)]+\))\{(\d+),(\d+)\}/', static function ($matches) {
|
|
||||||
return str_repeat($matches[1], Base::randomElement(range($matches[2], $matches[3])));
|
|
||||||
}, $regex);
|
|
||||||
// A{1,2} becomes A or AA or \d{3} becomes \d\d\d
|
|
||||||
$regex = preg_replace_callback('/(\\\?.)\{(\d+),(\d+)\}/', static function ($matches) {
|
|
||||||
return str_repeat($matches[1], Base::randomElement(range($matches[2], $matches[3])));
|
|
||||||
}, $regex);
|
|
||||||
// (this|that) becomes 'this' or 'that'
|
|
||||||
$regex = preg_replace_callback('/\((.*?)\)/', static function ($matches) {
|
|
||||||
return Base::randomElement(explode('|', str_replace(['(', ')'], '', $matches[1])));
|
|
||||||
}, $regex);
|
|
||||||
// All A-F inside of [] become ABCDEF
|
|
||||||
$regex = preg_replace_callback('/\[([^\]]+)\]/', static function ($matches) {
|
|
||||||
return '[' . preg_replace_callback('/(\w|\d)\-(\w|\d)/', static function ($range) {
|
|
||||||
return implode('', range($range[1], $range[2]));
|
|
||||||
}, $matches[1]) . ']';
|
|
||||||
}, $regex);
|
|
||||||
// All [ABC] become B (or A or C)
|
|
||||||
$regex = preg_replace_callback('/\[([^\]]+)\]/', static function ($matches) {
|
|
||||||
// remove backslashes (that are not followed by another backslash) because they are escape characters
|
|
||||||
$match = preg_replace('/\\\(?!\\\)/', '', $matches[1]);
|
|
||||||
$randomElement = Base::randomElement(str_split($match));
|
|
||||||
|
|
||||||
//[.] should not be a random character, but a literal .
|
|
||||||
return str_replace('.', '\.', $randomElement);
|
|
||||||
}, $regex);
|
|
||||||
// replace \d with number and \w with letter and . with ascii
|
|
||||||
$regex = preg_replace_callback('/\\\w/', [static::class, 'randomLetter'], $regex);
|
|
||||||
$regex = preg_replace_callback('/\\\d/', [static::class, 'randomDigit'], $regex);
|
|
||||||
//replace . with ascii except backslash
|
|
||||||
$regex = preg_replace_callback('/(?<!\\\)\./', static function () {
|
|
||||||
$chr = static::asciify('*');
|
|
||||||
|
|
||||||
if ($chr === '\\') {
|
|
||||||
$chr .= '\\';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $chr;
|
|
||||||
}, $regex);
|
|
||||||
// remove remaining single backslashes
|
|
||||||
$regex = str_replace('\\\\', '[:escaped_backslash:]', $regex);
|
|
||||||
$regex = str_replace('\\', '', $regex);
|
|
||||||
$regex = str_replace('[:escaped_backslash:]', '\\', $regex);
|
|
||||||
|
|
||||||
// phew
|
|
||||||
return $regex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts string to lowercase.
|
|
||||||
* Uses mb_string extension if available.
|
|
||||||
*
|
|
||||||
* @param string $string String that should be converted to lowercase
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function toLower($string = '')
|
|
||||||
{
|
|
||||||
return extension_loaded('mbstring') ? mb_strtolower($string, 'UTF-8') : strtolower($string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts string to uppercase.
|
|
||||||
* Uses mb_string extension if available.
|
|
||||||
*
|
|
||||||
* @param string $string String that should be converted to uppercase
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function toUpper($string = '')
|
|
||||||
{
|
|
||||||
return extension_loaded('mbstring') ? mb_strtoupper($string, 'UTF-8') : strtoupper($string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chainable method for making any formatter optional.
|
|
||||||
*
|
|
||||||
* @param float|int $weight Set the probability of receiving a null value.
|
|
||||||
* "0" will always return null, "1" will always return the generator.
|
|
||||||
* If $weight is an integer value, then the same system works
|
|
||||||
* between 0 (always get false) and 100 (always get true).
|
|
||||||
*
|
|
||||||
* @return mixed|null
|
|
||||||
*/
|
|
||||||
public function optional($weight = 0.5, $default = null)
|
|
||||||
{
|
|
||||||
// old system based on 0.1 <= $weight <= 0.9
|
|
||||||
// TODO: remove in v2
|
|
||||||
if ($weight > 0 && $weight < 1 && mt_rand() / mt_getrandmax() <= $weight) {
|
|
||||||
return $this->generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
// new system with percentage
|
|
||||||
if (is_int($weight) && mt_rand(1, 100) <= $weight) {
|
|
||||||
return $this->generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DefaultGenerator($default);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chainable method for making any formatter unique.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* // will never return twice the same value
|
|
||||||
* $faker->unique()->randomElement(array(1, 2, 3));
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param bool $reset If set to true, resets the list of existing values
|
|
||||||
* @param int $maxRetries Maximum number of retries to find a unique value,
|
|
||||||
* After which an OverflowException is thrown.
|
|
||||||
*
|
|
||||||
* @throws \OverflowException When no unique value can be found by iterating $maxRetries times
|
|
||||||
*
|
|
||||||
* @return UniqueGenerator A proxy class returning only non-existing values
|
|
||||||
*/
|
|
||||||
public function unique($reset = false, $maxRetries = 10000)
|
|
||||||
{
|
|
||||||
if ($reset || !$this->unique) {
|
|
||||||
$this->unique = new UniqueGenerator($this->generator, $maxRetries);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->unique;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chainable method for forcing any formatter to return only valid values.
|
|
||||||
*
|
|
||||||
* The value validity is determined by a function passed as first argument.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* $values = array();
|
|
||||||
* $evenValidator = function ($digit) {
|
|
||||||
* return $digit % 2 === 0;
|
|
||||||
* };
|
|
||||||
* for ($i=0; $i < 10; $i++) {
|
|
||||||
* $values []= $faker->valid($evenValidator)->randomDigit;
|
|
||||||
* }
|
|
||||||
* print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param Closure $validator A function returning true for valid values
|
|
||||||
* @param int $maxRetries Maximum number of retries to find a unique value,
|
|
||||||
* After which an OverflowException is thrown.
|
|
||||||
*
|
|
||||||
* @throws \OverflowException When no valid value can be found by iterating $maxRetries times
|
|
||||||
*
|
|
||||||
* @return ValidGenerator A proxy class returning only valid values
|
|
||||||
*/
|
|
||||||
public function valid($validator = null, $maxRetries = 10000)
|
|
||||||
{
|
|
||||||
return new ValidGenerator($this->generator, $validator, $maxRetries);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Biased extends Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns a biased integer between $min and $max (both inclusive).
|
|
||||||
* The distribution depends on $function.
|
|
||||||
*
|
|
||||||
* The algorithm creates two doubles, x ∈ [0, 1], y ∈ [0, 1) and checks whether the
|
|
||||||
* return value of $function for x is greater than or equal to y. If this is
|
|
||||||
* the case the number is accepted and x is mapped to the appropriate integer
|
|
||||||
* between $min and $max. Otherwise two new doubles are created until the pair
|
|
||||||
* is accepted.
|
|
||||||
*
|
|
||||||
* @param int $min Minimum value of the generated integers.
|
|
||||||
* @param int $max Maximum value of the generated integers.
|
|
||||||
* @param callable $function A function mapping x ∈ [0, 1] onto a double ∈ [0, 1]
|
|
||||||
*
|
|
||||||
* @return int An integer between $min and $max.
|
|
||||||
*/
|
|
||||||
public function biasedNumberBetween($min = 0, $max = 100, $function = 'sqrt')
|
|
||||||
{
|
|
||||||
do {
|
|
||||||
$x = mt_rand() / mt_getrandmax();
|
|
||||||
$y = mt_rand() / (mt_getrandmax() + 1);
|
|
||||||
} while (call_user_func($function, $x) < $y);
|
|
||||||
|
|
||||||
return (int) floor($x * ($max - $min + 1) + $min);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 'unbiased' creates an unbiased distribution by giving
|
|
||||||
* each value the same value of one.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
protected static function unbiased()
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 'linearLow' favors lower numbers. The probability decreases
|
|
||||||
* in a linear fashion.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
protected static function linearLow($x)
|
|
||||||
{
|
|
||||||
return 1 - $x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 'linearHigh' favors higher numbers. The probability increases
|
|
||||||
* in a linear fashion.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
protected static function linearHigh($x)
|
|
||||||
{
|
|
||||||
return $x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-158
@@ -1,158 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Color extends Base
|
|
||||||
{
|
|
||||||
protected static $safeColorNames = [
|
|
||||||
'black', 'maroon', 'green', 'navy', 'olive',
|
|
||||||
'purple', 'teal', 'lime', 'blue', 'silver',
|
|
||||||
'gray', 'yellow', 'fuchsia', 'aqua', 'white',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $allColorNames = [
|
|
||||||
'AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine',
|
|
||||||
'Azure', 'Beige', 'Bisque', 'Black', 'BlanchedAlmond',
|
|
||||||
'Blue', 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue',
|
|
||||||
'Chartreuse', 'Chocolate', 'Coral', 'CornflowerBlue',
|
|
||||||
'Cornsilk', 'Crimson', 'Cyan', 'DarkBlue', 'DarkCyan',
|
|
||||||
'DarkGoldenRod', 'DarkGray', 'DarkGreen', 'DarkKhaki',
|
|
||||||
'DarkMagenta', 'DarkOliveGreen', 'Darkorange', 'DarkOrchid',
|
|
||||||
'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue',
|
|
||||||
'DarkSlateGray', 'DarkTurquoise', 'DarkViolet', 'DeepPink',
|
|
||||||
'DeepSkyBlue', 'DimGray', 'DimGrey', 'DodgerBlue', 'FireBrick',
|
|
||||||
'FloralWhite', 'ForestGreen', 'Fuchsia', 'Gainsboro', 'GhostWhite',
|
|
||||||
'Gold', 'GoldenRod', 'Gray', 'Green', 'GreenYellow', 'HoneyDew',
|
|
||||||
'HotPink', 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender',
|
|
||||||
'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue', 'LightCoral',
|
|
||||||
'LightCyan', 'LightGoldenRodYellow', 'LightGray', 'LightGreen', 'LightPink',
|
|
||||||
'LightSalmon', 'LightSeaGreen', 'LightSkyBlue', 'LightSlateGray', 'LightSteelBlue',
|
|
||||||
'LightYellow', 'Lime', 'LimeGreen', 'Linen', 'Magenta', 'Maroon', 'MediumAquaMarine',
|
|
||||||
'MediumBlue', 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue',
|
|
||||||
'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed', 'MidnightBlue',
|
|
||||||
'MintCream', 'MistyRose', 'Moccasin', 'NavajoWhite', 'Navy', 'OldLace', 'Olive',
|
|
||||||
'OliveDrab', 'Orange', 'OrangeRed', 'Orchid', 'PaleGoldenRod', 'PaleGreen',
|
|
||||||
'PaleTurquoise', 'PaleVioletRed', 'PapayaWhip', 'PeachPuff', 'Peru', 'Pink', 'Plum',
|
|
||||||
'PowderBlue', 'Purple', 'Red', 'RosyBrown', 'RoyalBlue', 'SaddleBrown', 'Salmon',
|
|
||||||
'SandyBrown', 'SeaGreen', 'SeaShell', 'Sienna', 'Silver', 'SkyBlue', 'SlateBlue',
|
|
||||||
'SlateGray', 'Snow', 'SpringGreen', 'SteelBlue', 'Tan', 'Teal', 'Thistle', 'Tomato',
|
|
||||||
'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '#fa3cc2'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function hexColor()
|
|
||||||
{
|
|
||||||
return '#' . str_pad(dechex(self::numberBetween(1, 16777215)), 6, '0', STR_PAD_LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '#ff0044'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function safeHexColor()
|
|
||||||
{
|
|
||||||
$color = str_pad(dechex(self::numberBetween(0, 255)), 3, '0', STR_PAD_LEFT);
|
|
||||||
|
|
||||||
return '#' . $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'array(0,255,122)'
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function rgbColorAsArray()
|
|
||||||
{
|
|
||||||
$color = static::hexColor();
|
|
||||||
|
|
||||||
return [
|
|
||||||
hexdec(substr($color, 1, 2)),
|
|
||||||
hexdec(substr($color, 3, 2)),
|
|
||||||
hexdec(substr($color, 5, 2)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '0,255,122'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function rgbColor()
|
|
||||||
{
|
|
||||||
return implode(',', static::rgbColorAsArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'rgb(0,255,122)'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function rgbCssColor()
|
|
||||||
{
|
|
||||||
return 'rgb(' . static::rgbColor() . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'rgba(0,255,122,0.8)'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function rgbaCssColor()
|
|
||||||
{
|
|
||||||
return 'rgba(' . static::rgbColor() . ',' . static::randomFloat(1, 0, 1) . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'blue'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function safeColorName()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$safeColorNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'NavajoWhite'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function colorName()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$allColorNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '340,50,20'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function hslColor()
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'%s,%s,%s',
|
|
||||||
self::numberBetween(0, 360),
|
|
||||||
self::numberBetween(0, 100),
|
|
||||||
self::numberBetween(0, 100),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example array(340, 50, 20)
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function hslColorAsArray()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
self::numberBetween(0, 360),
|
|
||||||
self::numberBetween(0, 100),
|
|
||||||
self::numberBetween(0, 100),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Company extends Base
|
|
||||||
{
|
|
||||||
protected static $formats = [
|
|
||||||
'{{lastName}} {{companySuffix}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $companySuffix = ['Ltd'];
|
|
||||||
|
|
||||||
protected static $jobTitleFormat = [
|
|
||||||
'{{word}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Acme Ltd'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function company()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$formats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Ltd'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function companySuffix()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$companySuffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Job'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function jobTitle()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$jobTitleFormat);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,389 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class DateTime extends Base
|
|
||||||
{
|
|
||||||
protected static $century = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX', 'XXI'];
|
|
||||||
|
|
||||||
protected static $defaultTimezone = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime|float|int|string $max
|
|
||||||
*
|
|
||||||
* @return false|int
|
|
||||||
*/
|
|
||||||
protected static function getMaxTimestamp($max = 'now')
|
|
||||||
{
|
|
||||||
if (is_numeric($max)) {
|
|
||||||
return (int) $max;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($max instanceof \DateTime) {
|
|
||||||
return $max->getTimestamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtotime(empty($max) ? 'now' : $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a timestamp between January 1, 1970, and now
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @example 1061306726
|
|
||||||
*/
|
|
||||||
public static function unixTime($max = 'now')
|
|
||||||
{
|
|
||||||
return self::numberBetween(0, static::getMaxTimestamp($max));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a datetime object for a date between January 1, 1970 and now
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*
|
|
||||||
* @example DateTime('2005-08-16 20:39:21')
|
|
||||||
*/
|
|
||||||
public static function dateTime($max = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
return static::setTimezone(
|
|
||||||
new \DateTime('@' . static::unixTime($max)),
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a datetime object for a date between January 1, 001 and now
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*
|
|
||||||
* @example DateTime('1265-03-22 21:15:52')
|
|
||||||
*/
|
|
||||||
public static function dateTimeAD($max = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
$min = (PHP_INT_SIZE > 4 ? -62135597361 : -PHP_INT_MAX);
|
|
||||||
|
|
||||||
return static::setTimezone(
|
|
||||||
new \DateTime('@' . self::numberBetween($min, static::getMaxTimestamp($max))),
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a date string formatted with ISO8601
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '2003-10-21T16:05:52+0000'
|
|
||||||
*/
|
|
||||||
public static function iso8601($max = 'now')
|
|
||||||
{
|
|
||||||
return static::date(\DateTime::ISO8601, $max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date string between January 1, 1970 and now
|
|
||||||
*
|
|
||||||
* @param string $format
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '2008-11-27'
|
|
||||||
*/
|
|
||||||
public static function date($format = 'Y-m-d', $max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a time string (24h format by default)
|
|
||||||
*
|
|
||||||
* @param string $format
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '15:02:34'
|
|
||||||
*/
|
|
||||||
public static function time($format = 'H:i:s', $max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a DateTime object based on a random date between two given dates.
|
|
||||||
* Accepts date strings that can be recognized by strtotime().
|
|
||||||
*
|
|
||||||
* @param \DateTime|string $startDate Defaults to 30 years ago
|
|
||||||
* @param \DateTime|string $endDate Defaults to "now"
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*
|
|
||||||
* @example DateTime('1999-02-02 11:42:52')
|
|
||||||
*/
|
|
||||||
public static function dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
$startTimestamp = $startDate instanceof \DateTime ? $startDate->getTimestamp() : strtotime($startDate);
|
|
||||||
$endTimestamp = static::getMaxTimestamp($endDate);
|
|
||||||
|
|
||||||
if ($startTimestamp > $endTimestamp) {
|
|
||||||
throw new \InvalidArgumentException('Start date must be anterior to end date.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$timestamp = self::numberBetween($startTimestamp, $endTimestamp);
|
|
||||||
|
|
||||||
return static::setTimezone(
|
|
||||||
new \DateTime('@' . $timestamp),
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a DateTime object based on a random date between one given date and
|
|
||||||
* an interval
|
|
||||||
* Accepts date string that can be recognized by strtotime().
|
|
||||||
*
|
|
||||||
* @param \DateTime|string $date Defaults to 30 years ago
|
|
||||||
* @param string $interval Defaults to 5 days after
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @example dateTimeInInterval('1999-02-02 11:42:52', '+ 5 days')
|
|
||||||
*
|
|
||||||
* @see http://php.net/manual/en/timezones.php
|
|
||||||
* @see http://php.net/manual/en/function.date-default-timezone-get.php
|
|
||||||
*/
|
|
||||||
public static function dateTimeInInterval($date = '-30 years', $interval = '+5 days', $timezone = null)
|
|
||||||
{
|
|
||||||
$intervalObject = \DateInterval::createFromDateString($interval);
|
|
||||||
$datetime = $date instanceof \DateTime ? $date : new \DateTime($date);
|
|
||||||
$otherDatetime = clone $datetime;
|
|
||||||
$otherDatetime->add($intervalObject);
|
|
||||||
|
|
||||||
$begin = min($datetime, $otherDatetime);
|
|
||||||
$end = $datetime === $begin ? $otherDatetime : $datetime;
|
|
||||||
|
|
||||||
return static::dateTimeBetween(
|
|
||||||
$begin,
|
|
||||||
$end,
|
|
||||||
$timezone,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere within a century.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public static function dateTimeThisCentury($max = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
return static::dateTimeBetween('-100 year', $max, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere within a decade.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public static function dateTimeThisDecade($max = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
return static::dateTimeBetween('-10 year', $max, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere inside the current year.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public static function dateTimeThisYear($max = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
return static::dateTimeBetween('first day of january this year', $max, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a date time object somewhere within a month.
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public static function dateTimeThisMonth($max = 'now', $timezone = null)
|
|
||||||
{
|
|
||||||
return static::dateTimeBetween('-1 month', $max, $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string containing either "am" or "pm".
|
|
||||||
*
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'am'
|
|
||||||
*/
|
|
||||||
public static function amPm($max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format('a');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '22'
|
|
||||||
*/
|
|
||||||
public static function dayOfMonth($max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format('d');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'Tuesday'
|
|
||||||
*/
|
|
||||||
public static function dayOfWeek($max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format('l');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '7'
|
|
||||||
*/
|
|
||||||
public static function month($max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format('m');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'September'
|
|
||||||
*/
|
|
||||||
public static function monthName($max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format('F');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '1987'
|
|
||||||
*/
|
|
||||||
public static function year($max = 'now')
|
|
||||||
{
|
|
||||||
return static::dateTime($max)->format('Y');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'XVII'
|
|
||||||
*/
|
|
||||||
public static function century()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$century);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'Europe/Paris'
|
|
||||||
*/
|
|
||||||
public static function timezone(?string $countryCode = null)
|
|
||||||
{
|
|
||||||
if ($countryCode) {
|
|
||||||
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode);
|
|
||||||
} else {
|
|
||||||
$timezones = \DateTimeZone::listIdentifiers();
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::randomElement($timezones);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal method to set the time zone on a DateTime.
|
|
||||||
*
|
|
||||||
* @param string|null $timezone
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
private static function setTimezone(\DateTime $dt, $timezone)
|
|
||||||
{
|
|
||||||
return $dt->setTimezone(new \DateTimeZone(static::resolveTimezone($timezone)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets default time zone.
|
|
||||||
*
|
|
||||||
* @param string $timezone
|
|
||||||
*/
|
|
||||||
public static function setDefaultTimezone($timezone = null)
|
|
||||||
{
|
|
||||||
static::$defaultTimezone = $timezone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets default time zone.
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public static function getDefaultTimezone()
|
|
||||||
{
|
|
||||||
return static::$defaultTimezone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $timezone
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
private static function resolveTimezone($timezone)
|
|
||||||
{
|
|
||||||
return (null === $timezone) ? ((null === static::$defaultTimezone) ? date_default_timezone_get() : static::$defaultTimezone) : $timezone;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-610
@@ -1,610 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class File extends Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* MIME types from the apache.org file. Some types are truncated.
|
|
||||||
*
|
|
||||||
* @var array Map of MIME types => file extension(s)
|
|
||||||
*
|
|
||||||
* @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
|
||||||
*/
|
|
||||||
protected static $mimeTypes = [
|
|
||||||
'application/atom+xml' => 'atom',
|
|
||||||
'application/ecmascript' => 'ecma',
|
|
||||||
'application/emma+xml' => 'emma',
|
|
||||||
'application/epub+zip' => 'epub',
|
|
||||||
'application/java-archive' => 'jar',
|
|
||||||
'application/java-vm' => 'class',
|
|
||||||
'application/javascript' => 'js',
|
|
||||||
'application/json' => 'json',
|
|
||||||
'application/jsonml+json' => 'jsonml',
|
|
||||||
'application/lost+xml' => 'lostxml',
|
|
||||||
'application/mathml+xml' => 'mathml',
|
|
||||||
'application/mets+xml' => 'mets',
|
|
||||||
'application/mods+xml' => 'mods',
|
|
||||||
'application/mp4' => 'mp4s',
|
|
||||||
'application/msword' => ['doc', 'dot'],
|
|
||||||
'application/octet-stream' => [
|
|
||||||
'bin',
|
|
||||||
'dms',
|
|
||||||
'lrf',
|
|
||||||
'mar',
|
|
||||||
'so',
|
|
||||||
'dist',
|
|
||||||
'distz',
|
|
||||||
'pkg',
|
|
||||||
'bpk',
|
|
||||||
'dump',
|
|
||||||
'elc',
|
|
||||||
'deploy',
|
|
||||||
],
|
|
||||||
'application/ogg' => 'ogx',
|
|
||||||
'application/omdoc+xml' => 'omdoc',
|
|
||||||
'application/pdf' => 'pdf',
|
|
||||||
'application/pgp-encrypted' => 'pgp',
|
|
||||||
'application/pgp-signature' => ['asc', 'sig'],
|
|
||||||
'application/pkix-pkipath' => 'pkipath',
|
|
||||||
'application/pkixcmp' => 'pki',
|
|
||||||
'application/pls+xml' => 'pls',
|
|
||||||
'application/postscript' => ['ai', 'eps', 'ps'],
|
|
||||||
'application/pskc+xml' => 'pskcxml',
|
|
||||||
'application/rdf+xml' => 'rdf',
|
|
||||||
'application/reginfo+xml' => 'rif',
|
|
||||||
'application/rss+xml' => 'rss',
|
|
||||||
'application/rtf' => 'rtf',
|
|
||||||
'application/sbml+xml' => 'sbml',
|
|
||||||
'application/vnd.adobe.air-application-installer-package+zip' => 'air',
|
|
||||||
'application/vnd.adobe.xdp+xml' => 'xdp',
|
|
||||||
'application/vnd.adobe.xfdf' => 'xfdf',
|
|
||||||
'application/vnd.ahead.space' => 'ahead',
|
|
||||||
'application/vnd.dart' => 'dart',
|
|
||||||
'application/vnd.data-vision.rdz' => 'rdz',
|
|
||||||
'application/vnd.dece.data' => ['uvf', 'uvvf', 'uvd', 'uvvd'],
|
|
||||||
'application/vnd.dece.ttml+xml' => ['uvt', 'uvvt'],
|
|
||||||
'application/vnd.dece.unspecified' => ['uvx', 'uvvx'],
|
|
||||||
'application/vnd.dece.zip' => ['uvz', 'uvvz'],
|
|
||||||
'application/vnd.denovo.fcselayout-link' => 'fe_launch',
|
|
||||||
'application/vnd.dna' => 'dna',
|
|
||||||
'application/vnd.dolby.mlp' => 'mlp',
|
|
||||||
'application/vnd.dpgraph' => 'dpg',
|
|
||||||
'application/vnd.dreamfactory' => 'dfac',
|
|
||||||
'application/vnd.ds-keypoint' => 'kpxx',
|
|
||||||
'application/vnd.dvb.ait' => 'ait',
|
|
||||||
'application/vnd.dvb.service' => 'svc',
|
|
||||||
'application/vnd.dynageo' => 'geo',
|
|
||||||
'application/vnd.ecowin.chart' => 'mag',
|
|
||||||
'application/vnd.enliven' => 'nml',
|
|
||||||
'application/vnd.epson.esf' => 'esf',
|
|
||||||
'application/vnd.epson.msf' => 'msf',
|
|
||||||
'application/vnd.epson.quickanime' => 'qam',
|
|
||||||
'application/vnd.epson.salt' => 'slt',
|
|
||||||
'application/vnd.epson.ssf' => 'ssf',
|
|
||||||
'application/vnd.ezpix-album' => 'ez2',
|
|
||||||
'application/vnd.ezpix-package' => 'ez3',
|
|
||||||
'application/vnd.fdf' => 'fdf',
|
|
||||||
'application/vnd.fdsn.mseed' => 'mseed',
|
|
||||||
'application/vnd.fdsn.seed' => ['seed', 'dataless'],
|
|
||||||
'application/vnd.flographit' => 'gph',
|
|
||||||
'application/vnd.fluxtime.clip' => 'ftc',
|
|
||||||
'application/vnd.hal+xml' => 'hal',
|
|
||||||
'application/vnd.hydrostatix.sof-data' => 'sfd-hdstx',
|
|
||||||
'application/vnd.ibm.minipay' => 'mpy',
|
|
||||||
'application/vnd.ibm.secure-container' => 'sc',
|
|
||||||
'application/vnd.iccprofile' => ['icc', 'icm'],
|
|
||||||
'application/vnd.igloader' => 'igl',
|
|
||||||
'application/vnd.immervision-ivp' => 'ivp',
|
|
||||||
'application/vnd.kde.karbon' => 'karbon',
|
|
||||||
'application/vnd.kde.kchart' => 'chrt',
|
|
||||||
'application/vnd.kde.kformula' => 'kfo',
|
|
||||||
'application/vnd.kde.kivio' => 'flw',
|
|
||||||
'application/vnd.kde.kontour' => 'kon',
|
|
||||||
'application/vnd.kde.kpresenter' => ['kpr', 'kpt'],
|
|
||||||
'application/vnd.kde.kspread' => 'ksp',
|
|
||||||
'application/vnd.kde.kword' => ['kwd', 'kwt'],
|
|
||||||
'application/vnd.kenameaapp' => 'htke',
|
|
||||||
'application/vnd.kidspiration' => 'kia',
|
|
||||||
'application/vnd.kinar' => ['kne', 'knp'],
|
|
||||||
'application/vnd.koan' => ['skp', 'skd', 'skt', 'skm'],
|
|
||||||
'application/vnd.kodak-descriptor' => 'sse',
|
|
||||||
'application/vnd.las.las+xml' => 'lasxml',
|
|
||||||
'application/vnd.llamagraphics.life-balance.desktop' => 'lbd',
|
|
||||||
'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe',
|
|
||||||
'application/vnd.lotus-1-2-3' => '123',
|
|
||||||
'application/vnd.lotus-approach' => 'apr',
|
|
||||||
'application/vnd.lotus-freelance' => 'pre',
|
|
||||||
'application/vnd.lotus-notes' => 'nsf',
|
|
||||||
'application/vnd.lotus-organizer' => 'org',
|
|
||||||
'application/vnd.lotus-screencam' => 'scm',
|
|
||||||
'application/vnd.mozilla.xul+xml' => 'xul',
|
|
||||||
'application/vnd.ms-artgalry' => 'cil',
|
|
||||||
'application/vnd.ms-cab-compressed' => 'cab',
|
|
||||||
'application/vnd.ms-excel' => [
|
|
||||||
'xls',
|
|
||||||
'xlm',
|
|
||||||
'xla',
|
|
||||||
'xlc',
|
|
||||||
'xlt',
|
|
||||||
'xlw',
|
|
||||||
],
|
|
||||||
'application/vnd.ms-excel.addin.macroenabled.12' => 'xlam',
|
|
||||||
'application/vnd.ms-excel.sheet.binary.macroenabled.12' => 'xlsb',
|
|
||||||
'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm',
|
|
||||||
'application/vnd.ms-excel.template.macroenabled.12' => 'xltm',
|
|
||||||
'application/vnd.ms-fontobject' => 'eot',
|
|
||||||
'application/vnd.ms-htmlhelp' => 'chm',
|
|
||||||
'application/vnd.ms-ims' => 'ims',
|
|
||||||
'application/vnd.ms-lrm' => 'lrm',
|
|
||||||
'application/vnd.ms-officetheme' => 'thmx',
|
|
||||||
'application/vnd.ms-pki.seccat' => 'cat',
|
|
||||||
'application/vnd.ms-pki.stl' => 'stl',
|
|
||||||
'application/vnd.ms-powerpoint' => ['ppt', 'pps', 'pot'],
|
|
||||||
'application/vnd.ms-powerpoint.addin.macroenabled.12' => 'ppam',
|
|
||||||
'application/vnd.ms-powerpoint.presentation.macroenabled.12' => 'pptm',
|
|
||||||
'application/vnd.ms-powerpoint.slide.macroenabled.12' => 'sldm',
|
|
||||||
'application/vnd.ms-powerpoint.slideshow.macroenabled.12' => 'ppsm',
|
|
||||||
'application/vnd.ms-powerpoint.template.macroenabled.12' => 'potm',
|
|
||||||
'application/vnd.ms-project' => ['mpp', 'mpt'],
|
|
||||||
'application/vnd.ms-word.document.macroenabled.12' => 'docm',
|
|
||||||
'application/vnd.ms-word.template.macroenabled.12' => 'dotm',
|
|
||||||
'application/vnd.ms-works' => ['wps', 'wks', 'wcm', 'wdb'],
|
|
||||||
'application/vnd.ms-wpl' => 'wpl',
|
|
||||||
'application/vnd.ms-xpsdocument' => 'xps',
|
|
||||||
'application/vnd.mseq' => 'mseq',
|
|
||||||
'application/vnd.musician' => 'mus',
|
|
||||||
'application/vnd.oasis.opendocument.chart' => 'odc',
|
|
||||||
'application/vnd.oasis.opendocument.chart-template' => 'otc',
|
|
||||||
'application/vnd.oasis.opendocument.database' => 'odb',
|
|
||||||
'application/vnd.oasis.opendocument.formula' => 'odf',
|
|
||||||
'application/vnd.oasis.opendocument.formula-template' => 'odft',
|
|
||||||
'application/vnd.oasis.opendocument.graphics' => 'odg',
|
|
||||||
'application/vnd.oasis.opendocument.graphics-template' => 'otg',
|
|
||||||
'application/vnd.oasis.opendocument.image' => 'odi',
|
|
||||||
'application/vnd.oasis.opendocument.image-template' => 'oti',
|
|
||||||
'application/vnd.oasis.opendocument.presentation' => 'odp',
|
|
||||||
'application/vnd.oasis.opendocument.presentation-template' => 'otp',
|
|
||||||
'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
|
|
||||||
'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
|
|
||||||
'application/vnd.oasis.opendocument.text' => 'odt',
|
|
||||||
'application/vnd.oasis.opendocument.text-master' => 'odm',
|
|
||||||
'application/vnd.oasis.opendocument.text-template' => 'ott',
|
|
||||||
'application/vnd.oasis.opendocument.text-web' => 'oth',
|
|
||||||
'application/vnd.olpc-sugar' => 'xo',
|
|
||||||
'application/vnd.oma.dd2+xml' => 'dd2',
|
|
||||||
'application/vnd.openofficeorg.extension' => 'oxt',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slide' => 'sldx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'potx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'xltx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx',
|
|
||||||
'application/vnd.pvi.ptid1' => 'ptid',
|
|
||||||
'application/vnd.quark.quarkxpress' => [
|
|
||||||
'qxd',
|
|
||||||
'qxt',
|
|
||||||
'qwd',
|
|
||||||
'qwt',
|
|
||||||
'qxl',
|
|
||||||
'qxb',
|
|
||||||
],
|
|
||||||
'application/vnd.realvnc.bed' => 'bed',
|
|
||||||
'application/vnd.recordare.musicxml' => 'mxl',
|
|
||||||
'application/vnd.recordare.musicxml+xml' => 'musicxml',
|
|
||||||
'application/vnd.rig.cryptonote' => 'cryptonote',
|
|
||||||
'application/vnd.rim.cod' => 'cod',
|
|
||||||
'application/vnd.rn-realmedia' => 'rm',
|
|
||||||
'application/vnd.rn-realmedia-vbr' => 'rmvb',
|
|
||||||
'application/vnd.route66.link66+xml' => 'link66',
|
|
||||||
'application/vnd.sailingtracker.track' => 'st',
|
|
||||||
'application/vnd.seemail' => 'see',
|
|
||||||
'application/vnd.sema' => 'sema',
|
|
||||||
'application/vnd.semd' => 'semd',
|
|
||||||
'application/vnd.semf' => 'semf',
|
|
||||||
'application/vnd.shana.informed.formdata' => 'ifm',
|
|
||||||
'application/vnd.shana.informed.formtemplate' => 'itp',
|
|
||||||
'application/vnd.shana.informed.interchange' => 'iif',
|
|
||||||
'application/vnd.shana.informed.package' => 'ipk',
|
|
||||||
'application/vnd.simtech-mindmapper' => ['twd', 'twds'],
|
|
||||||
'application/vnd.smaf' => 'mmf',
|
|
||||||
'application/vnd.stepmania.stepchart' => 'sm',
|
|
||||||
'application/vnd.sun.xml.calc' => 'sxc',
|
|
||||||
'application/vnd.sun.xml.calc.template' => 'stc',
|
|
||||||
'application/vnd.sun.xml.draw' => 'sxd',
|
|
||||||
'application/vnd.sun.xml.draw.template' => 'std',
|
|
||||||
'application/vnd.sun.xml.impress' => 'sxi',
|
|
||||||
'application/vnd.sun.xml.impress.template' => 'sti',
|
|
||||||
'application/vnd.sun.xml.math' => 'sxm',
|
|
||||||
'application/vnd.sun.xml.writer' => 'sxw',
|
|
||||||
'application/vnd.sun.xml.writer.global' => 'sxg',
|
|
||||||
'application/vnd.sun.xml.writer.template' => 'stw',
|
|
||||||
'application/vnd.sus-calendar' => ['sus', 'susp'],
|
|
||||||
'application/vnd.svd' => 'svd',
|
|
||||||
'application/vnd.symbian.install' => ['sis', 'sisx'],
|
|
||||||
'application/vnd.syncml+xml' => 'xsm',
|
|
||||||
'application/vnd.syncml.dm+wbxml' => 'bdm',
|
|
||||||
'application/vnd.syncml.dm+xml' => 'xdm',
|
|
||||||
'application/vnd.tao.intent-module-archive' => 'tao',
|
|
||||||
'application/vnd.tcpdump.pcap' => ['pcap', 'cap', 'dmp'],
|
|
||||||
'application/vnd.tmobile-livetv' => 'tmo',
|
|
||||||
'application/vnd.trid.tpt' => 'tpt',
|
|
||||||
'application/vnd.triscape.mxs' => 'mxs',
|
|
||||||
'application/vnd.trueapp' => 'tra',
|
|
||||||
'application/vnd.ufdl' => ['ufd', 'ufdl'],
|
|
||||||
'application/vnd.uiq.theme' => 'utz',
|
|
||||||
'application/vnd.umajin' => 'umj',
|
|
||||||
'application/vnd.unity' => 'unityweb',
|
|
||||||
'application/vnd.uoml+xml' => 'uoml',
|
|
||||||
'application/vnd.vcx' => 'vcx',
|
|
||||||
'application/vnd.visio' => ['vsd', 'vst', 'vss', 'vsw'],
|
|
||||||
'application/vnd.visionary' => 'vis',
|
|
||||||
'application/vnd.vsf' => 'vsf',
|
|
||||||
'application/vnd.wap.wbxml' => 'wbxml',
|
|
||||||
'application/vnd.wap.wmlc' => 'wmlc',
|
|
||||||
'application/vnd.wap.wmlscriptc' => 'wmlsc',
|
|
||||||
'application/vnd.webturbo' => 'wtb',
|
|
||||||
'application/vnd.wolfram.player' => 'nbp',
|
|
||||||
'application/vnd.wordperfect' => 'wpd',
|
|
||||||
'application/vnd.wqd' => 'wqd',
|
|
||||||
'application/vnd.wt.stf' => 'stf',
|
|
||||||
'application/vnd.xara' => 'xar',
|
|
||||||
'application/vnd.xfdl' => 'xfdl',
|
|
||||||
'application/voicexml+xml' => 'vxml',
|
|
||||||
'application/widget' => 'wgt',
|
|
||||||
'application/winhlp' => 'hlp',
|
|
||||||
'application/wsdl+xml' => 'wsdl',
|
|
||||||
'application/wspolicy+xml' => 'wspolicy',
|
|
||||||
'application/x-7z-compressed' => '7z',
|
|
||||||
'application/x-bittorrent' => 'torrent',
|
|
||||||
'application/x-blorb' => ['blb', 'blorb'],
|
|
||||||
'application/x-bzip' => 'bz',
|
|
||||||
'application/x-cdlink' => 'vcd',
|
|
||||||
'application/x-cfs-compressed' => 'cfs',
|
|
||||||
'application/x-chat' => 'chat',
|
|
||||||
'application/x-chess-pgn' => 'pgn',
|
|
||||||
'application/x-conference' => 'nsc',
|
|
||||||
'application/x-cpio' => 'cpio',
|
|
||||||
'application/x-csh' => 'csh',
|
|
||||||
'application/x-debian-package' => ['deb', 'udeb'],
|
|
||||||
'application/x-dgc-compressed' => 'dgc',
|
|
||||||
'application/x-director' => [
|
|
||||||
'dir',
|
|
||||||
'dcr',
|
|
||||||
'dxr',
|
|
||||||
'cst',
|
|
||||||
'cct',
|
|
||||||
'cxt',
|
|
||||||
'w3d',
|
|
||||||
'fgd',
|
|
||||||
'swa',
|
|
||||||
],
|
|
||||||
'application/x-font-ttf' => ['ttf', 'ttc'],
|
|
||||||
'application/x-font-type1' => ['pfa', 'pfb', 'pfm', 'afm'],
|
|
||||||
'application/x-font-woff' => 'woff',
|
|
||||||
'application/x-freearc' => 'arc',
|
|
||||||
'application/x-futuresplash' => 'spl',
|
|
||||||
'application/x-gca-compressed' => 'gca',
|
|
||||||
'application/x-glulx' => 'ulx',
|
|
||||||
'application/x-gnumeric' => 'gnumeric',
|
|
||||||
'application/x-gramps-xml' => 'gramps',
|
|
||||||
'application/x-gtar' => 'gtar',
|
|
||||||
'application/x-hdf' => 'hdf',
|
|
||||||
'application/x-install-instructions' => 'install',
|
|
||||||
'application/x-iso9660-image' => 'iso',
|
|
||||||
'application/x-java-jnlp-file' => 'jnlp',
|
|
||||||
'application/x-latex' => 'latex',
|
|
||||||
'application/x-lzh-compressed' => ['lzh', 'lha'],
|
|
||||||
'application/x-mie' => 'mie',
|
|
||||||
'application/x-mobipocket-ebook' => ['prc', 'mobi'],
|
|
||||||
'application/x-ms-application' => 'application',
|
|
||||||
'application/x-ms-shortcut' => 'lnk',
|
|
||||||
'application/x-ms-wmd' => 'wmd',
|
|
||||||
'application/x-ms-wmz' => 'wmz',
|
|
||||||
'application/x-ms-xbap' => 'xbap',
|
|
||||||
'application/x-msaccess' => 'mdb',
|
|
||||||
'application/x-msbinder' => 'obd',
|
|
||||||
'application/x-mscardfile' => 'crd',
|
|
||||||
'application/x-msclip' => 'clp',
|
|
||||||
'application/x-msdownload' => ['exe', 'dll', 'com', 'bat', 'msi'],
|
|
||||||
'application/x-msmediaview' => [
|
|
||||||
'mvb',
|
|
||||||
'm13',
|
|
||||||
'm14',
|
|
||||||
],
|
|
||||||
'application/x-msmetafile' => ['wmf', 'wmz', 'emf', 'emz'],
|
|
||||||
'application/x-rar-compressed' => 'rar',
|
|
||||||
'application/x-research-info-systems' => 'ris',
|
|
||||||
'application/x-sh' => 'sh',
|
|
||||||
'application/x-shar' => 'shar',
|
|
||||||
'application/x-shockwave-flash' => 'swf',
|
|
||||||
'application/x-silverlight-app' => 'xap',
|
|
||||||
'application/x-sql' => 'sql',
|
|
||||||
'application/x-stuffit' => 'sit',
|
|
||||||
'application/x-stuffitx' => 'sitx',
|
|
||||||
'application/x-subrip' => 'srt',
|
|
||||||
'application/x-sv4cpio' => 'sv4cpio',
|
|
||||||
'application/x-sv4crc' => 'sv4crc',
|
|
||||||
'application/x-t3vm-image' => 't3',
|
|
||||||
'application/x-tads' => 'gam',
|
|
||||||
'application/x-tar' => 'tar',
|
|
||||||
'application/x-tcl' => 'tcl',
|
|
||||||
'application/x-tex' => 'tex',
|
|
||||||
'application/x-tex-tfm' => 'tfm',
|
|
||||||
'application/x-texinfo' => ['texinfo', 'texi'],
|
|
||||||
'application/x-tgif' => 'obj',
|
|
||||||
'application/x-ustar' => 'ustar',
|
|
||||||
'application/x-wais-source' => 'src',
|
|
||||||
'application/x-x509-ca-cert' => ['der', 'crt'],
|
|
||||||
'application/x-xfig' => 'fig',
|
|
||||||
'application/x-xliff+xml' => 'xlf',
|
|
||||||
'application/x-xpinstall' => 'xpi',
|
|
||||||
'application/x-xz' => 'xz',
|
|
||||||
'application/x-zmachine' => 'z1',
|
|
||||||
'application/xaml+xml' => 'xaml',
|
|
||||||
'application/xcap-diff+xml' => 'xdf',
|
|
||||||
'application/xenc+xml' => 'xenc',
|
|
||||||
'application/xhtml+xml' => ['xhtml', 'xht'],
|
|
||||||
'application/xml' => ['xml', 'xsl'],
|
|
||||||
'application/xml-dtd' => 'dtd',
|
|
||||||
'application/xop+xml' => 'xop',
|
|
||||||
'application/xproc+xml' => 'xpl',
|
|
||||||
'application/xslt+xml' => 'xslt',
|
|
||||||
'application/xspf+xml' => 'xspf',
|
|
||||||
'application/xv+xml' => ['mxml', 'xhvml', 'xvml', 'xvm'],
|
|
||||||
'application/yang' => 'yang',
|
|
||||||
'application/yin+xml' => 'yin',
|
|
||||||
'application/zip' => 'zip',
|
|
||||||
'audio/adpcm' => 'adp',
|
|
||||||
'audio/basic' => ['au', 'snd'],
|
|
||||||
'audio/midi' => ['mid', 'midi', 'kar', 'rmi'],
|
|
||||||
'audio/mp4' => 'mp4a',
|
|
||||||
'audio/mpeg' => [
|
|
||||||
'mpga',
|
|
||||||
'mp2',
|
|
||||||
'mp2a',
|
|
||||||
'mp3',
|
|
||||||
'm2a',
|
|
||||||
'm3a',
|
|
||||||
],
|
|
||||||
'audio/ogg' => ['oga', 'ogg', 'spx'],
|
|
||||||
'audio/vnd.dece.audio' => ['uva', 'uvva'],
|
|
||||||
'audio/vnd.rip' => 'rip',
|
|
||||||
'audio/webm' => 'weba',
|
|
||||||
'audio/x-aac' => 'aac',
|
|
||||||
'audio/x-aiff' => ['aif', 'aiff', 'aifc'],
|
|
||||||
'audio/x-caf' => 'caf',
|
|
||||||
'audio/x-flac' => 'flac',
|
|
||||||
'audio/x-matroska' => 'mka',
|
|
||||||
'audio/x-mpegurl' => 'm3u',
|
|
||||||
'audio/x-ms-wax' => 'wax',
|
|
||||||
'audio/x-ms-wma' => 'wma',
|
|
||||||
'audio/x-pn-realaudio' => ['ram', 'ra'],
|
|
||||||
'audio/x-pn-realaudio-plugin' => 'rmp',
|
|
||||||
'audio/x-wav' => 'wav',
|
|
||||||
'audio/xm' => 'xm',
|
|
||||||
'image/bmp' => 'bmp',
|
|
||||||
'image/cgm' => 'cgm',
|
|
||||||
'image/g3fax' => 'g3',
|
|
||||||
'image/gif' => 'gif',
|
|
||||||
'image/ief' => 'ief',
|
|
||||||
'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
|
|
||||||
'image/ktx' => 'ktx',
|
|
||||||
'image/png' => 'png',
|
|
||||||
'image/prs.btif' => 'btif',
|
|
||||||
'image/sgi' => 'sgi',
|
|
||||||
'image/svg+xml' => ['svg', 'svgz'],
|
|
||||||
'image/tiff' => ['tiff', 'tif'],
|
|
||||||
'image/vnd.adobe.photoshop' => 'psd',
|
|
||||||
'image/vnd.dece.graphic' => ['uvi', 'uvvi', 'uvg', 'uvvg'],
|
|
||||||
'image/vnd.dvb.subtitle' => 'sub',
|
|
||||||
'image/vnd.djvu' => ['djvu', 'djv'],
|
|
||||||
'image/vnd.dwg' => 'dwg',
|
|
||||||
'image/vnd.dxf' => 'dxf',
|
|
||||||
'image/vnd.fastbidsheet' => 'fbs',
|
|
||||||
'image/vnd.fpx' => 'fpx',
|
|
||||||
'image/vnd.fst' => 'fst',
|
|
||||||
'image/vnd.fujixerox.edmics-mmr' => 'mmr',
|
|
||||||
'image/vnd.fujixerox.edmics-rlc' => 'rlc',
|
|
||||||
'image/vnd.ms-modi' => 'mdi',
|
|
||||||
'image/vnd.ms-photo' => 'wdp',
|
|
||||||
'image/vnd.net-fpx' => 'npx',
|
|
||||||
'image/vnd.wap.wbmp' => 'wbmp',
|
|
||||||
'image/vnd.xiff' => 'xif',
|
|
||||||
'image/webp' => 'webp',
|
|
||||||
'image/x-3ds' => '3ds',
|
|
||||||
'image/x-cmu-raster' => 'ras',
|
|
||||||
'image/x-cmx' => 'cmx',
|
|
||||||
'image/x-freehand' => ['fh', 'fhc', 'fh4', 'fh5', 'fh7'],
|
|
||||||
'image/x-icon' => 'ico',
|
|
||||||
'image/x-mrsid-image' => 'sid',
|
|
||||||
'image/x-pcx' => 'pcx',
|
|
||||||
'image/x-pict' => ['pic', 'pct'],
|
|
||||||
'image/x-portable-anymap' => 'pnm',
|
|
||||||
'image/x-portable-bitmap' => 'pbm',
|
|
||||||
'image/x-portable-graymap' => 'pgm',
|
|
||||||
'image/x-portable-pixmap' => 'ppm',
|
|
||||||
'image/x-rgb' => 'rgb',
|
|
||||||
'image/x-tga' => 'tga',
|
|
||||||
'image/x-xbitmap' => 'xbm',
|
|
||||||
'image/x-xpixmap' => 'xpm',
|
|
||||||
'image/x-xwindowdump' => 'xwd',
|
|
||||||
'message/rfc822' => ['eml', 'mime'],
|
|
||||||
'model/iges' => ['igs', 'iges'],
|
|
||||||
'model/mesh' => ['msh', 'mesh', 'silo'],
|
|
||||||
'model/vnd.collada+xml' => 'dae',
|
|
||||||
'model/vnd.dwf' => 'dwf',
|
|
||||||
'model/vnd.gdl' => 'gdl',
|
|
||||||
'model/vnd.gtw' => 'gtw',
|
|
||||||
'model/vnd.mts' => 'mts',
|
|
||||||
'model/vnd.vtu' => 'vtu',
|
|
||||||
'model/vrml' => ['wrl', 'vrml'],
|
|
||||||
'model/x3d+binary' => 'x3db',
|
|
||||||
'model/x3d+vrml' => 'x3dv',
|
|
||||||
'model/x3d+xml' => 'x3d',
|
|
||||||
'text/cache-manifest' => 'appcache',
|
|
||||||
'text/calendar' => ['ics', 'ifb'],
|
|
||||||
'text/css' => 'css',
|
|
||||||
'text/csv' => 'csv',
|
|
||||||
'text/html' => ['html', 'htm'],
|
|
||||||
'text/n3' => 'n3',
|
|
||||||
'text/plain' => [
|
|
||||||
'txt',
|
|
||||||
'text',
|
|
||||||
'conf',
|
|
||||||
'def',
|
|
||||||
'list',
|
|
||||||
'log',
|
|
||||||
'in',
|
|
||||||
],
|
|
||||||
'text/prs.lines.tag' => 'dsc',
|
|
||||||
'text/richtext' => 'rtx',
|
|
||||||
'text/sgml' => ['sgml', 'sgm'],
|
|
||||||
'text/tab-separated-values' => 'tsv',
|
|
||||||
'text/troff' => [
|
|
||||||
't',
|
|
||||||
'tr',
|
|
||||||
'roff',
|
|
||||||
'man',
|
|
||||||
'me',
|
|
||||||
'ms',
|
|
||||||
],
|
|
||||||
'text/turtle' => 'ttl',
|
|
||||||
'text/uri-list' => ['uri', 'uris', 'urls'],
|
|
||||||
'text/vcard' => 'vcard',
|
|
||||||
'text/vnd.curl' => 'curl',
|
|
||||||
'text/vnd.curl.dcurl' => 'dcurl',
|
|
||||||
'text/vnd.curl.scurl' => 'scurl',
|
|
||||||
'text/vnd.curl.mcurl' => 'mcurl',
|
|
||||||
'text/vnd.dvb.subtitle' => 'sub',
|
|
||||||
'text/vnd.fly' => 'fly',
|
|
||||||
'text/vnd.fmi.flexstor' => 'flx',
|
|
||||||
'text/vnd.graphviz' => 'gv',
|
|
||||||
'text/vnd.in3d.3dml' => '3dml',
|
|
||||||
'text/vnd.in3d.spot' => 'spot',
|
|
||||||
'text/vnd.sun.j2me.app-descriptor' => 'jad',
|
|
||||||
'text/vnd.wap.wml' => 'wml',
|
|
||||||
'text/vnd.wap.wmlscript' => 'wmls',
|
|
||||||
'text/x-asm' => ['s', 'asm'],
|
|
||||||
'text/x-fortran' => ['f', 'for', 'f77', 'f90'],
|
|
||||||
'text/x-java-source' => 'java',
|
|
||||||
'text/x-opml' => 'opml',
|
|
||||||
'text/x-pascal' => ['p', 'pas'],
|
|
||||||
'text/x-nfo' => 'nfo',
|
|
||||||
'text/x-setext' => 'etx',
|
|
||||||
'text/x-sfv' => 'sfv',
|
|
||||||
'text/x-uuencode' => 'uu',
|
|
||||||
'text/x-vcalendar' => 'vcs',
|
|
||||||
'text/x-vcard' => 'vcf',
|
|
||||||
'video/3gpp' => '3gp',
|
|
||||||
'video/3gpp2' => '3g2',
|
|
||||||
'video/h261' => 'h261',
|
|
||||||
'video/h263' => 'h263',
|
|
||||||
'video/h264' => 'h264',
|
|
||||||
'video/jpeg' => 'jpgv',
|
|
||||||
'video/jpm' => ['jpm', 'jpgm'],
|
|
||||||
'video/mj2' => 'mj2',
|
|
||||||
'video/mp4' => 'mp4',
|
|
||||||
'video/mpeg' => ['mpeg', 'mpg', 'mpe', 'm1v', 'm2v'],
|
|
||||||
'video/ogg' => 'ogv',
|
|
||||||
'video/quicktime' => ['qt', 'mov'],
|
|
||||||
'video/vnd.dece.hd' => ['uvh', 'uvvh'],
|
|
||||||
'video/vnd.dece.mobile' => ['uvm', 'uvvm'],
|
|
||||||
'video/vnd.dece.pd' => ['uvp', 'uvvp'],
|
|
||||||
'video/vnd.dece.sd' => ['uvs', 'uvvs'],
|
|
||||||
'video/vnd.dece.video' => ['uvv', 'uvvv'],
|
|
||||||
'video/vnd.dvb.file' => 'dvb',
|
|
||||||
'video/vnd.fvt' => 'fvt',
|
|
||||||
'video/vnd.mpegurl' => ['mxu', 'm4u'],
|
|
||||||
'video/vnd.ms-playready.media.pyv' => 'pyv',
|
|
||||||
'video/vnd.uvvu.mp4' => ['uvu', 'uvvu'],
|
|
||||||
'video/vnd.vivo' => 'viv',
|
|
||||||
'video/webm' => 'webm',
|
|
||||||
'video/x-f4v' => 'f4v',
|
|
||||||
'video/x-fli' => 'fli',
|
|
||||||
'video/x-flv' => 'flv',
|
|
||||||
'video/x-m4v' => 'm4v',
|
|
||||||
'video/x-matroska' => ['mkv', 'mk3d', 'mks'],
|
|
||||||
'video/x-mng' => 'mng',
|
|
||||||
'video/x-ms-asf' => ['asf', 'asx'],
|
|
||||||
'video/x-ms-vob' => 'vob',
|
|
||||||
'video/x-ms-wm' => 'wm',
|
|
||||||
'video/x-ms-wmv' => 'wmv',
|
|
||||||
'video/x-ms-wmx' => 'wmx',
|
|
||||||
'video/x-ms-wvx' => 'wvx',
|
|
||||||
'video/x-msvideo' => 'avi',
|
|
||||||
'video/x-sgi-movie' => 'movie',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random MIME type
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'video/avi'
|
|
||||||
*/
|
|
||||||
public static function mimeType()
|
|
||||||
{
|
|
||||||
return static::randomElement(array_keys(static::$mimeTypes));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a random file extension (without a dot)
|
|
||||||
*
|
|
||||||
* @example avi
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function fileExtension()
|
|
||||||
{
|
|
||||||
$random_extension = static::randomElement(array_values(static::$mimeTypes));
|
|
||||||
|
|
||||||
return is_array($random_extension) ? static::randomElement($random_extension) : $random_extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy a random file from the source directory to the target directory and returns the filename/fullpath
|
|
||||||
*
|
|
||||||
* @param string $sourceDirectory The directory to look for random file taking
|
|
||||||
* @param string $targetDirectory
|
|
||||||
* @param bool $fullPath Whether to have the full path or just the filename
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function file($sourceDirectory = '/tmp', $targetDirectory = '/tmp', $fullPath = true)
|
|
||||||
{
|
|
||||||
if (!is_dir($sourceDirectory)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Source directory %s does not exist or is not a directory.', $sourceDirectory));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_dir($targetDirectory)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Target directory %s does not exist or is not a directory.', $targetDirectory));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sourceDirectory == $targetDirectory) {
|
|
||||||
throw new \InvalidArgumentException('Source and target directories must differ.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop . and .. and reset array keys
|
|
||||||
$files = array_filter(array_values(array_diff(scandir($sourceDirectory), ['.', '..'])), static function ($file) use ($sourceDirectory) {
|
|
||||||
return is_file($sourceDirectory . DIRECTORY_SEPARATOR . $file) && is_readable($sourceDirectory . DIRECTORY_SEPARATOR . $file);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (empty($files)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Source directory %s is empty.', $sourceDirectory));
|
|
||||||
}
|
|
||||||
|
|
||||||
$sourceFullPath = $sourceDirectory . DIRECTORY_SEPARATOR . static::randomElement($files);
|
|
||||||
|
|
||||||
$destinationFile = Uuid::uuid() . '.' . pathinfo($sourceFullPath, PATHINFO_EXTENSION);
|
|
||||||
$destinationFullPath = $targetDirectory . DIRECTORY_SEPARATOR . $destinationFile;
|
|
||||||
|
|
||||||
if (false === copy($sourceFullPath, $destinationFullPath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fullPath ? $destinationFullPath : $destinationFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,307 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
use Faker\Generator;
|
|
||||||
use Faker\UniqueGenerator;
|
|
||||||
|
|
||||||
class HtmlLorem extends Base
|
|
||||||
{
|
|
||||||
public const HTML_TAG = 'html';
|
|
||||||
public const HEAD_TAG = 'head';
|
|
||||||
public const BODY_TAG = 'body';
|
|
||||||
public const DIV_TAG = 'div';
|
|
||||||
public const P_TAG = 'p';
|
|
||||||
public const A_TAG = 'a';
|
|
||||||
public const SPAN_TAG = 'span';
|
|
||||||
public const TABLE_TAG = 'table';
|
|
||||||
public const THEAD_TAG = 'thead';
|
|
||||||
public const TBODY_TAG = 'tbody';
|
|
||||||
public const TR_TAG = 'tr';
|
|
||||||
public const TD_TAG = 'td';
|
|
||||||
public const TH_TAG = 'th';
|
|
||||||
public const UL_TAG = 'ul';
|
|
||||||
public const LI_TAG = 'li';
|
|
||||||
public const H_TAG = 'h';
|
|
||||||
public const B_TAG = 'b';
|
|
||||||
public const I_TAG = 'i';
|
|
||||||
public const TITLE_TAG = 'title';
|
|
||||||
public const FORM_TAG = 'form';
|
|
||||||
public const INPUT_TAG = 'input';
|
|
||||||
public const LABEL_TAG = 'label';
|
|
||||||
|
|
||||||
private $idGenerator;
|
|
||||||
|
|
||||||
public function __construct(Generator $generator)
|
|
||||||
{
|
|
||||||
parent::__construct($generator);
|
|
||||||
$generator->addProvider(new Lorem($generator));
|
|
||||||
$generator->addProvider(new Internet($generator));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $maxDepth
|
|
||||||
* @param int $maxWidth
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function randomHtml($maxDepth = 4, $maxWidth = 4)
|
|
||||||
{
|
|
||||||
if (!class_exists(\DOMDocument::class, false)) {
|
|
||||||
throw new \RuntimeException('ext-dom is required to use randomHtml.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$document = new \DOMDocument();
|
|
||||||
$this->idGenerator = new UniqueGenerator($this->generator);
|
|
||||||
|
|
||||||
$head = $document->createElement('head');
|
|
||||||
$this->addRandomTitle($head);
|
|
||||||
|
|
||||||
$body = $document->createElement('body');
|
|
||||||
$this->addLoginForm($body);
|
|
||||||
$this->addRandomSubTree($body, $maxDepth, $maxWidth);
|
|
||||||
|
|
||||||
$html = $document->createElement('html');
|
|
||||||
$html->appendChild($head);
|
|
||||||
$html->appendChild($body);
|
|
||||||
|
|
||||||
$document->appendChild($html);
|
|
||||||
|
|
||||||
return $document->saveHTML();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomSubTree(\DOMElement $root, $maxDepth, $maxWidth)
|
|
||||||
{
|
|
||||||
--$maxDepth;
|
|
||||||
|
|
||||||
if ($maxDepth <= 0) {
|
|
||||||
return $root;
|
|
||||||
}
|
|
||||||
|
|
||||||
$siblings = self::numberBetween(1, $maxWidth);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $siblings; ++$i) {
|
|
||||||
if ($maxDepth == 1) {
|
|
||||||
$this->addRandomLeaf($root);
|
|
||||||
} else {
|
|
||||||
$sibling = $root->ownerDocument->createElement('div');
|
|
||||||
$root->appendChild($sibling);
|
|
||||||
$this->addRandomAttribute($sibling);
|
|
||||||
$this->addRandomSubTree($sibling, self::numberBetween(0, $maxDepth), $maxWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $root;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomLeaf(\DOMElement $node): void
|
|
||||||
{
|
|
||||||
$rand = self::numberBetween(1, 10);
|
|
||||||
|
|
||||||
switch ($rand) {
|
|
||||||
case 1:
|
|
||||||
$this->addRandomP($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
$this->addRandomA($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
$this->addRandomSpan($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
$this->addRandomUL($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 5:
|
|
||||||
$this->addRandomH($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 6:
|
|
||||||
$this->addRandomB($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 7:
|
|
||||||
$this->addRandomI($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 8:
|
|
||||||
$this->addRandomTable($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$this->addRandomText($node);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomAttribute(\DOMElement $node): void
|
|
||||||
{
|
|
||||||
$rand = self::numberBetween(1, 2);
|
|
||||||
|
|
||||||
switch ($rand) {
|
|
||||||
case 1:
|
|
||||||
$node->setAttribute('class', $this->generator->word());
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
$node->setAttribute('id', (string) $this->idGenerator->randomNumber(5));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomP(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$node = $element->ownerDocument->createElement(static::P_TAG);
|
|
||||||
$node->textContent = $this->generator->sentence(self::numberBetween(1, $maxLength));
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomText(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$element->appendChild($text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomA(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$node = $element->ownerDocument->createElement(static::A_TAG);
|
|
||||||
$node->setAttribute('href', $this->generator->safeEmailDomain());
|
|
||||||
$node->appendChild($text);
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomTitle(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$node = $element->ownerDocument->createElement(static::TITLE_TAG);
|
|
||||||
$node->appendChild($text);
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomH(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$h = static::H_TAG . (string) self::numberBetween(1, 3);
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$node = $element->ownerDocument->createElement($h);
|
|
||||||
$node->appendChild($text);
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomB(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$node = $element->ownerDocument->createElement(static::B_TAG);
|
|
||||||
$node->appendChild($text);
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomI(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$node = $element->ownerDocument->createElement(static::I_TAG);
|
|
||||||
$node->appendChild($text);
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomSpan(\DOMElement $element, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$text = $element->ownerDocument->createTextNode($this->generator->sentence(self::numberBetween(1, $maxLength)));
|
|
||||||
$node = $element->ownerDocument->createElement(static::SPAN_TAG);
|
|
||||||
$node->appendChild($text);
|
|
||||||
$element->appendChild($node);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addLoginForm(\DOMElement $element): void
|
|
||||||
{
|
|
||||||
$textInput = $element->ownerDocument->createElement(static::INPUT_TAG);
|
|
||||||
$textInput->setAttribute('type', 'text');
|
|
||||||
$textInput->setAttribute('id', 'username');
|
|
||||||
|
|
||||||
$textLabel = $element->ownerDocument->createElement(static::LABEL_TAG);
|
|
||||||
$textLabel->setAttribute('for', 'username');
|
|
||||||
$textLabel->textContent = $this->generator->word();
|
|
||||||
|
|
||||||
$passwordInput = $element->ownerDocument->createElement(static::INPUT_TAG);
|
|
||||||
$passwordInput->setAttribute('type', 'password');
|
|
||||||
$passwordInput->setAttribute('id', 'password');
|
|
||||||
|
|
||||||
$passwordLabel = $element->ownerDocument->createElement(static::LABEL_TAG);
|
|
||||||
$passwordLabel->setAttribute('for', 'password');
|
|
||||||
$passwordLabel->textContent = $this->generator->word();
|
|
||||||
|
|
||||||
$submit = $element->ownerDocument->createElement(static::INPUT_TAG);
|
|
||||||
$submit->setAttribute('type', 'submit');
|
|
||||||
$submit->setAttribute('value', $this->generator->word());
|
|
||||||
|
|
||||||
$submit = $element->ownerDocument->createElement(static::FORM_TAG);
|
|
||||||
$submit->setAttribute('action', $this->generator->safeEmailDomain());
|
|
||||||
$submit->setAttribute('method', 'POST');
|
|
||||||
$submit->appendChild($textLabel);
|
|
||||||
$submit->appendChild($textInput);
|
|
||||||
$submit->appendChild($passwordLabel);
|
|
||||||
$submit->appendChild($passwordInput);
|
|
||||||
$element->appendChild($submit);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomTable(\DOMElement $element, $maxRows = 10, $maxCols = 6, $maxTitle = 4, $maxLength = 10): void
|
|
||||||
{
|
|
||||||
$rows = self::numberBetween(1, $maxRows);
|
|
||||||
$cols = self::numberBetween(1, $maxCols);
|
|
||||||
|
|
||||||
$table = $element->ownerDocument->createElement(static::TABLE_TAG);
|
|
||||||
$thead = $element->ownerDocument->createElement(static::THEAD_TAG);
|
|
||||||
$tbody = $element->ownerDocument->createElement(static::TBODY_TAG);
|
|
||||||
|
|
||||||
$table->appendChild($thead);
|
|
||||||
$table->appendChild($tbody);
|
|
||||||
|
|
||||||
$tr = $element->ownerDocument->createElement(static::TR_TAG);
|
|
||||||
$thead->appendChild($tr);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $cols; ++$i) {
|
|
||||||
$th = $element->ownerDocument->createElement(static::TH_TAG);
|
|
||||||
$th->textContent = $this->generator->sentence(self::numberBetween(1, $maxTitle));
|
|
||||||
$tr->appendChild($th);
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 0; $i < $rows; ++$i) {
|
|
||||||
$tr = $element->ownerDocument->createElement(static::TR_TAG);
|
|
||||||
$tbody->appendChild($tr);
|
|
||||||
|
|
||||||
for ($j = 0; $j < $cols; ++$j) {
|
|
||||||
$th = $element->ownerDocument->createElement(static::TD_TAG);
|
|
||||||
$th->textContent = $this->generator->sentence(self::numberBetween(1, $maxLength));
|
|
||||||
$tr->appendChild($th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$element->appendChild($table);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addRandomUL(\DOMElement $element, $maxItems = 11, $maxLength = 4): void
|
|
||||||
{
|
|
||||||
$num = self::numberBetween(1, $maxItems);
|
|
||||||
$ul = $element->ownerDocument->createElement(static::UL_TAG);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $num; ++$i) {
|
|
||||||
$li = $element->ownerDocument->createElement(static::LI_TAG);
|
|
||||||
$li->textContent = $this->generator->sentence(self::numberBetween(1, $maxLength));
|
|
||||||
$ul->appendChild($li);
|
|
||||||
}
|
|
||||||
$element->appendChild($ul);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-196
@@ -1,196 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Depends on image generation from http://lorempixel.com/
|
|
||||||
*/
|
|
||||||
class Image extends Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public const BASE_URL = 'https://via.placeholder.com';
|
|
||||||
|
|
||||||
public const FORMAT_JPG = 'jpg';
|
|
||||||
public const FORMAT_JPEG = 'jpeg';
|
|
||||||
public const FORMAT_PNG = 'png';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* @deprecated Categories are no longer used as a list in the placeholder API but referenced as string instead
|
|
||||||
*/
|
|
||||||
protected static $categories = [
|
|
||||||
'abstract', 'animals', 'business', 'cats', 'city', 'food', 'nightlife',
|
|
||||||
'fashion', 'people', 'nature', 'sports', 'technics', 'transport',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the URL that will return a random image
|
|
||||||
*
|
|
||||||
* Set randomize to false to remove the random GET parameter at the end of the url.
|
|
||||||
*
|
|
||||||
* @example 'http://via.placeholder.com/640x480.png/CCCCCC?text=well+hi+there'
|
|
||||||
*
|
|
||||||
* @param int $width
|
|
||||||
* @param int $height
|
|
||||||
* @param string|null $category
|
|
||||||
* @param bool $randomize
|
|
||||||
* @param string|null $word
|
|
||||||
* @param bool $gray
|
|
||||||
* @param string $format
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function imageUrl(
|
|
||||||
$width = 640,
|
|
||||||
$height = 480,
|
|
||||||
$category = null,
|
|
||||||
$randomize = true,
|
|
||||||
$word = null,
|
|
||||||
$gray = false,
|
|
||||||
$format = 'png'
|
|
||||||
) {
|
|
||||||
trigger_deprecation(
|
|
||||||
'fakerphp/faker',
|
|
||||||
'1.20',
|
|
||||||
'Provider is deprecated and will no longer be available in Faker 2. Please use a custom provider instead',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Validate image format
|
|
||||||
$imageFormats = static::getFormats();
|
|
||||||
|
|
||||||
if (!in_array(strtolower($format), $imageFormats, true)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
|
||||||
'Invalid image format "%s". Allowable formats are: %s',
|
|
||||||
$format,
|
|
||||||
implode(', ', $imageFormats),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$size = sprintf('%dx%d.%s', $width, $height, $format);
|
|
||||||
|
|
||||||
$imageParts = [];
|
|
||||||
|
|
||||||
if ($category !== null) {
|
|
||||||
$imageParts[] = $category;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($word !== null) {
|
|
||||||
$imageParts[] = $word;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($randomize === true) {
|
|
||||||
$imageParts[] = Lorem::word();
|
|
||||||
}
|
|
||||||
|
|
||||||
$backgroundColor = $gray === true ? 'CCCCCC' : str_replace('#', '', Color::safeHexColor());
|
|
||||||
|
|
||||||
return sprintf(
|
|
||||||
'%s/%s/%s%s',
|
|
||||||
self::BASE_URL,
|
|
||||||
$size,
|
|
||||||
$backgroundColor,
|
|
||||||
count($imageParts) > 0 ? '?text=' . urlencode(implode(' ', $imageParts)) : '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download a remote random image to disk and return its location
|
|
||||||
*
|
|
||||||
* Requires curl, or allow_url_fopen to be on in php.ini.
|
|
||||||
*
|
|
||||||
* @example '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.png'
|
|
||||||
*
|
|
||||||
* @return bool|string
|
|
||||||
*/
|
|
||||||
public static function image(
|
|
||||||
$dir = null,
|
|
||||||
$width = 640,
|
|
||||||
$height = 480,
|
|
||||||
$category = null,
|
|
||||||
$fullPath = true,
|
|
||||||
$randomize = true,
|
|
||||||
$word = null,
|
|
||||||
$gray = false,
|
|
||||||
$format = 'png'
|
|
||||||
) {
|
|
||||||
trigger_deprecation(
|
|
||||||
'fakerphp/faker',
|
|
||||||
'1.20',
|
|
||||||
'Provider is deprecated and will no longer be available in Faker 2. Please use a custom provider instead',
|
|
||||||
);
|
|
||||||
|
|
||||||
$dir = null === $dir ? sys_get_temp_dir() : $dir; // GNU/Linux / OS X / Windows compatible
|
|
||||||
|
|
||||||
// Validate directory path
|
|
||||||
if (!is_dir($dir) || !is_writable($dir)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Cannot write to directory "%s"', $dir));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a random filename. Use the server address so that a file
|
|
||||||
// generated at the same time on a different server won't have a collision.
|
|
||||||
$name = md5(uniqid(empty($_SERVER['SERVER_ADDR']) ? '' : $_SERVER['SERVER_ADDR'], true));
|
|
||||||
$filename = sprintf('%s.%s', $name, $format);
|
|
||||||
$filepath = $dir . DIRECTORY_SEPARATOR . $filename;
|
|
||||||
|
|
||||||
$url = static::imageUrl($width, $height, $category, $randomize, $word, $gray, $format);
|
|
||||||
|
|
||||||
// save file
|
|
||||||
if (function_exists('curl_exec')) {
|
|
||||||
// use cURL
|
|
||||||
$fp = fopen($filepath, 'w');
|
|
||||||
$ch = curl_init($url);
|
|
||||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
|
||||||
$success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;
|
|
||||||
fclose($fp);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
if (!$success) {
|
|
||||||
unlink($filepath);
|
|
||||||
|
|
||||||
// could not contact the distant URL or HTTP error - fail silently.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} elseif (ini_get('allow_url_fopen')) {
|
|
||||||
// use remote fopen() via copy()
|
|
||||||
$success = copy($url, $filepath);
|
|
||||||
|
|
||||||
if (!$success) {
|
|
||||||
// could not contact the distant URL or HTTP error - fail silently.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return new \RuntimeException('The image formatter downloads an image from a remote HTTP server. Therefore, it requires that PHP can request remote hosts, either via cURL or fopen()');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fullPath ? $filepath : $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getFormats(): array
|
|
||||||
{
|
|
||||||
trigger_deprecation(
|
|
||||||
'fakerphp/faker',
|
|
||||||
'1.20',
|
|
||||||
'Provider is deprecated and will no longer be available in Faker 2. Please use a custom provider instead',
|
|
||||||
);
|
|
||||||
|
|
||||||
return array_keys(static::getFormatConstants());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getFormatConstants(): array
|
|
||||||
{
|
|
||||||
trigger_deprecation(
|
|
||||||
'fakerphp/faker',
|
|
||||||
'1.20',
|
|
||||||
'Provider is deprecated and will no longer be available in Faker 2. Please use a custom provider instead',
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
|
||||||
static::FORMAT_JPG => constant('IMAGETYPE_JPEG'),
|
|
||||||
static::FORMAT_JPEG => constant('IMAGETYPE_JPEG'),
|
|
||||||
static::FORMAT_PNG => constant('IMAGETYPE_PNG'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,407 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Internet extends Base
|
|
||||||
{
|
|
||||||
protected static $freeEmailDomain = ['gmail.com', 'yahoo.com', 'hotmail.com'];
|
|
||||||
protected static $tld = ['com', 'com', 'com', 'com', 'com', 'com', 'biz', 'info', 'net', 'org'];
|
|
||||||
|
|
||||||
protected static $userNameFormats = [
|
|
||||||
'{{lastName}}.{{firstName}}',
|
|
||||||
'{{firstName}}.{{lastName}}',
|
|
||||||
'{{firstName}}##',
|
|
||||||
'?{{lastName}}',
|
|
||||||
];
|
|
||||||
protected static $emailFormats = [
|
|
||||||
'{{userName}}@{{domainName}}',
|
|
||||||
'{{userName}}@{{freeEmailDomain}}',
|
|
||||||
];
|
|
||||||
protected static $urlFormats = [
|
|
||||||
'http://www.{{domainName}}/',
|
|
||||||
'http://{{domainName}}/',
|
|
||||||
'http://www.{{domainName}}/{{slug}}',
|
|
||||||
'http://www.{{domainName}}/{{slug}}',
|
|
||||||
'https://www.{{domainName}}/{{slug}}',
|
|
||||||
'http://www.{{domainName}}/{{slug}}.html',
|
|
||||||
'http://{{domainName}}/{{slug}}',
|
|
||||||
'http://{{domainName}}/{{slug}}',
|
|
||||||
'http://{{domainName}}/{{slug}}.html',
|
|
||||||
'https://{{domainName}}/{{slug}}.html',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://tools.ietf.org/html/rfc1918#section-3
|
|
||||||
*/
|
|
||||||
protected static $localIpBlocks = [
|
|
||||||
['10.0.0.0', '10.255.255.255'],
|
|
||||||
['172.16.0.0', '172.31.255.255'],
|
|
||||||
['192.168.0.0', '192.168.255.255'],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'jdoe@acme.biz'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function email()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$emailFormats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'jdoe@example.com'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
final public function safeEmail()
|
|
||||||
{
|
|
||||||
return preg_replace('/\s/u', '', $this->userName() . '@' . static::safeEmailDomain());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'jdoe@gmail.com'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function freeEmail()
|
|
||||||
{
|
|
||||||
return preg_replace('/\s/u', '', $this->userName() . '@' . static::freeEmailDomain());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'jdoe@dawson.com'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function companyEmail()
|
|
||||||
{
|
|
||||||
return preg_replace('/\s/u', '', $this->userName() . '@' . $this->domainName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'gmail.com'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function freeEmailDomain()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$freeEmailDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'example.org'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
final public static function safeEmailDomain()
|
|
||||||
{
|
|
||||||
$domains = [
|
|
||||||
'example.com',
|
|
||||||
'example.org',
|
|
||||||
'example.net',
|
|
||||||
];
|
|
||||||
|
|
||||||
return static::randomElement($domains);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'jdoe'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function userName()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$userNameFormats);
|
|
||||||
$username = static::bothify($this->generator->parse($format));
|
|
||||||
|
|
||||||
$username = strtolower(static::transliterate($username));
|
|
||||||
|
|
||||||
// check if transliterate() didn't support the language and removed all letters
|
|
||||||
if (trim($username, '._') === '') {
|
|
||||||
throw new \Exception('userName failed with the selected locale. Try a different locale or activate the "intl" PHP extension.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean possible trailing dots from first/last names
|
|
||||||
$username = str_replace('..', '.', $username);
|
|
||||||
$username = rtrim($username, '.');
|
|
||||||
|
|
||||||
return $username;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'fY4èHdZv68'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function password($minLength = 6, $maxLength = 20)
|
|
||||||
{
|
|
||||||
$pattern = str_repeat('*', $this->numberBetween($minLength, $maxLength));
|
|
||||||
|
|
||||||
return $this->asciify($pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'tiramisu.com'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function domainName()
|
|
||||||
{
|
|
||||||
return $this->domainWord() . '.' . $this->tld();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'faber'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function domainWord()
|
|
||||||
{
|
|
||||||
$lastName = $this->generator->format('lastName');
|
|
||||||
|
|
||||||
$lastName = strtolower(static::transliterate($lastName));
|
|
||||||
|
|
||||||
// check if transliterate() didn't support the language and removed all letters
|
|
||||||
if (trim($lastName, '._') === '') {
|
|
||||||
throw new \Exception('domainWord failed with the selected locale. Try a different locale or activate the "intl" PHP extension.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean possible trailing dot from last name
|
|
||||||
$lastName = rtrim($lastName, '.');
|
|
||||||
|
|
||||||
return $lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'com'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function tld()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$tld);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'http://www.runolfsdottir.com/'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function url()
|
|
||||||
{
|
|
||||||
$format = static::randomElement(static::$urlFormats);
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function slug($nbWords = 6, $variableNbWords = true)
|
|
||||||
{
|
|
||||||
if ($nbWords <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($variableNbWords) {
|
|
||||||
$nbWords = (int) ($nbWords * self::numberBetween(60, 140) / 100) + 1;
|
|
||||||
}
|
|
||||||
$words = $this->generator->words($nbWords);
|
|
||||||
|
|
||||||
return implode('-', $words);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '237.149.115.38'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function ipv4()
|
|
||||||
{
|
|
||||||
return long2ip(Miscellaneous::boolean() ? self::numberBetween(-2147483648, -2) : self::numberBetween(16777216, 2147483647));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function ipv6()
|
|
||||||
{
|
|
||||||
$res = [];
|
|
||||||
|
|
||||||
for ($i = 0; $i < 8; ++$i) {
|
|
||||||
$res[] = dechex(self::numberBetween(0, 65535));
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode(':', $res);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '10.1.1.17'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function localIpv4()
|
|
||||||
{
|
|
||||||
$ipBlock = self::randomElement(static::$localIpBlocks);
|
|
||||||
|
|
||||||
return long2ip(static::numberBetween(ip2long($ipBlock[0]), ip2long($ipBlock[1])));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '32:F1:39:2F:D6:18'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function macAddress()
|
|
||||||
{
|
|
||||||
$mac = [];
|
|
||||||
|
|
||||||
for ($i = 0; $i < 6; ++$i) {
|
|
||||||
$mac[] = sprintf('%02X', self::numberBetween(0, 0xff));
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode(':', $mac);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function transliterate($string)
|
|
||||||
{
|
|
||||||
if (0 === preg_match('/[^A-Za-z0-9_.]/', $string)) {
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
$transId = 'Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC;';
|
|
||||||
|
|
||||||
if (class_exists(\Transliterator::class, false) && $transliterator = \Transliterator::create($transId)) {
|
|
||||||
$transString = $transliterator->transliterate($string);
|
|
||||||
} else {
|
|
||||||
$transString = static::toAscii($string);
|
|
||||||
}
|
|
||||||
|
|
||||||
return preg_replace('/[^A-Za-z0-9_.]/u', '', $transString);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function toAscii($string)
|
|
||||||
{
|
|
||||||
static $arrayFrom, $arrayTo;
|
|
||||||
|
|
||||||
if (empty($arrayFrom)) {
|
|
||||||
$transliterationTable = [
|
|
||||||
'IJ' => 'I', 'Ö' => 'O', 'Œ' => 'O', 'Ü' => 'U', 'ä' => 'a', 'æ' => 'a',
|
|
||||||
'ij' => 'i', 'ö' => 'o', 'œ' => 'o', 'ü' => 'u', 'ß' => 's', 'ſ' => 's',
|
|
||||||
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A',
|
|
||||||
'Æ' => 'A', 'Ā' => 'A', 'Ą' => 'A', 'Ă' => 'A', 'Ç' => 'C', 'Ć' => 'C',
|
|
||||||
'Č' => 'C', 'Ĉ' => 'C', 'Ċ' => 'C', 'Ď' => 'D', 'Đ' => 'D', 'È' => 'E',
|
|
||||||
'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ē' => 'E', 'Ę' => 'E', 'Ě' => 'E',
|
|
||||||
'Ĕ' => 'E', 'Ė' => 'E', 'Ĝ' => 'G', 'Ğ' => 'G', 'Ġ' => 'G', 'Ģ' => 'G',
|
|
||||||
'Ĥ' => 'H', 'Ħ' => 'H', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I',
|
|
||||||
'Ī' => 'I', 'Ĩ' => 'I', 'Ĭ' => 'I', 'Į' => 'I', 'İ' => 'I', 'Ĵ' => 'J',
|
|
||||||
'Ķ' => 'K', 'Ľ' => 'K', 'Ĺ' => 'K', 'Ļ' => 'K', 'Ŀ' => 'K', 'Ł' => 'L',
|
|
||||||
'Ñ' => 'N', 'Ń' => 'N', 'Ň' => 'N', 'Ņ' => 'N', 'Ŋ' => 'N', 'Ò' => 'O',
|
|
||||||
'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Ō' => 'O', 'Ő' => 'O',
|
|
||||||
'Ŏ' => 'O', 'Ŕ' => 'R', 'Ř' => 'R', 'Ŗ' => 'R', 'Ś' => 'S', 'Ş' => 'S',
|
|
||||||
'Ŝ' => 'S', 'Ș' => 'S', 'Š' => 'S', 'Ť' => 'T', 'Ţ' => 'T', 'Ŧ' => 'T',
|
|
||||||
'Ț' => 'T', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ū' => 'U', 'Ů' => 'U',
|
|
||||||
'Ű' => 'U', 'Ŭ' => 'U', 'Ũ' => 'U', 'Ų' => 'U', 'Ŵ' => 'W', 'Ŷ' => 'Y',
|
|
||||||
'Ÿ' => 'Y', 'Ý' => 'Y', 'Ź' => 'Z', 'Ż' => 'Z', 'Ž' => 'Z', 'à' => 'a',
|
|
||||||
'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ā' => 'a', 'ą' => 'a', 'ă' => 'a',
|
|
||||||
'å' => 'a', 'ç' => 'c', 'ć' => 'c', 'č' => 'c', 'ĉ' => 'c', 'ċ' => 'c',
|
|
||||||
'ď' => 'd', 'đ' => 'd', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e',
|
|
||||||
'ē' => 'e', 'ę' => 'e', 'ě' => 'e', 'ĕ' => 'e', 'ė' => 'e', 'ƒ' => 'f',
|
|
||||||
'ĝ' => 'g', 'ğ' => 'g', 'ġ' => 'g', 'ģ' => 'g', 'ĥ' => 'h', 'ħ' => 'h',
|
|
||||||
'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ī' => 'i', 'ĩ' => 'i',
|
|
||||||
'ĭ' => 'i', 'į' => 'i', 'ı' => 'i', 'ĵ' => 'j', 'ķ' => 'k', 'ĸ' => 'k',
|
|
||||||
'ł' => 'l', 'ľ' => 'l', 'ĺ' => 'l', 'ļ' => 'l', 'ŀ' => 'l', 'ñ' => 'n',
|
|
||||||
'ń' => 'n', 'ň' => 'n', 'ņ' => 'n', 'ʼn' => 'n', 'ŋ' => 'n', 'ò' => 'o',
|
|
||||||
'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ø' => 'o', 'ō' => 'o', 'ő' => 'o',
|
|
||||||
'ŏ' => 'o', 'ŕ' => 'r', 'ř' => 'r', 'ŗ' => 'r', 'ś' => 's', 'š' => 's',
|
|
||||||
'ť' => 't', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ū' => 'u', 'ů' => 'u',
|
|
||||||
'ű' => 'u', 'ŭ' => 'u', 'ũ' => 'u', 'ų' => 'u', 'ŵ' => 'w', 'ÿ' => 'y',
|
|
||||||
'ý' => 'y', 'ŷ' => 'y', 'ż' => 'z', 'ź' => 'z', 'ž' => 'z', 'Α' => 'A',
|
|
||||||
'Ά' => 'A', 'Ἀ' => 'A', 'Ἁ' => 'A', 'Ἂ' => 'A', 'Ἃ' => 'A', 'Ἄ' => 'A',
|
|
||||||
'Ἅ' => 'A', 'Ἆ' => 'A', 'Ἇ' => 'A', 'ᾈ' => 'A', 'ᾉ' => 'A', 'ᾊ' => 'A',
|
|
||||||
'ᾋ' => 'A', 'ᾌ' => 'A', 'ᾍ' => 'A', 'ᾎ' => 'A', 'ᾏ' => 'A', 'Ᾰ' => 'A',
|
|
||||||
'Ᾱ' => 'A', 'Ὰ' => 'A', 'ᾼ' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D',
|
|
||||||
'Ε' => 'E', 'Έ' => 'E', 'Ἐ' => 'E', 'Ἑ' => 'E', 'Ἒ' => 'E', 'Ἓ' => 'E',
|
|
||||||
'Ἔ' => 'E', 'Ἕ' => 'E', 'Ὲ' => 'E', 'Ζ' => 'Z', 'Η' => 'I', 'Ή' => 'I',
|
|
||||||
'Ἠ' => 'I', 'Ἡ' => 'I', 'Ἢ' => 'I', 'Ἣ' => 'I', 'Ἤ' => 'I', 'Ἥ' => 'I',
|
|
||||||
'Ἦ' => 'I', 'Ἧ' => 'I', 'ᾘ' => 'I', 'ᾙ' => 'I', 'ᾚ' => 'I', 'ᾛ' => 'I',
|
|
||||||
'ᾜ' => 'I', 'ᾝ' => 'I', 'ᾞ' => 'I', 'ᾟ' => 'I', 'Ὴ' => 'I', 'ῌ' => 'I',
|
|
||||||
'Θ' => 'T', 'Ι' => 'I', 'Ί' => 'I', 'Ϊ' => 'I', 'Ἰ' => 'I', 'Ἱ' => 'I',
|
|
||||||
'Ἲ' => 'I', 'Ἳ' => 'I', 'Ἴ' => 'I', 'Ἵ' => 'I', 'Ἶ' => 'I', 'Ἷ' => 'I',
|
|
||||||
'Ῐ' => 'I', 'Ῑ' => 'I', 'Ὶ' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M',
|
|
||||||
'Ν' => 'N', 'Ξ' => 'K', 'Ο' => 'O', 'Ό' => 'O', 'Ὀ' => 'O', 'Ὁ' => 'O',
|
|
||||||
'Ὂ' => 'O', 'Ὃ' => 'O', 'Ὄ' => 'O', 'Ὅ' => 'O', 'Ὸ' => 'O', 'Π' => 'P',
|
|
||||||
'Ρ' => 'R', 'Ῥ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Ύ' => 'Y',
|
|
||||||
'Ϋ' => 'Y', 'Ὑ' => 'Y', 'Ὓ' => 'Y', 'Ὕ' => 'Y', 'Ὗ' => 'Y', 'Ῠ' => 'Y',
|
|
||||||
'Ῡ' => 'Y', 'Ὺ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'P', 'Ω' => 'O',
|
|
||||||
'Ώ' => 'O', 'Ὠ' => 'O', 'Ὡ' => 'O', 'Ὢ' => 'O', 'Ὣ' => 'O', 'Ὤ' => 'O',
|
|
||||||
'Ὥ' => 'O', 'Ὦ' => 'O', 'Ὧ' => 'O', 'ᾨ' => 'O', 'ᾩ' => 'O', 'ᾪ' => 'O',
|
|
||||||
'ᾫ' => 'O', 'ᾬ' => 'O', 'ᾭ' => 'O', 'ᾮ' => 'O', 'ᾯ' => 'O', 'Ὼ' => 'O',
|
|
||||||
'ῼ' => 'O', 'α' => 'a', 'ά' => 'a', 'ἀ' => 'a', 'ἁ' => 'a', 'ἂ' => 'a',
|
|
||||||
'ἃ' => 'a', 'ἄ' => 'a', 'ἅ' => 'a', 'ἆ' => 'a', 'ἇ' => 'a', 'ᾀ' => 'a',
|
|
||||||
'ᾁ' => 'a', 'ᾂ' => 'a', 'ᾃ' => 'a', 'ᾄ' => 'a', 'ᾅ' => 'a', 'ᾆ' => 'a',
|
|
||||||
'ᾇ' => 'a', 'ὰ' => 'a', 'ᾰ' => 'a', 'ᾱ' => 'a', 'ᾲ' => 'a', 'ᾳ' => 'a',
|
|
||||||
'ᾴ' => 'a', 'ᾶ' => 'a', 'ᾷ' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd',
|
|
||||||
'ε' => 'e', 'έ' => 'e', 'ἐ' => 'e', 'ἑ' => 'e', 'ἒ' => 'e', 'ἓ' => 'e',
|
|
||||||
'ἔ' => 'e', 'ἕ' => 'e', 'ὲ' => 'e', 'ζ' => 'z', 'η' => 'i', 'ή' => 'i',
|
|
||||||
'ἠ' => 'i', 'ἡ' => 'i', 'ἢ' => 'i', 'ἣ' => 'i', 'ἤ' => 'i', 'ἥ' => 'i',
|
|
||||||
'ἦ' => 'i', 'ἧ' => 'i', 'ᾐ' => 'i', 'ᾑ' => 'i', 'ᾒ' => 'i', 'ᾓ' => 'i',
|
|
||||||
'ᾔ' => 'i', 'ᾕ' => 'i', 'ᾖ' => 'i', 'ᾗ' => 'i', 'ὴ' => 'i', 'ῂ' => 'i',
|
|
||||||
'ῃ' => 'i', 'ῄ' => 'i', 'ῆ' => 'i', 'ῇ' => 'i', 'θ' => 't', 'ι' => 'i',
|
|
||||||
'ί' => 'i', 'ϊ' => 'i', 'ΐ' => 'i', 'ἰ' => 'i', 'ἱ' => 'i', 'ἲ' => 'i',
|
|
||||||
'ἳ' => 'i', 'ἴ' => 'i', 'ἵ' => 'i', 'ἶ' => 'i', 'ἷ' => 'i', 'ὶ' => 'i',
|
|
||||||
'ῐ' => 'i', 'ῑ' => 'i', 'ῒ' => 'i', 'ῖ' => 'i', 'ῗ' => 'i', 'κ' => 'k',
|
|
||||||
'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => 'k', 'ο' => 'o', 'ό' => 'o',
|
|
||||||
'ὀ' => 'o', 'ὁ' => 'o', 'ὂ' => 'o', 'ὃ' => 'o', 'ὄ' => 'o', 'ὅ' => 'o',
|
|
||||||
'ὸ' => 'o', 'π' => 'p', 'ρ' => 'r', 'ῤ' => 'r', 'ῥ' => 'r', 'σ' => 's',
|
|
||||||
'ς' => 's', 'τ' => 't', 'υ' => 'y', 'ύ' => 'y', 'ϋ' => 'y', 'ΰ' => 'y',
|
|
||||||
'ὐ' => 'y', 'ὑ' => 'y', 'ὒ' => 'y', 'ὓ' => 'y', 'ὔ' => 'y', 'ὕ' => 'y',
|
|
||||||
'ὖ' => 'y', 'ὗ' => 'y', 'ὺ' => 'y', 'ῠ' => 'y', 'ῡ' => 'y', 'ῢ' => 'y',
|
|
||||||
'ῦ' => 'y', 'ῧ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'p', 'ω' => 'o',
|
|
||||||
'ώ' => 'o', 'ὠ' => 'o', 'ὡ' => 'o', 'ὢ' => 'o', 'ὣ' => 'o', 'ὤ' => 'o',
|
|
||||||
'ὥ' => 'o', 'ὦ' => 'o', 'ὧ' => 'o', 'ᾠ' => 'o', 'ᾡ' => 'o', 'ᾢ' => 'o',
|
|
||||||
'ᾣ' => 'o', 'ᾤ' => 'o', 'ᾥ' => 'o', 'ᾦ' => 'o', 'ᾧ' => 'o', 'ὼ' => 'o',
|
|
||||||
'ῲ' => 'o', 'ῳ' => 'o', 'ῴ' => 'o', 'ῶ' => 'o', 'ῷ' => 'o', 'А' => 'A',
|
|
||||||
'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E',
|
|
||||||
'Ж' => 'Z', 'З' => 'Z', 'И' => 'I', 'Й' => 'I', 'К' => 'K', 'Л' => 'L',
|
|
||||||
'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S',
|
|
||||||
'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'K', 'Ц' => 'T', 'Ч' => 'C',
|
|
||||||
'Ш' => 'S', 'Щ' => 'S', 'Ы' => 'Y', 'Э' => 'E', 'Ю' => 'Y', 'Я' => 'Y',
|
|
||||||
'а' => 'A', 'б' => 'B', 'в' => 'V', 'г' => 'G', 'д' => 'D', 'е' => 'E',
|
|
||||||
'ё' => 'E', 'ж' => 'Z', 'з' => 'Z', 'и' => 'I', 'й' => 'I', 'к' => 'K',
|
|
||||||
'л' => 'L', 'м' => 'M', 'н' => 'N', 'о' => 'O', 'п' => 'P', 'р' => 'R',
|
|
||||||
'с' => 'S', 'т' => 'T', 'у' => 'U', 'ф' => 'F', 'х' => 'K', 'ц' => 'T',
|
|
||||||
'ч' => 'C', 'ш' => 'S', 'щ' => 'S', 'ы' => 'Y', 'э' => 'E', 'ю' => 'Y',
|
|
||||||
'я' => 'Y', 'ð' => 'd', 'Ð' => 'D', 'þ' => 't', 'Þ' => 'T', 'ა' => 'a',
|
|
||||||
'ბ' => 'b', 'გ' => 'g', 'დ' => 'd', 'ე' => 'e', 'ვ' => 'v', 'ზ' => 'z',
|
|
||||||
'თ' => 't', 'ი' => 'i', 'კ' => 'k', 'ლ' => 'l', 'მ' => 'm', 'ნ' => 'n',
|
|
||||||
'ო' => 'o', 'პ' => 'p', 'ჟ' => 'z', 'რ' => 'r', 'ს' => 's', 'ტ' => 't',
|
|
||||||
'უ' => 'u', 'ფ' => 'p', 'ქ' => 'k', 'ღ' => 'g', 'ყ' => 'q', 'შ' => 's',
|
|
||||||
'ჩ' => 'c', 'ც' => 't', 'ძ' => 'd', 'წ' => 't', 'ჭ' => 'c', 'ხ' => 'k',
|
|
||||||
'ჯ' => 'j', 'ჰ' => 'h', 'ţ' => 't', 'ʼ' => "'", '̧' => '', 'ḩ' => 'h',
|
|
||||||
'‘' => "'", '’' => "'", 'ừ' => 'u', '/' => '', 'ế' => 'e', 'ả' => 'a',
|
|
||||||
'ị' => 'i', 'ậ' => 'a', 'ệ' => 'e', 'ỉ' => 'i', 'ồ' => 'o', 'ề' => 'e',
|
|
||||||
'ơ' => 'o', 'ạ' => 'a', 'ẵ' => 'a', 'ư' => 'u', 'ằ' => 'a', 'ầ' => 'a',
|
|
||||||
'ḑ' => 'd', 'Ḩ' => 'H', 'Ḑ' => 'D', 'ș' => 's', 'ț' => 't', 'ộ' => 'o',
|
|
||||||
'ắ' => 'a', 'ş' => 's', "'" => '', 'ու' => 'u', 'ա' => 'a', 'բ' => 'b',
|
|
||||||
'գ' => 'g', 'դ' => 'd', 'ե' => 'e', 'զ' => 'z', 'է' => 'e', 'ը' => 'y',
|
|
||||||
'թ' => 't', 'ժ' => 'zh', 'ի' => 'i', 'լ' => 'l', 'խ' => 'kh', 'ծ' => 'ts',
|
|
||||||
'կ' => 'k', 'հ' => 'h', 'ձ' => 'dz', 'ղ' => 'gh', 'ճ' => 'ch', 'մ' => 'm',
|
|
||||||
'յ' => 'y', 'ն' => 'n', 'շ' => 'sh', 'ո' => 'o', 'չ' => 'ch', 'պ' => 'p',
|
|
||||||
'ջ' => 'j', 'ռ' => 'r', 'ս' => 's', 'վ' => 'v', 'տ' => 't', 'ր' => 'r',
|
|
||||||
'ց' => 'ts', 'փ' => 'p', 'ք' => 'q', 'և' => 'ev', 'օ' => 'o', 'ֆ' => 'f',
|
|
||||||
];
|
|
||||||
$arrayFrom = array_keys($transliterationTable);
|
|
||||||
$arrayTo = array_values($transliterationTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return str_replace($arrayFrom, $arrayTo, $string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-228
@@ -1,228 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Lorem extends Base
|
|
||||||
{
|
|
||||||
protected static $wordList = [
|
|
||||||
'alias', 'consequatur', 'aut', 'perferendis', 'sit', 'voluptatem',
|
|
||||||
'accusantium', 'doloremque', 'aperiam', 'eaque', 'ipsa', 'quae', 'ab',
|
|
||||||
'illo', 'inventore', 'veritatis', 'et', 'quasi', 'architecto',
|
|
||||||
'beatae', 'vitae', 'dicta', 'sunt', 'explicabo', 'aspernatur', 'aut',
|
|
||||||
'odit', 'aut', 'fugit', 'sed', 'quia', 'consequuntur', 'magni',
|
|
||||||
'dolores', 'eos', 'qui', 'ratione', 'voluptatem', 'sequi', 'nesciunt',
|
|
||||||
'neque', 'dolorem', 'ipsum', 'quia', 'dolor', 'sit', 'amet',
|
|
||||||
'consectetur', 'adipisci', 'velit', 'sed', 'quia', 'non', 'numquam',
|
|
||||||
'eius', 'modi', 'tempora', 'incidunt', 'ut', 'labore', 'et', 'dolore',
|
|
||||||
'magnam', 'aliquam', 'quaerat', 'voluptatem', 'ut', 'enim', 'ad',
|
|
||||||
'minima', 'veniam', 'quis', 'nostrum', 'exercitationem', 'ullam',
|
|
||||||
'corporis', 'nemo', 'enim', 'ipsam', 'voluptatem', 'quia', 'voluptas',
|
|
||||||
'sit', 'suscipit', 'laboriosam', 'nisi', 'ut', 'aliquid', 'ex', 'ea',
|
|
||||||
'commodi', 'consequatur', 'quis', 'autem', 'vel', 'eum', 'iure',
|
|
||||||
'reprehenderit', 'qui', 'in', 'ea', 'voluptate', 'velit', 'esse',
|
|
||||||
'quam', 'nihil', 'molestiae', 'et', 'iusto', 'odio', 'dignissimos',
|
|
||||||
'ducimus', 'qui', 'blanditiis', 'praesentium', 'laudantium', 'totam',
|
|
||||||
'rem', 'voluptatum', 'deleniti', 'atque', 'corrupti', 'quos',
|
|
||||||
'dolores', 'et', 'quas', 'molestias', 'excepturi', 'sint',
|
|
||||||
'occaecati', 'cupiditate', 'non', 'provident', 'sed', 'ut',
|
|
||||||
'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error',
|
|
||||||
'similique', 'sunt', 'in', 'culpa', 'qui', 'officia', 'deserunt',
|
|
||||||
'mollitia', 'animi', 'id', 'est', 'laborum', 'et', 'dolorum', 'fuga',
|
|
||||||
'et', 'harum', 'quidem', 'rerum', 'facilis', 'est', 'et', 'expedita',
|
|
||||||
'distinctio', 'nam', 'libero', 'tempore', 'cum', 'soluta', 'nobis',
|
|
||||||
'est', 'eligendi', 'optio', 'cumque', 'nihil', 'impedit', 'quo',
|
|
||||||
'porro', 'quisquam', 'est', 'qui', 'minus', 'id', 'quod', 'maxime',
|
|
||||||
'placeat', 'facere', 'possimus', 'omnis', 'voluptas', 'assumenda',
|
|
||||||
'est', 'omnis', 'dolor', 'repellendus', 'temporibus', 'autem',
|
|
||||||
'quibusdam', 'et', 'aut', 'consequatur', 'vel', 'illum', 'qui',
|
|
||||||
'dolorem', 'eum', 'fugiat', 'quo', 'voluptas', 'nulla', 'pariatur',
|
|
||||||
'at', 'vero', 'eos', 'et', 'accusamus', 'officiis', 'debitis', 'aut',
|
|
||||||
'rerum', 'necessitatibus', 'saepe', 'eveniet', 'ut', 'et',
|
|
||||||
'voluptates', 'repudiandae', 'sint', 'et', 'molestiae', 'non',
|
|
||||||
'recusandae', 'itaque', 'earum', 'rerum', 'hic', 'tenetur', 'a',
|
|
||||||
'sapiente', 'delectus', 'ut', 'aut', 'reiciendis', 'voluptatibus',
|
|
||||||
'maiores', 'doloribus', 'asperiores', 'repellat',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Lorem'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function word()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$wordList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an array of random words
|
|
||||||
*
|
|
||||||
* @example array('Lorem', 'ipsum', 'dolor')
|
|
||||||
*
|
|
||||||
* @param int $nb how many words to return
|
|
||||||
* @param bool $asText if true the sentences are returned as one string
|
|
||||||
*
|
|
||||||
* @return array|string
|
|
||||||
*/
|
|
||||||
public static function words($nb = 3, $asText = false)
|
|
||||||
{
|
|
||||||
$words = [];
|
|
||||||
|
|
||||||
for ($i = 0; $i < $nb; ++$i) {
|
|
||||||
$words[] = static::word();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asText ? implode(' ', $words) : $words;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random sentence
|
|
||||||
*
|
|
||||||
* @example 'Lorem ipsum dolor sit amet.'
|
|
||||||
*
|
|
||||||
* @param int $nbWords around how many words the sentence should contain
|
|
||||||
* @param bool $variableNbWords set to false if you want exactly $nbWords returned,
|
|
||||||
* otherwise $nbWords may vary by +/-40% with a minimum of 1
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function sentence($nbWords = 6, $variableNbWords = true)
|
|
||||||
{
|
|
||||||
if ($nbWords <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($variableNbWords) {
|
|
||||||
$nbWords = self::randomizeNbElements($nbWords);
|
|
||||||
}
|
|
||||||
|
|
||||||
$words = static::words($nbWords);
|
|
||||||
$words[0] = ucwords($words[0]);
|
|
||||||
|
|
||||||
return implode(' ', $words) . '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an array of sentences
|
|
||||||
*
|
|
||||||
* @example array('Lorem ipsum dolor sit amet.', 'Consectetur adipisicing eli.')
|
|
||||||
*
|
|
||||||
* @param int $nb how many sentences to return
|
|
||||||
* @param bool $asText if true the sentences are returned as one string
|
|
||||||
*
|
|
||||||
* @return array|string
|
|
||||||
*/
|
|
||||||
public static function sentences($nb = 3, $asText = false)
|
|
||||||
{
|
|
||||||
$sentences = [];
|
|
||||||
|
|
||||||
for ($i = 0; $i < $nb; ++$i) {
|
|
||||||
$sentences[] = static::sentence();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asText ? implode(' ', $sentences) : $sentences;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a single paragraph
|
|
||||||
*
|
|
||||||
* @example 'Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
|
|
||||||
*
|
|
||||||
* @param int $nbSentences around how many sentences the paragraph should contain
|
|
||||||
* @param bool $variableNbSentences set to false if you want exactly $nbSentences returned,
|
|
||||||
* otherwise $nbSentences may vary by +/-40% with a minimum of 1
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function paragraph($nbSentences = 3, $variableNbSentences = true)
|
|
||||||
{
|
|
||||||
if ($nbSentences <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($variableNbSentences) {
|
|
||||||
$nbSentences = self::randomizeNbElements($nbSentences);
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode(' ', static::sentences($nbSentences));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an array of paragraphs
|
|
||||||
*
|
|
||||||
* @example array($paragraph1, $paragraph2, $paragraph3)
|
|
||||||
*
|
|
||||||
* @param int $nb how many paragraphs to return
|
|
||||||
* @param bool $asText if true the paragraphs are returned as one string, separated by two newlines
|
|
||||||
*
|
|
||||||
* @return array|string
|
|
||||||
*/
|
|
||||||
public static function paragraphs($nb = 3, $asText = false)
|
|
||||||
{
|
|
||||||
$paragraphs = [];
|
|
||||||
|
|
||||||
for ($i = 0; $i < $nb; ++$i) {
|
|
||||||
$paragraphs[] = static::paragraph();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asText ? implode("\n\n", $paragraphs) : $paragraphs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a text string.
|
|
||||||
* Depending on the $maxNbChars, returns a string made of words, sentences, or paragraphs.
|
|
||||||
*
|
|
||||||
* @example 'Sapiente sunt omnis. Ut pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
|
|
||||||
*
|
|
||||||
* @param int $maxNbChars Maximum number of characters the text should contain (minimum 5)
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function text($maxNbChars = 200)
|
|
||||||
{
|
|
||||||
if ($maxNbChars < 5) {
|
|
||||||
throw new \InvalidArgumentException('text() can only generate text of at least 5 characters');
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = 'paragraph';
|
|
||||||
|
|
||||||
if ($maxNbChars < 100) {
|
|
||||||
$type = 'sentence';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($maxNbChars < 25) {
|
|
||||||
$type = 'word';
|
|
||||||
}
|
|
||||||
|
|
||||||
$text = [];
|
|
||||||
|
|
||||||
while (empty($text)) {
|
|
||||||
$size = 0;
|
|
||||||
|
|
||||||
// until $maxNbChars is reached
|
|
||||||
while ($size < $maxNbChars) {
|
|
||||||
$word = ($size ? ' ' : '') . static::$type();
|
|
||||||
$text[] = $word;
|
|
||||||
|
|
||||||
$size += strlen($word);
|
|
||||||
}
|
|
||||||
|
|
||||||
array_pop($text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type === 'word') {
|
|
||||||
// capitalize first letter
|
|
||||||
$text[0] = ucwords($text[0]);
|
|
||||||
|
|
||||||
// end sentence with full stop
|
|
||||||
$text[count($text) - 1] .= '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode('', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function randomizeNbElements($nbElements)
|
|
||||||
{
|
|
||||||
return (int) ($nbElements * self::numberBetween(60, 140) / 100) + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Medical extends Base
|
|
||||||
{
|
|
||||||
protected static $bloodTypes = ['A', 'AB', 'B', 'O'];
|
|
||||||
|
|
||||||
protected static $bloodRhFactors = ['+', '-'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'AB'
|
|
||||||
*/
|
|
||||||
public static function bloodType(): string
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$bloodTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '+'
|
|
||||||
*/
|
|
||||||
public static function bloodRh(): string
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$bloodRhFactors);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'AB+'
|
|
||||||
*/
|
|
||||||
public function bloodGroup(): string
|
|
||||||
{
|
|
||||||
return $this->generator->parse('{{bloodType}}{{bloodRh}}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,342 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Miscellaneous extends Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @see https://en.wikipedia.org/wiki/Emoji#Unicode_blocks
|
|
||||||
* On date of 2017-03-26
|
|
||||||
*
|
|
||||||
* U+1F600 - U+1F637 in Unicode Codepoint Escape Syntax
|
|
||||||
*/
|
|
||||||
protected static $emoji = [
|
|
||||||
"\u{1F600}", "\u{1F601}", "\u{1F602}", "\u{1F603}",
|
|
||||||
"\u{1F604}", "\u{1F605}", "\u{1F606}", "\u{1F607}",
|
|
||||||
"\u{1F608}", "\u{1F609}", "\u{1F60A}", "\u{1F60B}",
|
|
||||||
"\u{1F60C}", "\u{1F60D}", "\u{1F60E}", "\u{1F60F}",
|
|
||||||
"\u{1F610}", "\u{1F611}", "\u{1F612}", "\u{1F613}",
|
|
||||||
"\u{1F614}", "\u{1F615}", "\u{1F616}", "\u{1F617}",
|
|
||||||
"\u{1F618}", "\u{1F619}", "\u{1F61A}", "\u{1F61B}",
|
|
||||||
"\u{1F61C}", "\u{1F61D}", "\u{1F61E}", "\u{1F61F}",
|
|
||||||
"\u{1F620}", "\u{1F621}", "\u{1F622}", "\u{1F623}",
|
|
||||||
"\u{1F624}", "\u{1F625}", "\u{1F626}", "\u{1F627}",
|
|
||||||
"\u{1F628}", "\u{1F629}", "\u{1F62A}", "\u{1F62B}",
|
|
||||||
"\u{1F62C}", "\u{1F62D}", "\u{1F62E}", "\u{1F62F}",
|
|
||||||
"\u{1F630}", "\u{1F631}", "\u{1F632}", "\u{1F633}",
|
|
||||||
"\u{1F634}", "\u{1F635}", "\u{1F636}", "\u{1F637}",
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
|
||||||
* On date of 2016-04-22
|
|
||||||
*/
|
|
||||||
protected static $languageCode = [
|
|
||||||
'aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av',
|
|
||||||
'ay', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bm', 'bn', 'bo',
|
|
||||||
'br', 'bs', 'ca', 'ce', 'ch', 'co', 'cr', 'cs', 'cu', 'cv',
|
|
||||||
'cy', 'da', 'de', 'dv', 'dz', 'ee', 'el', 'en', 'eo', 'es',
|
|
||||||
'et', 'eu', 'fa', 'ff', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga',
|
|
||||||
'gd', 'gl', 'gn', 'gu', 'gv', 'ha', 'he', 'hi', 'ho', 'hr',
|
|
||||||
'ht', 'hu', 'hy', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'ik',
|
|
||||||
'io', 'is', 'it', 'iu', 'ja', 'jv', 'ka', 'kg', 'ki', 'kj',
|
|
||||||
'kk', 'kl', 'km', 'kn', 'ko', 'kr', 'ks', 'ku', 'kv', 'kw',
|
|
||||||
'ky', 'la', 'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv',
|
|
||||||
'mg', 'mh', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my',
|
|
||||||
'na', 'nb', 'nd', 'ne', 'ng', 'nl', 'nn', 'no', 'nr', 'nv',
|
|
||||||
'ny', 'oc', 'oj', 'om', 'or', 'os', 'pa', 'pi', 'pl', 'ps',
|
|
||||||
'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sc', 'sd',
|
|
||||||
'se', 'sg', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr',
|
|
||||||
'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti',
|
|
||||||
'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'ty', 'ug',
|
|
||||||
'uk', 'ur', 'uz', 've', 'vi', 'vo', 'wa', 'wo', 'xh', 'yi',
|
|
||||||
'yo', 'za', 'zh', 'zu',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
||||||
* On date of 2014-10-19
|
|
||||||
*/
|
|
||||||
protected static $countryCode = [
|
|
||||||
'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR',
|
|
||||||
'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE',
|
|
||||||
'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ',
|
|
||||||
'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF',
|
|
||||||
'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU',
|
|
||||||
'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO',
|
|
||||||
'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ',
|
|
||||||
'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG',
|
|
||||||
'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT',
|
|
||||||
'GU', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE',
|
|
||||||
'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM',
|
|
||||||
'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR',
|
|
||||||
'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS',
|
|
||||||
'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG',
|
|
||||||
'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS',
|
|
||||||
'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE',
|
|
||||||
'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM',
|
|
||||||
'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR',
|
|
||||||
'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW',
|
|
||||||
'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK',
|
|
||||||
'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY',
|
|
||||||
'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM',
|
|
||||||
'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM',
|
|
||||||
'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU',
|
|
||||||
'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
|
|
||||||
* On date of 2014-10-19
|
|
||||||
*/
|
|
||||||
protected static $countryISOAlpha3 = [
|
|
||||||
'ABW', 'AFG', 'AGO', 'AIA', 'ALA', 'ALB', 'AND', 'ARE', 'ARG', 'ARM',
|
|
||||||
'ASM', 'ATA', 'ATF', 'ATG', 'AUS', 'AUT', 'AZE', 'BDI', 'BEL', 'BEN',
|
|
||||||
'BES', 'BFA', 'BGD', 'BGR', 'BHR', 'BHS', 'BIH', 'BLM', 'BLR', 'BLZ',
|
|
||||||
'BMU', 'BOL', 'BRA', 'BRB', 'BRN', 'BTN', 'BVT', 'BWA', 'CAF', 'CAN',
|
|
||||||
'CCK', 'CHE', 'CHL', 'CHN', 'CIV', 'CMR', 'COD', 'COG', 'COK', 'COL',
|
|
||||||
'COM', 'CPV', 'CRI', 'CUB', 'CUW', 'CXR', 'CYM', 'CYP', 'CZE', 'DEU',
|
|
||||||
'DJI', 'DMA', 'DNK', 'DOM', 'DZA', 'ECU', 'EGY', 'ERI', 'ESH', 'ESP',
|
|
||||||
'EST', 'ETH', 'FIN', 'FJI', 'FLK', 'FRA', 'FRO', 'FSM', 'GAB', 'GBR',
|
|
||||||
'GEO', 'GGY', 'GHA', 'GIB', 'GIN', 'GLP', 'GMB', 'GNB', 'GNQ', 'GRC',
|
|
||||||
'GRD', 'GRL', 'GTM', 'GUF', 'GUM', 'GUY', 'HKG', 'HMD', 'HND', 'HRV',
|
|
||||||
'HTI', 'HUN', 'IDN', 'IMN', 'IND', 'IOT', 'IRL', 'IRN', 'IRQ', 'ISL',
|
|
||||||
'ISR', 'ITA', 'JAM', 'JEY', 'JOR', 'JPN', 'KAZ', 'KEN', 'KGZ', 'KHM',
|
|
||||||
'KIR', 'KNA', 'KOR', 'KWT', 'LAO', 'LBN', 'LBR', 'LBY', 'LCA', 'LIE',
|
|
||||||
'LKA', 'LSO', 'LTU', 'LUX', 'LVA', 'MAC', 'MAF', 'MAR', 'MCO', 'MDA',
|
|
||||||
'MDG', 'MDV', 'MEX', 'MHL', 'MKD', 'MLI', 'MLT', 'MMR', 'MNE', 'MNG',
|
|
||||||
'MNP', 'MOZ', 'MRT', 'MSR', 'MTQ', 'MUS', 'MWI', 'MYS', 'MYT', 'NAM',
|
|
||||||
'NCL', 'NER', 'NFK', 'NGA', 'NIC', 'NIU', 'NLD', 'NOR', 'NPL', 'NRU',
|
|
||||||
'NZL', 'OMN', 'PAK', 'PAN', 'PCN', 'PER', 'PHL', 'PLW', 'PNG', 'POL',
|
|
||||||
'PRI', 'PRK', 'PRT', 'PRY', 'PSE', 'PYF', 'QAT', 'REU', 'ROU', 'RUS',
|
|
||||||
'RWA', 'SAU', 'SDN', 'SEN', 'SGP', 'SGS', 'SHN', 'SJM', 'SLB', 'SLE',
|
|
||||||
'SLV', 'SMR', 'SOM', 'SPM', 'SRB', 'SSD', 'STP', 'SUR', 'SVK', 'SVN',
|
|
||||||
'SWE', 'SWZ', 'SXM', 'SYC', 'SYR', 'TCA', 'TCD', 'TGO', 'THA', 'TJK',
|
|
||||||
'TKL', 'TKM', 'TLS', 'TON', 'TTO', 'TUN', 'TUR', 'TUV', 'TWN', 'TZA',
|
|
||||||
'UGA', 'UKR', 'UMI', 'URY', 'USA', 'UZB', 'VAT', 'VCT', 'VEN', 'VGB',
|
|
||||||
'VIR', 'VNM', 'VUT', 'WLF', 'WSM', 'YEM', 'ZAF', 'ZMB', 'ZWE',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $localeData = [
|
|
||||||
'aa_DJ', 'aa_ER', 'aa_ET',
|
|
||||||
'af_NA', 'af_ZA', 'ak_GH',
|
|
||||||
'am_ET', 'ar_AE', 'ar_BH', 'ar_DZ',
|
|
||||||
'ar_EG', 'ar_IQ', 'ar_JO', 'ar_KW', 'ar_LB',
|
|
||||||
'ar_LY', 'ar_MA', 'ar_OM', 'ar_QA', 'ar_SA',
|
|
||||||
'ar_SD', 'ar_SY', 'ar_TN', 'ar_YE',
|
|
||||||
'as_IN', 'az_AZ', 'be_BY',
|
|
||||||
'bg_BG', 'bn_BD', 'bn_IN',
|
|
||||||
'bo_CN', 'bo_IN', 'bs_BA',
|
|
||||||
'byn_ER', 'ca_ES',
|
|
||||||
'cch_NG', 'cs_CZ',
|
|
||||||
'cy_GB', 'da_DK', 'de_AT',
|
|
||||||
'de_BE', 'de_CH', 'de_DE', 'de_LI', 'de_LU',
|
|
||||||
'dv_MV', 'dz_BT',
|
|
||||||
'ee_GH', 'ee_TG', 'el_CY', 'el_GR',
|
|
||||||
'en_AS', 'en_AU', 'en_BE', 'en_BW',
|
|
||||||
'en_BZ', 'en_CA', 'en_GB', 'en_GU', 'en_HK',
|
|
||||||
'en_IE', 'en_IN', 'en_JM', 'en_MH', 'en_MP',
|
|
||||||
'en_MT', 'en_NA', 'en_NZ', 'en_PH', 'en_PK',
|
|
||||||
'en_SG', 'en_TT', 'en_UM', 'en_US', 'en_VI',
|
|
||||||
'en_ZA', 'en_ZW', 'es_AR',
|
|
||||||
'es_BO', 'es_CL', 'es_CO', 'es_CR', 'es_DO',
|
|
||||||
'es_EC', 'es_ES', 'es_GT', 'es_HN', 'es_MX',
|
|
||||||
'es_NI', 'es_PA', 'es_PE', 'es_PR', 'es_PY',
|
|
||||||
'es_SV', 'es_US', 'es_UY', 'es_VE',
|
|
||||||
'et_EE', 'eu_ES', 'fa_AF',
|
|
||||||
'fa_IR', 'fi_FI', 'fil_PH',
|
|
||||||
'fo_FO', 'fr_BE', 'fr_CA',
|
|
||||||
'fr_CH', 'fr_FR', 'fr_LU', 'fr_MC', 'fr_SN',
|
|
||||||
'fur_IT', 'ga_IE',
|
|
||||||
'gaa_GH', 'gez_ER', 'gez_ET',
|
|
||||||
'gl_ES', 'gsw_CH', 'gu_IN',
|
|
||||||
'gv_GB', 'ha_GH', 'ha_NE',
|
|
||||||
'ha_NG', 'ha_SD', 'haw_US',
|
|
||||||
'he_IL', 'hi_IN', 'hr_HR',
|
|
||||||
'hu_HU', 'hy_AM',
|
|
||||||
'id_ID', 'ig_NG',
|
|
||||||
'ii_CN', 'is_IS',
|
|
||||||
'it_CH', 'it_IT',
|
|
||||||
'ja_JP', 'ka_GE', 'kaj_NG',
|
|
||||||
'kam_KE', 'kcg_NG',
|
|
||||||
'kfo_CI', 'kk_KZ', 'kl_GL',
|
|
||||||
'km_KH', 'kn_IN',
|
|
||||||
'ko_KR', 'kok_IN', 'kpe_GN',
|
|
||||||
'kpe_LR', 'ku_IQ', 'ku_IR', 'ku_SY',
|
|
||||||
'ku_TR', 'kw_GB', 'ky_KG',
|
|
||||||
'ln_CD', 'ln_CG', 'lo_LA',
|
|
||||||
'lt_LT', 'lv_LV',
|
|
||||||
'mk_MK', 'ml_IN', 'mn_CN',
|
|
||||||
'mn_MN', 'mr_IN',
|
|
||||||
'ms_BN', 'ms_MY', 'mt_MT',
|
|
||||||
'my_MM', 'nb_NO', 'nds_DE',
|
|
||||||
'ne_IN', 'ne_NP', 'nl_BE',
|
|
||||||
'nl_NL', 'nn_NO',
|
|
||||||
'nr_ZA', 'nso_ZA', 'ny_MW',
|
|
||||||
'oc_FR', 'om_ET', 'om_KE',
|
|
||||||
'or_IN', 'pa_IN', 'pa_PK',
|
|
||||||
'pl_PL', 'ps_AF',
|
|
||||||
'pt_BR', 'pt_PT', 'ro_MD', 'ro_RO',
|
|
||||||
'ru_RU', 'ru_UA', 'rw_RW',
|
|
||||||
'sa_IN', 'se_FI', 'se_NO',
|
|
||||||
'sh_BA', 'sh_CS', 'sh_YU',
|
|
||||||
'si_LK', 'sid_ET', 'sk_SK',
|
|
||||||
'sl_SI', 'so_DJ', 'so_ET',
|
|
||||||
'so_KE', 'so_SO', 'sq_AL',
|
|
||||||
'sr_BA', 'sr_CS', 'sr_ME', 'sr_RS', 'sr_YU',
|
|
||||||
'ss_SZ', 'ss_ZA', 'st_LS',
|
|
||||||
'st_ZA', 'sv_FI', 'sv_SE',
|
|
||||||
'sw_KE', 'sw_TZ', 'syr_SY',
|
|
||||||
'ta_IN', 'te_IN', 'tg_TJ',
|
|
||||||
'th_TH', 'ti_ER', 'ti_ET',
|
|
||||||
'tig_ER', 'tn_ZA',
|
|
||||||
'to_TO', 'tr_TR',
|
|
||||||
'trv_TW', 'ts_ZA', 'tt_RU',
|
|
||||||
'ug_CN', 'uk_UA',
|
|
||||||
'ur_IN', 'ur_PK', 'uz_AF', 'uz_UZ',
|
|
||||||
've_ZA', 'vi_VN',
|
|
||||||
'wal_ET', 'wo_SN', 'xh_ZA',
|
|
||||||
'yo_NG', 'zh_CN', 'zh_HK',
|
|
||||||
'zh_MO', 'zh_SG', 'zh_TW', 'zu_ZA',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_4217
|
|
||||||
* On date of 2023-01-01
|
|
||||||
*
|
|
||||||
* With the following exceptions:
|
|
||||||
* SVC has been replaced by the USD in 2001: https://en.wikipedia.org/wiki/Salvadoran_col%C3%B3n
|
|
||||||
* ZWL has been suspended since 2009: https://en.wikipedia.org/wiki/Zimbabwean_dollar
|
|
||||||
* HRK has been replaced by EUR since 2023: https://en.wikipedia.org/wiki/Croatian_kuna
|
|
||||||
*/
|
|
||||||
protected static $currencyCode = [
|
|
||||||
'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
|
|
||||||
'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL',
|
|
||||||
'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', 'CDF', 'CHF', 'CLP', 'CNY',
|
|
||||||
'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD',
|
|
||||||
'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP',
|
|
||||||
'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HTG', 'HUF', 'IDR', 'ILS',
|
|
||||||
'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR',
|
|
||||||
'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD',
|
|
||||||
'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU',
|
|
||||||
'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK',
|
|
||||||
'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG',
|
|
||||||
'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK',
|
|
||||||
'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SYP', 'SZL', 'THB',
|
|
||||||
'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX',
|
|
||||||
'USD', 'UYU', 'UZS', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XOF',
|
|
||||||
'XPF', 'YER', 'ZAR', 'ZMW',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a boolean, true or false.
|
|
||||||
*
|
|
||||||
* @param int $chanceOfGettingTrue Between 0 (always get false) and 100 (always get true)
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @example true
|
|
||||||
*/
|
|
||||||
public static function boolean($chanceOfGettingTrue = 50)
|
|
||||||
{
|
|
||||||
return self::numberBetween(1, 100) <= $chanceOfGettingTrue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'cfcd208495d565ef66e7dff9f98764da'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function md5()
|
|
||||||
{
|
|
||||||
return md5(self::numberBetween());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'b5d86317c2a144cd04d0d7c03b2b02666fafadf2'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function sha1()
|
|
||||||
{
|
|
||||||
return sha1(self::numberBetween());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '85086017559ccc40638fcde2fecaf295e0de7ca51b7517b6aebeaaf75b4d4654'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function sha256()
|
|
||||||
{
|
|
||||||
return hash('sha256', self::numberBetween());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'fr_FR'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function locale()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$localeData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'FR'
|
|
||||||
*
|
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function countryCode()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$countryCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'FRA'
|
|
||||||
*
|
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function countryISOAlpha3()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$countryISOAlpha3);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'fr'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function languageCode()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$languageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'EUR'
|
|
||||||
*
|
|
||||||
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function currencyCode()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$currencyCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an Emoji (Unicode character between U+1F600 and U+1F637).
|
|
||||||
*
|
|
||||||
* @see https://en.wikipedia.org/wiki/Emoji#Unicode_blocks
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function emoji()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$emoji);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,312 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
use Faker\Calculator\Iban;
|
|
||||||
use Faker\Calculator\Luhn;
|
|
||||||
|
|
||||||
class Payment extends Base
|
|
||||||
{
|
|
||||||
public static $expirationDateFormat = 'm/y';
|
|
||||||
|
|
||||||
protected static $cardVendors = [
|
|
||||||
'Visa', 'Visa', 'Visa', 'Visa', 'Visa',
|
|
||||||
'MasterCard', 'MasterCard', 'MasterCard', 'MasterCard', 'MasterCard',
|
|
||||||
'American Express', 'Discover Card', 'Visa Retired', 'JCB',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array List of card brand masks for generating valid credit card numbers
|
|
||||||
*
|
|
||||||
* @see https://en.wikipedia.org/wiki/Payment_card_number Reference for existing prefixes
|
|
||||||
* @see https://www.mastercard.us/en-us/issuers/get-support/2-series-bin-expansion.html MasterCard 2017 2-Series BIN Expansion
|
|
||||||
*/
|
|
||||||
protected static $cardParams = [
|
|
||||||
'Visa' => [
|
|
||||||
'4539###########',
|
|
||||||
'4556###########',
|
|
||||||
'4916###########',
|
|
||||||
'4532###########',
|
|
||||||
'4929###########',
|
|
||||||
'40240071#######',
|
|
||||||
'4485###########',
|
|
||||||
'4716###########',
|
|
||||||
'4##############',
|
|
||||||
],
|
|
||||||
'Visa Retired' => [
|
|
||||||
'4539########',
|
|
||||||
'4556########',
|
|
||||||
'4916########',
|
|
||||||
'4532########',
|
|
||||||
'4929########',
|
|
||||||
'40240071####',
|
|
||||||
'4485########',
|
|
||||||
'4716########',
|
|
||||||
'4###########',
|
|
||||||
],
|
|
||||||
'MasterCard' => [
|
|
||||||
'2221###########',
|
|
||||||
'23#############',
|
|
||||||
'24#############',
|
|
||||||
'25#############',
|
|
||||||
'26#############',
|
|
||||||
'2720###########',
|
|
||||||
'51#############',
|
|
||||||
'52#############',
|
|
||||||
'53#############',
|
|
||||||
'54#############',
|
|
||||||
'55#############',
|
|
||||||
],
|
|
||||||
'American Express' => [
|
|
||||||
'34############',
|
|
||||||
'37############',
|
|
||||||
],
|
|
||||||
'Discover Card' => [
|
|
||||||
'6011###########',
|
|
||||||
],
|
|
||||||
'JCB' => [
|
|
||||||
'3528###########',
|
|
||||||
'3589###########',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array list of IBAN formats, source: @see https://www.swift.com/standards/data-standards/iban
|
|
||||||
*/
|
|
||||||
protected static $ibanFormats = [
|
|
||||||
'AD' => [['n', 4], ['n', 4], ['c', 12]],
|
|
||||||
'AE' => [['n', 3], ['n', 16]],
|
|
||||||
'AL' => [['n', 8], ['c', 16]],
|
|
||||||
'AT' => [['n', 5], ['n', 11]],
|
|
||||||
'AZ' => [['a', 4], ['c', 20]],
|
|
||||||
'BA' => [['n', 3], ['n', 3], ['n', 8], ['n', 2]],
|
|
||||||
'BE' => [['n', 3], ['n', 7], ['n', 2]],
|
|
||||||
'BG' => [['a', 4], ['n', 4], ['n', 2], ['c', 8]],
|
|
||||||
'BH' => [['a', 4], ['c', 14]],
|
|
||||||
'BR' => [['n', 8], ['n', 5], ['n', 10], ['a', 1], ['c', 1]],
|
|
||||||
'CH' => [['n', 5], ['c', 12]],
|
|
||||||
'CR' => [['n', 4], ['n', 14]],
|
|
||||||
'CY' => [['n', 3], ['n', 5], ['c', 16]],
|
|
||||||
'CZ' => [['n', 4], ['n', 6], ['n', 10]],
|
|
||||||
'DE' => [['n', 8], ['n', 10]],
|
|
||||||
'DK' => [['n', 4], ['n', 9], ['n', 1]],
|
|
||||||
'DO' => [['c', 4], ['n', 20]],
|
|
||||||
'EE' => [['n', 2], ['n', 2], ['n', 11], ['n', 1]],
|
|
||||||
'EG' => [['n', 4], ['n', 4], ['n', 17]],
|
|
||||||
'ES' => [['n', 4], ['n', 4], ['n', 1], ['n', 1], ['n', 10]],
|
|
||||||
'FI' => [['n', 6], ['n', 7], ['n', 1]],
|
|
||||||
'FR' => [['n', 5], ['n', 5], ['c', 11], ['n', 2]],
|
|
||||||
'GB' => [['a', 4], ['n', 6], ['n', 8]],
|
|
||||||
'GE' => [['a', 2], ['n', 16]],
|
|
||||||
'GI' => [['a', 4], ['c', 15]],
|
|
||||||
'GR' => [['n', 3], ['n', 4], ['c', 16]],
|
|
||||||
'GT' => [['c', 4], ['c', 20]],
|
|
||||||
'HR' => [['n', 7], ['n', 10]],
|
|
||||||
'HU' => [['n', 3], ['n', 4], ['n', 1], ['n', 15], ['n', 1]],
|
|
||||||
'IE' => [['a', 4], ['n', 6], ['n', 8]],
|
|
||||||
'IL' => [['n', 3], ['n', 3], ['n', 13]],
|
|
||||||
'IS' => [['n', 4], ['n', 2], ['n', 6], ['n', 10]],
|
|
||||||
'IT' => [['a', 1], ['n', 5], ['n', 5], ['c', 12]],
|
|
||||||
'KW' => [['a', 4], ['n', 22]],
|
|
||||||
'KZ' => [['n', 3], ['c', 13]],
|
|
||||||
'LB' => [['n', 4], ['c', 20]],
|
|
||||||
'LI' => [['n', 5], ['c', 12]],
|
|
||||||
'LT' => [['n', 5], ['n', 11]],
|
|
||||||
'LU' => [['n', 3], ['c', 13]],
|
|
||||||
'LV' => [['a', 4], ['c', 13]],
|
|
||||||
'MC' => [['n', 5], ['n', 5], ['c', 11], ['n', 2]],
|
|
||||||
'MD' => [['c', 2], ['c', 18]],
|
|
||||||
'ME' => [['n', 3], ['n', 13], ['n', 2]],
|
|
||||||
'MK' => [['n', 3], ['c', 10], ['n', 2]],
|
|
||||||
'MR' => [['n', 5], ['n', 5], ['n', 11], ['n', 2]],
|
|
||||||
'MT' => [['a', 4], ['n', 5], ['c', 18]],
|
|
||||||
'MU' => [['a', 4], ['n', 2], ['n', 2], ['n', 12], ['n', 3], ['a', 3]],
|
|
||||||
'NL' => [['a', 4], ['n', 10]],
|
|
||||||
'NO' => [['n', 4], ['n', 6], ['n', 1]],
|
|
||||||
'PK' => [['a', 4], ['c', 16]],
|
|
||||||
'PL' => [['n', 8], ['n', 16]],
|
|
||||||
'PS' => [['a', 4], ['c', 21]],
|
|
||||||
'PT' => [['n', 4], ['n', 4], ['n', 11], ['n', 2]],
|
|
||||||
'RO' => [['a', 4], ['c', 16]],
|
|
||||||
'RS' => [['n', 3], ['n', 13], ['n', 2]],
|
|
||||||
'SA' => [['n', 2], ['c', 18]],
|
|
||||||
'SE' => [['n', 3], ['n', 16], ['n', 1]],
|
|
||||||
'SI' => [['n', 5], ['n', 8], ['n', 2]],
|
|
||||||
'SK' => [['n', 4], ['n', 6], ['n', 10]],
|
|
||||||
'SM' => [['a', 1], ['n', 5], ['n', 5], ['c', 12]],
|
|
||||||
'TN' => [['n', 2], ['n', 3], ['n', 13], ['n', 2]],
|
|
||||||
'TR' => [['n', 5], ['n', 1], ['c', 16]],
|
|
||||||
'VG' => [['a', 4], ['n', 16]],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string Returns a credit card vendor name
|
|
||||||
*
|
|
||||||
* @example 'MasterCard'
|
|
||||||
*/
|
|
||||||
public static function creditCardType()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$cardVendors);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the String of a credit card number.
|
|
||||||
*
|
|
||||||
* @param string $type Supporting any of 'Visa', 'MasterCard', 'American Express', 'Discover' and 'JCB'
|
|
||||||
* @param bool $formatted Set to true if the output string should contain one separator every 4 digits
|
|
||||||
* @param string $separator Separator string for formatting card number. Defaults to dash (-).
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '4485480221084675'
|
|
||||||
*/
|
|
||||||
public static function creditCardNumber($type = null, $formatted = false, $separator = '-')
|
|
||||||
{
|
|
||||||
if (null === $type) {
|
|
||||||
$type = static::creditCardType();
|
|
||||||
}
|
|
||||||
$mask = static::randomElement(static::$cardParams[$type]);
|
|
||||||
|
|
||||||
$number = static::numerify($mask);
|
|
||||||
$number .= Luhn::computeCheckDigit($number);
|
|
||||||
|
|
||||||
if ($formatted) {
|
|
||||||
$p1 = substr($number, 0, 4);
|
|
||||||
$p2 = substr($number, 4, 4);
|
|
||||||
$p3 = substr($number, 8, 4);
|
|
||||||
$p4 = substr($number, 12);
|
|
||||||
$number = $p1 . $separator . $p2 . $separator . $p3 . $separator . $p4;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $valid True (by default) to get a valid expiration date, false to get a maybe valid date
|
|
||||||
*
|
|
||||||
* @return \DateTime
|
|
||||||
*
|
|
||||||
* @example 04/13
|
|
||||||
*/
|
|
||||||
public function creditCardExpirationDate($valid = true)
|
|
||||||
{
|
|
||||||
if ($valid) {
|
|
||||||
return $this->generator->dateTimeBetween('now', '36 months');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->generator->dateTimeBetween('-36 months', '36 months');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $valid True (by default) to get a valid expiration date, false to get a maybe valid date
|
|
||||||
* @param string $expirationDateFormat
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example '04/13'
|
|
||||||
*/
|
|
||||||
public function creditCardExpirationDateString($valid = true, $expirationDateFormat = null)
|
|
||||||
{
|
|
||||||
return $this->creditCardExpirationDate($valid)->format(null === $expirationDateFormat ? static::$expirationDateFormat : $expirationDateFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $valid True (by default) to get a valid expiration date, false to get a maybe valid date
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function creditCardDetails($valid = true)
|
|
||||||
{
|
|
||||||
$type = static::creditCardType();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'type' => $type,
|
|
||||||
'number' => static::creditCardNumber($type),
|
|
||||||
'name' => $this->generator->name(),
|
|
||||||
'expirationDate' => $this->creditCardExpirationDateString($valid),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* International Bank Account Number (IBAN)
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Bank_Account_Number
|
|
||||||
*
|
|
||||||
* @param string $countryCode ISO 3166-1 alpha-2 country code
|
|
||||||
* @param string $prefix for generating bank account number of a specific bank
|
|
||||||
* @param int $length total length without country code and 2 check digits
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function iban($countryCode = null, $prefix = '', $length = null)
|
|
||||||
{
|
|
||||||
$countryCode = null === $countryCode ? self::randomKey(self::$ibanFormats) : strtoupper($countryCode);
|
|
||||||
|
|
||||||
$format = !isset(static::$ibanFormats[$countryCode]) ? null : static::$ibanFormats[$countryCode];
|
|
||||||
|
|
||||||
if ($length === null) {
|
|
||||||
if ($format === null) {
|
|
||||||
$length = 24;
|
|
||||||
} else {
|
|
||||||
$length = 0;
|
|
||||||
|
|
||||||
foreach ($format as $part) {
|
|
||||||
[$class, $groupCount] = $part;
|
|
||||||
$length += $groupCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($format === null) {
|
|
||||||
$format = [['n', $length]];
|
|
||||||
}
|
|
||||||
|
|
||||||
$expandedFormat = '';
|
|
||||||
|
|
||||||
foreach ($format as $item) {
|
|
||||||
[$class, $length] = $item;
|
|
||||||
$expandedFormat .= str_repeat($class, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $prefix;
|
|
||||||
$expandedFormat = substr($expandedFormat, strlen($result));
|
|
||||||
|
|
||||||
foreach (str_split($expandedFormat) as $class) {
|
|
||||||
switch ($class) {
|
|
||||||
default:
|
|
||||||
case 'c':
|
|
||||||
$result .= Miscellaneous::boolean() ? static::randomDigit() : strtoupper(static::randomLetter());
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'a':
|
|
||||||
$result .= strtoupper(static::randomLetter());
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'n':
|
|
||||||
$result .= static::randomDigit();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$checksum = Iban::checksum($countryCode . '00' . $result);
|
|
||||||
|
|
||||||
return $countryCode . $checksum . $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the String of a SWIFT/BIC number
|
|
||||||
*
|
|
||||||
* @example 'RZTIAT22263'
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/ISO_9362
|
|
||||||
*
|
|
||||||
* @return string Swift/Bic number
|
|
||||||
*/
|
|
||||||
public static function swiftBicNumber()
|
|
||||||
{
|
|
||||||
return self::regexify('^([A-Z]){4}([A-Z]){2}([0-9A-Z]){2}([0-9A-Z]{3})?$');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-147
@@ -1,147 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Person extends Base
|
|
||||||
{
|
|
||||||
public const GENDER_MALE = 'male';
|
|
||||||
public const GENDER_FEMALE = 'female';
|
|
||||||
|
|
||||||
protected static $titleFormat = [
|
|
||||||
'{{titleMale}}',
|
|
||||||
'{{titleFemale}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $firstNameFormat = [
|
|
||||||
'{{firstNameMale}}',
|
|
||||||
'{{firstNameFemale}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $maleNameFormats = [
|
|
||||||
'{{firstNameMale}} {{lastName}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $femaleNameFormats = [
|
|
||||||
'{{firstNameFemale}} {{lastName}}',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $firstNameMale = [
|
|
||||||
'John',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $firstNameFemale = [
|
|
||||||
'Jane',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static $lastName = ['Doe'];
|
|
||||||
|
|
||||||
protected static $titleMale = ['Mr.', 'Dr.', 'Prof.'];
|
|
||||||
|
|
||||||
protected static $titleFemale = ['Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $gender 'male', 'female' or null for any
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'John Doe'
|
|
||||||
*/
|
|
||||||
public function name($gender = null)
|
|
||||||
{
|
|
||||||
if ($gender === static::GENDER_MALE) {
|
|
||||||
$format = static::randomElement(static::$maleNameFormats);
|
|
||||||
} elseif ($gender === static::GENDER_FEMALE) {
|
|
||||||
$format = static::randomElement(static::$femaleNameFormats);
|
|
||||||
} else {
|
|
||||||
$format = static::randomElement(array_merge(static::$maleNameFormats, static::$femaleNameFormats));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->generator->parse($format);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string|null $gender 'male', 'female' or null for any
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @example 'John'
|
|
||||||
*/
|
|
||||||
public function firstName($gender = null)
|
|
||||||
{
|
|
||||||
if ($gender === static::GENDER_MALE) {
|
|
||||||
return static::firstNameMale();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($gender === static::GENDER_FEMALE) {
|
|
||||||
return static::firstNameFemale();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->generator->parse(static::randomElement(static::$firstNameFormat));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function firstNameMale()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$firstNameMale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function firstNameFemale()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$firstNameFemale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Doe'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function lastName()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$lastName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Mrs.'
|
|
||||||
*
|
|
||||||
* @param string|null $gender 'male', 'female' or null for any
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function title($gender = null)
|
|
||||||
{
|
|
||||||
if ($gender === static::GENDER_MALE) {
|
|
||||||
return static::titleMale();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($gender === static::GENDER_FEMALE) {
|
|
||||||
return static::titleFemale();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->generator->parse(static::randomElement(static::$titleFormat));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Mr.'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function titleMale()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$titleMale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example 'Mrs.'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function titleFemale()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$titleFemale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,270 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
use Faker\Calculator\Luhn;
|
|
||||||
|
|
||||||
class PhoneNumber extends Base
|
|
||||||
{
|
|
||||||
protected static $formats = ['###-###-###'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://github.com/giggsey/libphonenumber-for-php/blob/master/src/CountryCodeToRegionCodeMap.php
|
|
||||||
* @see https://libphonenumber.appspot.com/phonenumberparser?number=%2B4576597442
|
|
||||||
*/
|
|
||||||
protected static $e164Formats = [
|
|
||||||
'+1##########',
|
|
||||||
'+7##########',
|
|
||||||
'+20##########',
|
|
||||||
'+27##########',
|
|
||||||
'+30##########',
|
|
||||||
'+31##########',
|
|
||||||
'+32#########',
|
|
||||||
'+33#########',
|
|
||||||
'+34#########',
|
|
||||||
'+36#########',
|
|
||||||
'+39##########',
|
|
||||||
'+40#########',
|
|
||||||
'+41#########',
|
|
||||||
'+43##########',
|
|
||||||
'+44##########',
|
|
||||||
'+45########',
|
|
||||||
'+46##########',
|
|
||||||
'+47########',
|
|
||||||
'+48##########',
|
|
||||||
'+49##########',
|
|
||||||
'+51#########',
|
|
||||||
'+52##########',
|
|
||||||
'+53##########',
|
|
||||||
'+54##########',
|
|
||||||
'+55#########',
|
|
||||||
'+56##########',
|
|
||||||
'+57##########',
|
|
||||||
'+58##########',
|
|
||||||
'+60##########',
|
|
||||||
'+61##########',
|
|
||||||
'+62##########',
|
|
||||||
'+63##########',
|
|
||||||
'+64##########',
|
|
||||||
'+65##########',
|
|
||||||
'+66##########',
|
|
||||||
'+81##########',
|
|
||||||
'+82##########',
|
|
||||||
'+84##########',
|
|
||||||
'+86##########',
|
|
||||||
'+90##########',
|
|
||||||
'+91##########',
|
|
||||||
'+92##########',
|
|
||||||
'+93#########',
|
|
||||||
'+94#########',
|
|
||||||
'+95##########',
|
|
||||||
'+98##########',
|
|
||||||
'+211#########',
|
|
||||||
'+212#########',
|
|
||||||
'+213#########',
|
|
||||||
'+216########',
|
|
||||||
'+218#########',
|
|
||||||
'+220#######',
|
|
||||||
'+221#########',
|
|
||||||
'+222########',
|
|
||||||
'+223########',
|
|
||||||
'+224#########',
|
|
||||||
'+225##########',
|
|
||||||
'+226########',
|
|
||||||
'+227########',
|
|
||||||
'+228########',
|
|
||||||
'+229########',
|
|
||||||
'+230########',
|
|
||||||
'+231#########',
|
|
||||||
'+232########',
|
|
||||||
'+233#########',
|
|
||||||
'+234##########',
|
|
||||||
'+235########',
|
|
||||||
'+236########',
|
|
||||||
'+237#########',
|
|
||||||
'+238#######',
|
|
||||||
'+239#######',
|
|
||||||
'+240#########',
|
|
||||||
'+241########',
|
|
||||||
'+242#########',
|
|
||||||
'+243#########',
|
|
||||||
'+244#########',
|
|
||||||
'+245#########',
|
|
||||||
'+246#######',
|
|
||||||
'+247######',
|
|
||||||
'+248#######',
|
|
||||||
'+249#########',
|
|
||||||
'+250#########',
|
|
||||||
'+251#########',
|
|
||||||
'+252#########',
|
|
||||||
'+253########',
|
|
||||||
'+254##########',
|
|
||||||
'+255#########',
|
|
||||||
'+256#########',
|
|
||||||
'+257########',
|
|
||||||
'+258#########',
|
|
||||||
'+260#########',
|
|
||||||
'+261#########',
|
|
||||||
'+262#########',
|
|
||||||
'+263##########',
|
|
||||||
'+264#########',
|
|
||||||
'+265#########',
|
|
||||||
'+266########',
|
|
||||||
'+267##########',
|
|
||||||
'+268#########',
|
|
||||||
'+269#######',
|
|
||||||
'+290#####',
|
|
||||||
'+291#######',
|
|
||||||
'+297#######',
|
|
||||||
'+298######',
|
|
||||||
'+299######',
|
|
||||||
'+350########',
|
|
||||||
'+351#########',
|
|
||||||
'+352##########',
|
|
||||||
'+353##########',
|
|
||||||
'+354#########',
|
|
||||||
'+355#########',
|
|
||||||
'+356########',
|
|
||||||
'+357########',
|
|
||||||
'+358##########',
|
|
||||||
'+359#########',
|
|
||||||
'+370########',
|
|
||||||
'+371########',
|
|
||||||
'+372##########',
|
|
||||||
'+373########',
|
|
||||||
'+374########',
|
|
||||||
'+375##########',
|
|
||||||
'+376#########',
|
|
||||||
'+377#########',
|
|
||||||
'+378##########',
|
|
||||||
'+380##########',
|
|
||||||
'+381##########',
|
|
||||||
'+382#########',
|
|
||||||
'+383#########',
|
|
||||||
'+385#########',
|
|
||||||
'+386########',
|
|
||||||
'+387#########',
|
|
||||||
'+389########',
|
|
||||||
'+420#########',
|
|
||||||
'+421#########',
|
|
||||||
'+423#########',
|
|
||||||
'+500#####',
|
|
||||||
'+501#######',
|
|
||||||
'+502########',
|
|
||||||
'+503########',
|
|
||||||
'+504########',
|
|
||||||
'+505########',
|
|
||||||
'+506########',
|
|
||||||
'+507##########',
|
|
||||||
'+508#########',
|
|
||||||
'+509########',
|
|
||||||
'+590#########',
|
|
||||||
'+591#########',
|
|
||||||
'+592#######',
|
|
||||||
'+593##########',
|
|
||||||
'+594#########',
|
|
||||||
'+595##########',
|
|
||||||
'+596#########',
|
|
||||||
'+597#######',
|
|
||||||
'+598##########',
|
|
||||||
'+599########',
|
|
||||||
'+670########',
|
|
||||||
'+672######',
|
|
||||||
'+673#######',
|
|
||||||
'+674#######',
|
|
||||||
'+675########',
|
|
||||||
'+676#######',
|
|
||||||
'+677#######',
|
|
||||||
'+678#######',
|
|
||||||
'+679#######',
|
|
||||||
'+680#######',
|
|
||||||
'+681#########',
|
|
||||||
'+682#####',
|
|
||||||
'+683#######',
|
|
||||||
'+685##########',
|
|
||||||
'+686########',
|
|
||||||
'+687######',
|
|
||||||
'+688#######',
|
|
||||||
'+689#########',
|
|
||||||
'+690#######',
|
|
||||||
'+691#######',
|
|
||||||
'+692#######',
|
|
||||||
'+800########',
|
|
||||||
'+808########',
|
|
||||||
'+850##########',
|
|
||||||
'+852#########',
|
|
||||||
'+853########',
|
|
||||||
'+855##########',
|
|
||||||
'+856##########',
|
|
||||||
'+870#########',
|
|
||||||
'+878############',
|
|
||||||
'+880##########',
|
|
||||||
'+881#########',
|
|
||||||
'+882##########',
|
|
||||||
'+883#########',
|
|
||||||
'+886##########',
|
|
||||||
'+888###########',
|
|
||||||
'+960##########',
|
|
||||||
'+961########',
|
|
||||||
'+962#########',
|
|
||||||
'+963#########',
|
|
||||||
'+964##########',
|
|
||||||
'+965########',
|
|
||||||
'+966##########',
|
|
||||||
'+967#########',
|
|
||||||
'+968#########',
|
|
||||||
'+970##########',
|
|
||||||
'+971##########',
|
|
||||||
'+972##########',
|
|
||||||
'+973########',
|
|
||||||
'+974########',
|
|
||||||
'+975########',
|
|
||||||
'+976##########',
|
|
||||||
'+977##########',
|
|
||||||
'+979#########',
|
|
||||||
'+992#########',
|
|
||||||
'+993########',
|
|
||||||
'+994#########',
|
|
||||||
'+995#########',
|
|
||||||
'+996#########',
|
|
||||||
'+998#########',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example '555-123-546'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function phoneNumber()
|
|
||||||
{
|
|
||||||
return static::numerify($this->generator->parse(static::randomElement(static::$formats)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example +11134567890
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function e164PhoneNumber()
|
|
||||||
{
|
|
||||||
return static::numerify($this->generator->parse(static::randomElement(static::$e164Formats)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* International Mobile Equipment Identity (IMEI)
|
|
||||||
*
|
|
||||||
* @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
|
|
||||||
* @see http://imei-number.com/imei-validation-check/
|
|
||||||
*
|
|
||||||
* @example '720084494799532'
|
|
||||||
*
|
|
||||||
* @return int $imei
|
|
||||||
*/
|
|
||||||
public function imei()
|
|
||||||
{
|
|
||||||
$imei = (string) static::numerify('##############');
|
|
||||||
$imei .= Luhn::computeCheckDigit($imei);
|
|
||||||
|
|
||||||
return $imei;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-202
@@ -1,202 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
abstract class Text extends Base
|
|
||||||
{
|
|
||||||
protected static $baseText = '';
|
|
||||||
protected static $separator = ' ';
|
|
||||||
protected static $separatorLen = 1;
|
|
||||||
protected $explodedText;
|
|
||||||
protected $consecutiveWords = [];
|
|
||||||
protected static $textStartsWithUppercase = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a text string by the Markov chain algorithm.
|
|
||||||
*
|
|
||||||
* Depending on the $maxNbChars, returns a random valid looking text. The algorithm
|
|
||||||
* generates a weighted table with the specified number of words as the index and the
|
|
||||||
* possible following words as the value.
|
|
||||||
*
|
|
||||||
* @example 'Alice, swallowing down her flamingo, and began by taking the little golden key'
|
|
||||||
*
|
|
||||||
* @param int $maxNbChars Maximum number of characters the text should contain (minimum: 10)
|
|
||||||
* @param int $indexSize Determines how many words are considered for the generation of the next word.
|
|
||||||
* The minimum is 1, and it produces a higher level of randomness, although the
|
|
||||||
* generated text usually doesn't make sense. Higher index sizes (up to 5)
|
|
||||||
* produce more correct text, at the price of less randomness.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function realText($maxNbChars = 200, $indexSize = 2)
|
|
||||||
{
|
|
||||||
return $this->realTextBetween((int) round($maxNbChars * 0.8), $maxNbChars, $indexSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a text string by the Markov chain algorithm.
|
|
||||||
*
|
|
||||||
* Depending on the $maxNbChars, returns a random valid looking text. The algorithm
|
|
||||||
* generates a weighted table with the specified number of words as the index and the
|
|
||||||
* possible following words as the value.
|
|
||||||
*
|
|
||||||
* @example 'Alice, swallowing down her flamingo, and began by taking the little golden key'
|
|
||||||
*
|
|
||||||
* @param int $minNbChars Minimum number of characters the text should contain (maximum: 8)
|
|
||||||
* @param int $maxNbChars Maximum number of characters the text should contain (minimum: 10)
|
|
||||||
* @param int $indexSize Determines how many words are considered for the generation of the next word.
|
|
||||||
* The minimum is 1, and it produces a higher level of randomness, although the
|
|
||||||
* generated text usually doesn't make sense. Higher index sizes (up to 5)
|
|
||||||
* produce more correct text, at the price of less randomness.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function realTextBetween($minNbChars = 160, $maxNbChars = 200, $indexSize = 2)
|
|
||||||
{
|
|
||||||
if ($minNbChars < 1) {
|
|
||||||
throw new \InvalidArgumentException('minNbChars must be at least 1');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($maxNbChars < 10) {
|
|
||||||
throw new \InvalidArgumentException('maxNbChars must be at least 10');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($indexSize < 1) {
|
|
||||||
throw new \InvalidArgumentException('indexSize must be at least 1');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($indexSize > 5) {
|
|
||||||
throw new \InvalidArgumentException('indexSize must be at most 5');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($minNbChars >= $maxNbChars) {
|
|
||||||
throw new \InvalidArgumentException('minNbChars must be smaller than maxNbChars');
|
|
||||||
}
|
|
||||||
|
|
||||||
$words = $this->getConsecutiveWords($indexSize);
|
|
||||||
$iterations = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
++$iterations;
|
|
||||||
|
|
||||||
if ($iterations >= 100) {
|
|
||||||
throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a valid real text', $iterations));
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->generateText($maxNbChars, $words);
|
|
||||||
} while (static::strlen($result) <= $minNbChars);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $maxNbChars
|
|
||||||
* @param array $words
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function generateText($maxNbChars, $words)
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
$resultLength = 0;
|
|
||||||
// take a random starting point
|
|
||||||
$next = static::randomKey($words);
|
|
||||||
|
|
||||||
while ($resultLength < $maxNbChars && isset($words[$next])) {
|
|
||||||
// fetch a random word to append
|
|
||||||
$word = static::randomElement($words[$next]);
|
|
||||||
|
|
||||||
// calculate next index
|
|
||||||
$currentWords = static::explode($next);
|
|
||||||
$currentWords[] = $word;
|
|
||||||
array_shift($currentWords);
|
|
||||||
$next = static::implode($currentWords);
|
|
||||||
|
|
||||||
// ensure text starts with an uppercase letter
|
|
||||||
if ($resultLength == 0 && !static::validStart($word)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// append the element
|
|
||||||
$result[] = $word;
|
|
||||||
$resultLength += static::strlen($word) + static::$separatorLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove the element that caused the text to overflow
|
|
||||||
array_pop($result);
|
|
||||||
|
|
||||||
// build result
|
|
||||||
$result = static::implode($result);
|
|
||||||
|
|
||||||
return static::appendEnd($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getConsecutiveWords($indexSize)
|
|
||||||
{
|
|
||||||
if (!isset($this->consecutiveWords[$indexSize])) {
|
|
||||||
$parts = $this->getExplodedText();
|
|
||||||
$words = [];
|
|
||||||
$index = [];
|
|
||||||
|
|
||||||
for ($i = 0; $i < $indexSize; ++$i) {
|
|
||||||
$index[] = array_shift($parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 0, $count = count($parts); $i < $count; ++$i) {
|
|
||||||
$stringIndex = static::implode($index);
|
|
||||||
|
|
||||||
if (!isset($words[$stringIndex])) {
|
|
||||||
$words[$stringIndex] = [];
|
|
||||||
}
|
|
||||||
$word = $parts[$i];
|
|
||||||
$words[$stringIndex][] = $word;
|
|
||||||
array_shift($index);
|
|
||||||
$index[] = $word;
|
|
||||||
}
|
|
||||||
// cache look up words for performance
|
|
||||||
$this->consecutiveWords[$indexSize] = $words;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->consecutiveWords[$indexSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getExplodedText()
|
|
||||||
{
|
|
||||||
if ($this->explodedText === null) {
|
|
||||||
$this->explodedText = static::explode(preg_replace('/\s+/u', ' ', static::$baseText));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->explodedText;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function explode($text)
|
|
||||||
{
|
|
||||||
return explode(static::$separator, $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function implode($words)
|
|
||||||
{
|
|
||||||
return implode(static::$separator, $words);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function strlen($text)
|
|
||||||
{
|
|
||||||
return function_exists('mb_strlen') ? mb_strlen($text, 'UTF-8') : strlen($text);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function validStart($word)
|
|
||||||
{
|
|
||||||
$isValid = true;
|
|
||||||
|
|
||||||
if (static::$textStartsWithUppercase) {
|
|
||||||
$isValid = preg_match('/^\p{Lu}/u', $word);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $isValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function appendEnd($text)
|
|
||||||
{
|
|
||||||
return preg_replace("/([ ,-:;\x{2013}\x{2014}]+$)/us", '', $text) . '.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class UserAgent extends Base
|
|
||||||
{
|
|
||||||
protected static $userAgents = ['firefox', 'chrome', 'internetExplorer', 'opera', 'safari', 'msedge'];
|
|
||||||
|
|
||||||
protected static $windowsPlatformTokens = [
|
|
||||||
'Windows NT 6.2', 'Windows NT 6.1', 'Windows NT 6.0', 'Windows NT 5.2', 'Windows NT 5.1',
|
|
||||||
'Windows NT 5.01', 'Windows NT 5.0', 'Windows NT 4.0', 'Windows 98; Win 9x 4.90', 'Windows 98',
|
|
||||||
'Windows 95', 'Windows CE',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Possible processors on Linux
|
|
||||||
*/
|
|
||||||
protected static $linuxProcessor = ['i686', 'x86_64'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mac processors (it also added U;)
|
|
||||||
*/
|
|
||||||
protected static $macProcessor = ['Intel', 'PPC', 'U; Intel', 'U; PPC'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add as many languages as you like.
|
|
||||||
*/
|
|
||||||
protected static $lang = ['en-US', 'sl-SI', 'nl-NL'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate mac processor
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function macProcessor()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$macProcessor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate linux processor
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function linuxProcessor()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$linuxProcessor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random user agent
|
|
||||||
*
|
|
||||||
* @example 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function userAgent()
|
|
||||||
{
|
|
||||||
$userAgentName = static::randomElement(static::$userAgents);
|
|
||||||
|
|
||||||
return static::$userAgentName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Chrome user agent
|
|
||||||
*
|
|
||||||
* @example 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function chrome()
|
|
||||||
{
|
|
||||||
$saf = self::numberBetween(531, 536) . self::numberBetween(0, 2);
|
|
||||||
|
|
||||||
$platforms = [
|
|
||||||
'(' . static::linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . self::numberBetween(36, 40) . '.0.' . self::numberBetween(800, 899) . ".0 Mobile Safari/$saf",
|
|
||||||
'(' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . self::numberBetween(36, 40) . '.0.' . self::numberBetween(800, 899) . ".0 Mobile Safari/$saf",
|
|
||||||
'(' . static::macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . self::numberBetween(36, 40) . '.0.' . self::numberBetween(800, 899) . ".0 Mobile Safari/$saf",
|
|
||||||
];
|
|
||||||
|
|
||||||
return 'Mozilla/5.0 ' . static::randomElement($platforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Edge user agent
|
|
||||||
*
|
|
||||||
* @example 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36 Edg/99.0.1150.36'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function msedge()
|
|
||||||
{
|
|
||||||
$saf = self::numberBetween(531, 537) . '.' . self::numberBetween(0, 2);
|
|
||||||
$chrv = self::numberBetween(79, 99) . '.0';
|
|
||||||
|
|
||||||
$platforms = [
|
|
||||||
'(' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . self::numberBetween(4000, 4844) . '.' . self::numberBetween(10, 99) . " Safari/$saf Edg/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99),
|
|
||||||
'(' . static::macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . self::numberBetween(4000, 4844) . '.' . self::numberBetween(10, 99) . " Safari/$saf Edg/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99),
|
|
||||||
'(' . static::linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . self::numberBetween(4000, 4844) . '.' . self::numberBetween(10, 99) . " Safari/$saf EdgA/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99),
|
|
||||||
'(' . static::iosMobileToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/15.0 EdgiOS/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99) . " Mobile/15E148 Safari/$saf",
|
|
||||||
];
|
|
||||||
|
|
||||||
return 'Mozilla/5.0 ' . static::randomElement($platforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Firefox user agent
|
|
||||||
*
|
|
||||||
* @example 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function firefox()
|
|
||||||
{
|
|
||||||
$ver = 'Gecko/' . date('Ymd', self::numberBetween(strtotime('2010-1-1'), time())) . ' Firefox/' . self::numberBetween(35, 37) . '.0';
|
|
||||||
|
|
||||||
$platforms = [
|
|
||||||
'(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . '; rv:1.9.' . self::numberBetween(0, 2) . '.20) ' . $ver,
|
|
||||||
'(' . static::linuxPlatformToken() . '; rv:' . self::numberBetween(5, 7) . '.0) ' . $ver,
|
|
||||||
'(' . static::macPlatformToken() . ' rv:' . self::numberBetween(2, 6) . '.0) ' . $ver,
|
|
||||||
];
|
|
||||||
|
|
||||||
return 'Mozilla/5.0 ' . static::randomElement($platforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Safari user agent
|
|
||||||
*
|
|
||||||
* @example 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_1 rv:3.0; en-US) AppleWebKit/534.11.3 (KHTML, like Gecko) Version/4.0 Safari/534.11.3'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function safari()
|
|
||||||
{
|
|
||||||
$saf = self::numberBetween(531, 535) . '.' . self::numberBetween(1, 50) . '.' . self::numberBetween(1, 7);
|
|
||||||
|
|
||||||
if (Miscellaneous::boolean()) {
|
|
||||||
$ver = self::numberBetween(4, 5) . '.' . self::numberBetween(0, 1);
|
|
||||||
} else {
|
|
||||||
$ver = self::numberBetween(4, 5) . '.0.' . self::numberBetween(1, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mobileDevices = [
|
|
||||||
'iPhone; CPU iPhone OS',
|
|
||||||
'iPad; CPU OS',
|
|
||||||
];
|
|
||||||
|
|
||||||
$platforms = [
|
|
||||||
'(Windows; U; ' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
|
|
||||||
'(' . static::macPlatformToken() . ' rv:' . self::numberBetween(2, 6) . '.0; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
|
|
||||||
'(' . static::randomElement($mobileDevices) . ' ' . self::numberBetween(7, 8) . '_' . self::numberBetween(0, 2) . '_' . self::numberBetween(1, 2) . ' like Mac OS X; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/" . self::numberBetween(3, 4) . '.0.5 Mobile/8B' . self::numberBetween(111, 119) . " Safari/6$saf",
|
|
||||||
];
|
|
||||||
|
|
||||||
return 'Mozilla/5.0 ' . static::randomElement($platforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Opera user agent
|
|
||||||
*
|
|
||||||
* @example 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function opera()
|
|
||||||
{
|
|
||||||
$platforms = [
|
|
||||||
'(' . static::linuxPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.' . self::numberBetween(8, 12) . '.' . self::numberBetween(160, 355) . ' Version/' . self::numberBetween(10, 12) . '.00',
|
|
||||||
'(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.' . self::numberBetween(8, 12) . '.' . self::numberBetween(160, 355) . ' Version/' . self::numberBetween(10, 12) . '.00',
|
|
||||||
];
|
|
||||||
|
|
||||||
return 'Opera/' . self::numberBetween(8, 9) . '.' . self::numberBetween(10, 99) . ' ' . static::randomElement($platforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate Internet Explorer user agent
|
|
||||||
*
|
|
||||||
* @example 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function internetExplorer()
|
|
||||||
{
|
|
||||||
return 'Mozilla/5.0 (compatible; MSIE ' . self::numberBetween(5, 11) . '.0; ' . static::windowsPlatformToken() . '; Trident/' . self::numberBetween(3, 5) . '.' . self::numberBetween(0, 1) . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function windowsPlatformToken()
|
|
||||||
{
|
|
||||||
return static::randomElement(static::$windowsPlatformTokens);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function macPlatformToken()
|
|
||||||
{
|
|
||||||
return 'Macintosh; ' . static::randomElement(static::$macProcessor) . ' Mac OS X 10_' . self::numberBetween(5, 8) . '_' . self::numberBetween(0, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function iosMobileToken()
|
|
||||||
{
|
|
||||||
$iosVer = self::numberBetween(13, 15) . '_' . self::numberBetween(0, 2);
|
|
||||||
|
|
||||||
return 'iPhone; CPU iPhone OS ' . $iosVer . ' like Mac OS X';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function linuxPlatformToken()
|
|
||||||
{
|
|
||||||
return 'X11; Linux ' . static::randomElement(static::$linuxProcessor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Faker\Provider;
|
|
||||||
|
|
||||||
class Uuid extends Base
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Generate name based md5 UUID (version 3).
|
|
||||||
*
|
|
||||||
* @example '7e57d004-2b97-0e7a-b45f-5387367791cd'
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function uuid()
|
|
||||||
{
|
|
||||||
// fix for compatibility with 32bit architecture; each mt_rand call is restricted to 32bit
|
|
||||||
// two such calls will cause 64bits of randomness regardless of architecture
|
|
||||||
$seed = self::numberBetween(0, 2147483647) . '#' . self::numberBetween(0, 2147483647);
|
|
||||||
|
|
||||||
// Hash the seed and convert to a byte array
|
|
||||||
$val = md5($seed, true);
|
|
||||||
$byte = array_values(unpack('C16', $val));
|
|
||||||
|
|
||||||
// extract fields from byte array
|
|
||||||
$tLo = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) | $byte[3];
|
|
||||||
$tMi = ($byte[4] << 8) | $byte[5];
|
|
||||||
$tHi = ($byte[6] << 8) | $byte[7];
|
|
||||||
$csLo = $byte[9];
|
|
||||||
$csHi = $byte[8] & 0x3f | (1 << 7);
|
|
||||||
|
|
||||||
// correct byte order for big edian architecture
|
|
||||||
if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {
|
|
||||||
$tLo = (($tLo & 0x000000ff) << 24) | (($tLo & 0x0000ff00) << 8)
|
|
||||||
| (($tLo & 0x00ff0000) >> 8) | (($tLo & 0xff000000) >> 24);
|
|
||||||
$tMi = (($tMi & 0x00ff) << 8) | (($tMi & 0xff00) >> 8);
|
|
||||||
$tHi = (($tHi & 0x00ff) << 8) | (($tHi & 0xff00) >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply version number
|
|
||||||
$tHi &= 0x0fff;
|
|
||||||
$tHi |= (3 << 12);
|
|
||||||
|
|
||||||
// cast to string
|
|
||||||
return sprintf(
|
|
||||||
'%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x',
|
|
||||||
$tLo,
|
|
||||||
$tMi,
|
|
||||||
$tHi,
|
|
||||||
$csHi,
|
|
||||||
$csLo,
|
|
||||||
$byte[10],
|
|
||||||
$byte[11],
|
|
||||||
$byte[12],
|
|
||||||
$byte[13],
|
|
||||||
$byte[14],
|
|
||||||
$byte[15],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user