@@ -23,7 +23,7 @@ class PatternLabListener extends \PatternLab\Listener {
23
23
public function __construct () {
24
24
25
25
// add listener
26
- $ this ->addListener ("twigPatternLoader.customize " ,"fakeContent " );
26
+ $ this ->addListener ("patternData.dataLoaded " ,"fakeContent " );
27
27
28
28
// set-up locale
29
29
$ locale = Config::getOption ("faker.locale " );
@@ -38,6 +38,19 @@ public function __construct() {
38
38
39
39
}
40
40
41
+ /**
42
+ * Clean the passed option
43
+ * @param {String} the option to be cleaned
44
+ *
45
+ * @return {String} the cleaned option
46
+ */
47
+ private function clean ($ option ) {
48
+ $ option = trim ($ option );
49
+ $ option = (($ option [0 ] == '" ' ) || ($ option [0 ] == "' " )) ? substr ($ option , 1 ) : $ option ;
50
+ $ option = (($ option [strlen ($ option )-1 ] == '" ' ) || ($ option [strlen ($ option )-1 ] == "' " )) ? substr ($ option , 0 , -1 ) : $ option ;
51
+ return $ option ;
52
+ }
53
+
41
54
/**
42
55
* Go through data and replace any values that match items from the link.array
43
56
* @param {String} a string entry from the data to check for link.pattern
@@ -58,7 +71,7 @@ private function compareReplaceFaker($value) {
58
71
}
59
72
60
73
/**
61
- * Read in the data and process faker data
74
+ * Fake some content
62
75
*/
63
76
public function fakeContent () {
64
77
@@ -68,26 +81,47 @@ public function fakeContent() {
68
81
}
69
82
70
83
/**
71
- * Read in the data and process faker data
84
+ * Format the options and fake out the data
85
+ * @param {String} the name of the formatter
86
+ * @param {String} a string of options. separated by commas if appropriate
87
+ *
88
+ * @return {String} the formatted text
72
89
*/
73
90
public function formatOptionsAndFake ($ formatter , $ options ) {
74
91
75
92
if (($ formatter == "date " ) || ($ formatter == "time " )) {
93
+
94
+ // don't try to parse date or time options. cross our fingers
76
95
return $ this ->faker ->$ formatter ($ options );
96
+
77
97
} else {
98
+
99
+ // get explodey
78
100
$ options = explode (", " , $ options );
79
- if (count ($ options ) === 6 ) {
80
- return $ this ->faker ->$ formatter ($ options [0 ],$ options [1 ],$ options [2 ],$ options [3 ],$ options [4 ],$ options [5 ]);
81
- } else if (count ($ options ) === 5 ) {
82
- return $ this ->faker ->$ formatter ($ options [0 ],$ options [1 ],$ options [2 ],$ options [3 ],$ options [4 ]);
83
- } else if (count ($ options ) === 4 ) {
84
- return $ this ->faker ->$ formatter ($ options [0 ],$ options [1 ],$ options [2 ],$ options [3 ]);
85
- } else if (count ($ options ) === 3 ) {
86
- return $ this ->faker ->$ formatter ($ options [0 ],$ options [1 ],$ options [2 ]);
87
- } else if (count ($ options ) === 2 ) {
88
- return $ this ->faker ->$ formatter ($ options [0 ],$ options [1 ]);
101
+ $ count = count ($ options );
102
+
103
+ // clean up the options
104
+ $ option0 = $ this ->clean ($ options [0 ]);
105
+ $ option1 = isset ($ options [1 ]) ? $ this ->clean ($ options [1 ]) : "" ;
106
+ $ option2 = isset ($ options [2 ]) ? $ this ->clean ($ options [2 ]) : "" ;
107
+ $ option3 = isset ($ options [3 ]) ? $ this ->clean ($ options [3 ]) : "" ;
108
+ $ option4 = isset ($ options [4 ]) ? $ this ->clean ($ options [4 ]) : "" ;
109
+ $ option5 = isset ($ options [5 ]) ? $ this ->clean ($ options [5 ]) : "" ;
110
+ $ option6 = isset ($ options [6 ]) ? $ this ->clean ($ options [6 ]) : "" ;
111
+
112
+ // probably should have used a switch. i'm lazy
113
+ if ($ count === 6 ) {
114
+ return $ this ->faker ->$ formatter ($ option0 ,$ option1 ,$ option2 ,$ option3 ,$ option4 ,$ option5 );
115
+ } else if ($ count === 5 ) {
116
+ return $ this ->faker ->$ formatter ($ option0 ,$ option1 ,$ option2 ,$ option3 ,$ option4 );
117
+ } else if ($ count === 4 ) {
118
+ return $ this ->faker ->$ formatter ($ option0 ,$ option1 ,$ option2 ,$ option3 );
119
+ } else if ($ count === 3 ) {
120
+ return $ this ->faker ->$ formatter ($ option0 ,$ option1 ,$ option2 );
121
+ } else if ($ count === 2 ) {
122
+ return $ this ->faker ->$ formatter ($ option0 ,$ option1 );
89
123
} else {
90
- return $ this ->faker ->$ formatter ($ options [ 0 ] );
124
+ return $ this ->faker ->$ formatter ($ option0 );
91
125
}
92
126
}
93
127
0 commit comments