@@ -212,44 +212,39 @@ protected function getDefaultFormats()
212212 private static function mergeFormats (array $ formats , array $ newFormats )
213213 {
214214 $ added = array ();
215+ $ integers = array ('flags ' , 'type ' );
216+ $ strings = array ('html ' , 'cli ' , 'function ' );
215217
218+ /* Sanitize the array so that we do not have to care later */
219+ foreach ($ newFormats as $ j => $ new ) {
220+ foreach ($ integers as $ name ) {
221+ if (! isset ($ new [$ name ])) {
222+ $ newFormats [$ j ][$ name ] = 0 ;
223+ }
224+ }
225+ foreach ($ strings as $ name ) {
226+ if (! isset ($ new [$ name ])) {
227+ $ newFormats [$ j ][$ name ] = '' ;
228+ }
229+ }
230+ }
231+
232+ /* Process changes to existing formats */
216233 foreach ($ formats as $ i => $ original ) {
217234 foreach ($ newFormats as $ j => $ new ) {
218- if (isset ($ new ['type ' ])
219- && $ new ['type ' ] === $ original ['type ' ]
220- && (
221- (
222- isset ($ new ['flags ' ])
223- && $ original ['flags ' ] === $ new ['flags ' ]
224- )
225- || (
226- !isset ($ new ['flags ' ])
227- && $ original ['flags ' ] == 0
228- )
229- )
235+ if ($ new ['type ' ] === $ original ['type ' ]
236+ && $ original ['flags ' ] === $ new ['flags ' ]
230237 ) {
231- $ formats [$ i ] = array (
232- 'type ' => $ original ['type ' ],
233- 'flags ' => isset ($ new ['flags ' ]) ? $ new ['flags ' ] : 0 ,
234- 'html ' => isset ($ new ['html ' ]) ? $ new ['html ' ] : '' ,
235- 'cli ' => isset ($ new ['cli ' ]) ? $ new ['cli ' ] : '' ,
236- 'function ' => isset ($ new ['function ' ]) ? $ new ['function ' ] : '' ,
237- );
238-
238+ $ formats [$ i ] = $ new ;
239239 $ added [] = $ j ;
240240 }
241241 }
242242 }
243243
244+ /* Add not already handled formats */
244245 foreach ($ newFormats as $ j => $ new ) {
245- if (!in_array ($ j , $ added ) && isset ($ new ['type ' ])) {
246- $ formats [] = array (
247- 'type ' => $ new ['type ' ],
248- 'flags ' => isset ($ new ['flags ' ]) ? $ new ['flags ' ] : 0 ,
249- 'html ' => isset ($ new ['html ' ]) ? $ new ['html ' ] : '' ,
250- 'cli ' => isset ($ new ['cli ' ]) ? $ new ['cli ' ] : '' ,
251- 'function ' => isset ($ new ['function ' ]) ? $ new ['function ' ] : '' ,
252- );
246+ if (! in_array ($ j , $ added )) {
247+ $ formats [] = $ new ;
253248 }
254249 }
255250
0 commit comments