-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatternGenerator.php
49 lines (46 loc) · 1.73 KB
/
PatternGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// ============================================================================
class PatternGenerator extends FlexDataGen {
/*
Produces a string based on the given pattern (analogous to sprintf()); each
placeholder in the pattern is generated by the corresponding generator in
the provided list of generators
*/
// ============================================================================
protected $generators;
// ------------------------------------------------------------------------
public function __construct(
$options = [/*
pattern: string (required)
generators: array (required)
unique: bool (optional) = false
*/]
) {
// ------------------------------------------------------------------------
parent::__construct($options);
$this->createGenerators();
}
// ------------------------------------------------------------------------
protected function createGenerators(
) {
// ------------------------------------------------------------------------
$this->generators = [];
foreach($this->options['generators'] as $generator) {
$this->generators[] = Helper::getInstance(
$generator['generator'],
$generator['options']
);
}
}
// ------------------------------------------------------------------------
protected function generateValue(
$row_no
) {
// ------------------------------------------------------------------------
$args = [];
foreach($this->generators as $generator) {
$args[] = $generator->getData(1)[0];
}
return sprintf($this->options['pattern'], ...$args);
}
}