@@ -23,7 +23,7 @@ class PatternLabListener extends \PatternLab\Listener {
2323 public function __construct () {
2424
2525 // add listener
26- $ this ->addListener ("twigPatternLoader.customize " ,"fakeContent " );
26+ $ this ->addListener ("patternData.dataLoaded " ,"fakeContent " );
2727
2828 // set-up locale
2929 $ locale = Config::getOption ("faker.locale " );
@@ -38,6 +38,19 @@ public function __construct() {
3838
3939 }
4040
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+
4154 /**
4255 * Go through data and replace any values that match items from the link.array
4356 * @param {String} a string entry from the data to check for link.pattern
@@ -58,7 +71,7 @@ private function compareReplaceFaker($value) {
5871 }
5972
6073 /**
61- * Read in the data and process faker data
74+ * Fake some content
6275 */
6376 public function fakeContent () {
6477
@@ -68,26 +81,47 @@ public function fakeContent() {
6881 }
6982
7083 /**
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
7289 */
7390 public function formatOptionsAndFake ($ formatter , $ options ) {
7491
7592 if (($ formatter == "date " ) || ($ formatter == "time " )) {
93+
94+ // don't try to parse date or time options. cross our fingers
7695 return $ this ->faker ->$ formatter ($ options );
96+
7797 } else {
98+
99+ // get explodey
78100 $ 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 );
89123 } else {
90- return $ this ->faker ->$ formatter ($ options [ 0 ] );
124+ return $ this ->faker ->$ formatter ($ option0 );
91125 }
92126 }
93127
0 commit comments