Skip to content

Commit 803efe6

Browse files
committed
feat: add a way to generate fake data in static template
1 parent a5d51c9 commit 803efe6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

components/StaticTemplatesBundle/lib/Faker/Generators/DeterminedAssociativeArrayGenerator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ public function support(string $type): bool
2626

2727
public function generate(string $type): array
2828
{
29+
$matches = [];
2930
preg_match('/^\{(.*)\}$/', $type, $matches);
30-
$els = explode(',', $matches[1]) ?? [];
31+
32+
$els = [];
33+
preg_match_all('/(\w+):([^,\s{\[]+|{\S+}(\[(\d+)?\])?|\[\S+\])/', $matches[1] ?? '', $els, PREG_SET_ORDER);
34+
3135
$items = [];
3236
foreach ($els as $el) {
33-
[$elKey, $elType] = explode(':', $el);
37+
[,$elKey, $elType] = $el;
3438
$items[trim($elKey)] = $this->generator->generate(trim($elType));
3539
}
3640

0 commit comments

Comments
 (0)