oltrematica/laravel-fake-parking
Composer 安装命令:
composer require oltrematica/laravel-fake-parking
包简介
Fake parking driver for oltrematica/laravel-parking-hub: returns random-but-stable parking outcomes for demo environments without any external API.
README 文档
README
Driver di parcheggio fake per oltrematica/laravel-parking-hub.
Pensato per ambienti demo: senza alcuna API esterna, letta una targa restituisce un
esito stabile-per-targa che l'hub rende come pallino verde / fucsia / rosso.
Requisiti
- PHP
^8.3 oltrematica/laravel-parking-hub(fornisce contratto, DTO ed enum)
Installazione
composer require oltrematica/laravel-fake-parking
Il ServiceProvider è auto-registrato (package discovery). Per pubblicare il file di
configurazione di riferimento:
php artisan vendor:publish --tag=fake-parking-config
Esiti
| Esito | Peso default | Significato | Come è costruito |
|---|---|---|---|
| 🟢 Verde | 65 | OK, sforamento tollerabile | Parcheggio valido ora (overflow 0%) |
| 🔴 Rosso | 20 | Violazione significativa | Parcheggio scaduto, overflow > 50% |
| 🟣 Fucsia | 3 | Avvertenza, sforamento moderato | Parcheggio scaduto, 10% < overflow ≤ 50% |
Il colore non è un campo della risposta: l'hub lo calcola a valle dall'overflow_percentage
ricavato da ParkingValidationResponseData::findClosestParkingRange(). Questo driver fabbrica
quindi un parcheggio le cui date producono l'overflow corrispondente all'esito estratto.
La whitelist non è producibile da un provider e quindi non è gestita.
Registrazione come driver
Nel config/parking-hub.php dell'applicazione, aggiungi una voce nei drivers:
'fake' => [ 'class' => \Oltrematica\FakeParking\Support\FakeParkingValidator::class, ],
Con la sola chiave class valgono i default interni (65 / 20 / 3, deterministico,
durata 30–180 min). Per usarlo come driver predefinito: PARKING_HUB_DEFAULT_DRIVER=fake.
Configurazione
Opzioni disponibili
| Chiave | Tipo | Default | Vincoli |
|---|---|---|---|
probabilities.green |
int |
65 |
intero ≥ 0 |
probabilities.red |
int |
20 |
intero ≥ 0 |
probabilities.fuchsia |
int |
3 |
intero ≥ 0; somma dei tre > 0 |
deterministic |
bool |
true |
— |
duration.min |
int (minuti) |
30 |
≥ 1 |
duration.max |
int (minuti) |
180 |
≥ duration.min |
Config malformata (peso negativo, somma dei pesi = 0, min > max) lancia
InvalidArgumentException alla costruzione del driver.
Le percentuali (pesi)
green / red / fuchsia sono pesi e vengono normalizzati a 100% sulla loro
somma — non devono per forza sommare a 100:
| green | red | fuchsia | somma | 🟢 verde | 🔴 rosso | 🟣 fucsia |
|---|---|---|---|---|---|---|
| 65 | 20 | 3 | 88 | 73,9% | 22,7% | 3,4% |
| 70 | 25 | 5 | 100 | 70,0% | 25,0% | 5,0% |
| 50 | 50 | 0 | 100 | 50,0% | 50,0% | 0,0% |
Come impostarle
Hai due strade.
A) Direttamente nella voce del driver (consigliata):
'fake' => [ 'class' => \Oltrematica\FakeParking\Support\FakeParkingValidator::class, 'probabilities' => ['green' => 65, 'red' => 20, 'fuchsia' => 3], 'deterministic' => true, 'duration' => ['min' => 30, 'max' => 180], ],
B) Tramite .env usando il config pubblicato del pacchetto:
FAKE_PARKING_PROB_GREEN=65 FAKE_PARKING_PROB_RED=20 FAKE_PARKING_PROB_FUCHSIA=3 FAKE_PARKING_DETERMINISTIC=true FAKE_PARKING_DURATION_MIN=30 FAKE_PARKING_DURATION_MAX=180
⚠️ Importante: a runtime il
ParkingHubManagerpassa al driver l'arraydrivers.fakediparking-hub.php, nonconfig('fake-parking'). Quindi, per far valere i valori del.env/del config pubblicato, vanno collegati esplicitamente nella voce del driver:'fake' => array_merge( ['class' => \Oltrematica\FakeParking\Support\FakeParkingValidator::class], config('fake-parking'), ),
Determinismo
Con deterministic = true (default) l'esito è stabile per targa: il seed è derivato
dall'hash della targa normalizzata (strtoupper(trim($plate))), quindi la stessa targa
produce sempre lo stesso esito (anche tra istanze/richieste diverse). Con false ogni
lettura estrae un nuovo esito casuale.
Uso
use Oltrematica\ParkingHub\Facades\ParkingHub; use Carbon\Carbon; $response = ParkingHub::driver('fake')->checkPlate('AA123BB', Carbon::now()); $response->responseStatus; // sempre ProviderInteractionStatus::SUCCESS_OK $response->isValid; // true solo per l'esito "verde" $response->parkingEndTime; // fine del parcheggio fabbricato $response->purchasedParkings; // 1 elemento (start/end del parcheggio)
Se $verificationDateTime è null, viene usato Carbon::now().
Testing
composer test # Pest composer analyse # PHPStan (level max) composer format # Pint
Licenza
MIT.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-29