1515use \PatternLab \Timer ;
1616
1717class Util {
18-
18+
1919 protected $ patternPaths = array ();
20-
20+
2121 /**
2222 * Set-up the pattern paths var
2323 */
2424 public function __construct ($ options ) {
25-
25+
2626 $ this ->patternPaths = $ options ["patternPaths " ];
27-
27+
2828 }
29-
29+
3030 /**
3131 * Helper function to find and replace the given parameters in a particular partial before handing it back to Mustache
3232 * @param {String} the file contents
@@ -66,7 +66,7 @@ public function findReplaceParameters($fileData, $parameters) {
6666 }
6767 return $ fileData ;
6868 }
69-
69+
7070 /**
7171 * Helper function for getting a Mustache template file name.
7272 * @param {String} the pattern type for the pattern
@@ -75,40 +75,40 @@ public function findReplaceParameters($fileData, $parameters) {
7575 * @return {Array} an array of rendered partials that match the given path
7676 */
7777 public function getFileName ($ name ,$ ext ) {
78-
78+
7979 $ fileName = "" ;
8080 $ dirSep = DIRECTORY_SEPARATOR ;
81-
81+
8282 // test to see what kind of path was supplied
8383 $ posDash = strpos ($ name ,"- " );
8484 $ posSlash = strpos ($ name ,$ dirSep );
85-
85+
8686 if (($ posSlash === false ) && ($ posDash !== false )) {
8787 $ fileName = $ this ->getPatternFileName ($ name );
8888 } else {
8989 $ fileName = $ name ;
9090 }
91-
91+
9292 if (substr ($ fileName , 0 - strlen ($ ext )) !== $ ext ) {
9393 $ fileName .= $ ext ;
9494 }
95-
95+
9696 return $ fileName ;
97-
97+
9898 }
99-
99+
100100 /**
101101 * Helper function to return the pattern file name
102102 * @param {String} the name of the pattern
103103 *
104104 * @return {String} the file path to the pattern
105105 */
106106 public function getPatternFileName ($ name ) {
107-
107+
108108 $ patternFileName = "" ;
109-
109+
110110 list ($ patternType ,$ pattern ) = $ this ->getPatternInfo ($ name );
111-
111+
112112 // see if the pattern is an exact match for patternPaths. if not iterate over patternPaths to find a likely match
113113 if (isset ($ this ->patternPaths [$ patternType ][$ pattern ])) {
114114 $ patternFileName = $ this ->patternPaths [$ patternType ][$ pattern ];
@@ -121,21 +121,21 @@ public function getPatternFileName($name) {
121121 }
122122 }
123123 }
124-
124+
125125 return $ patternFileName ;
126-
126+
127127 }
128-
128+
129129 /**
130130 * Helper function to return the parts of a partial name
131131 * @param {String} the name of the partial
132132 *
133133 * @return {Array} the pattern type and the name of the pattern
134134 */
135135 public function getPatternInfo ($ name ) {
136-
136+
137137 $ patternBits = explode ("- " ,$ name );
138-
138+
139139 $ i = 1 ;
140140 $ k = 2 ;
141141 $ c = count ($ patternBits );
@@ -145,32 +145,32 @@ public function getPatternInfo($name) {
145145 $ i ++;
146146 $ k ++;
147147 }
148-
148+
149149 $ patternBits = explode ("- " ,$ name ,$ k );
150150 $ pattern = $ patternBits [count ($ patternBits )-1 ];
151-
151+
152152 return array ($ patternType , $ pattern );
153-
153+
154154 }
155-
155+
156156 /**
157157 * Helper function for finding if a partial name has style modifier or parameters
158158 * @param {String} the pattern name
159159 *
160160 * @return {Array} an array containing just the partial name, a style modifier, and any parameters
161161 */
162162 public function getPartialInfo ($ partial ) {
163-
163+
164164 $ styleModifier = array ();
165165 $ parameters = array ();
166-
166+
167167 if (strpos ($ partial , "( " ) !== false ) {
168168 $ partialBits = explode ("( " ,$ partial ,2 );
169169 $ partial = trim ($ partialBits [0 ]);
170170 $ parametersString = substr ($ partialBits [1 ],0 ,(strlen ($ partialBits [1 ]) - strlen (strrchr ($ partialBits [1 ],") " ))));
171171 $ parameters = $ this ->parseParameters ($ parametersString );
172172 }
173-
173+
174174 if (strpos ($ partial , ": " ) !== false ) {
175175 $ partialBits = explode (": " ,$ partial ,2 );
176176 $ partial = $ partialBits [0 ];
@@ -181,19 +181,19 @@ public function getPartialInfo($partial) {
181181 }
182182 $ styleModifier = array ("styleModifier " => $ styleModifier );
183183 }
184-
184+
185185 return array ($ partial ,$ styleModifier ,$ parameters );
186-
186+
187187 }
188-
188+
189189 /**
190190 * Helper function to parse the parameters and return them as an array
191191 * @param {String} the parameter string
192192 *
193193 * @return {Array} the keys and values for the parameters
194194 */
195195 private function parseParameters ($ string ) {
196-
196+
197197 $ parameters = array ();
198198 $ arrayParameters = array ();
199199 $ arrayOptions = array ();
@@ -208,12 +208,12 @@ private function parseParameters($string) {
208208 $ keyBuffer = "" ;
209209 $ arrayKeyBuffer = "" ;
210210 $ strLength = strlen ($ string );
211-
211+
212212 for ($ i = 0 ; $ i < $ strLength ; $ i ++) {
213-
213+
214214 $ previousChar = $ char ;
215215 $ char = $ string [$ i ];
216-
216+
217217 if ($ inKey && !$ betweenDQuotes && !$ betweenSQuotes && (($ char == "\"" ) || ($ char == "' " ))) {
218218 // if inKey, a quote, and betweenQuotes is false ignore quote, set betweenQuotes to true and empty buffer to kill spaces
219219 ($ char == "\"" ) ? ($ betweenDQuotes = true ) : ($ betweenSQuotes = true );
@@ -300,18 +300,18 @@ private function parseParameters($string) {
300300 $ buffer .= $ char ;
301301 } else if (!$ inValue && !$ inKey && ($ char == ", " )) {
302302 // if inValue is false, inKey false, and a comma set inKey true
303- if ($ inArray && !$ inOption ) {
303+ if ($ inArray && !$ inOption ) {
304304 // don't do anything
305305 } else {
306306 $ inKey = true ;
307307 }
308-
308+
309309 }
310310 }
311-
311+
312312 return $ parameters ;
313-
313+
314314 }
315-
315+
316316
317317}
0 commit comments