@@ -274,6 +274,29 @@ public function allowElement(string $element, array|string $allowedAttributes =
274
274
return $ clone ;
275
275
}
276
276
277
+ /**
278
+ * Configures the given elements as allowed.
279
+ *
280
+ * Allowed elements are elements the sanitizer should retain from the input.
281
+ *
282
+ * A list of allowed attributes for this element can be passed as a second argument.
283
+ * Passing "*" will allow all standard attributes on this element. By default, no
284
+ * attributes are allowed on the element.
285
+ *
286
+ * @param list<string> $elements
287
+ * @param list<string>|string $allowedAttributes
288
+ */
289
+ public function allowElements (array $ elements , array |string $ allowedAttributes = []): static
290
+ {
291
+ $ clone = clone $ this ;
292
+
293
+ foreach ($ elements as $ element ) {
294
+ $ clone = $ clone ->allowElement ($ element , $ allowedAttributes );
295
+ }
296
+
297
+ return $ clone ;
298
+ }
299
+
277
300
/**
278
301
* Configures the given element as blocked.
279
302
*
@@ -292,6 +315,23 @@ public function blockElement(string $element): static
292
315
return $ clone ;
293
316
}
294
317
318
+ /**
319
+ * Configures the given elements as blocked.
320
+ *
321
+ * Blocked elements are elements the sanitizer should remove from the input, but retain
322
+ * their children.
323
+ */
324
+ public function blockElements (array $ elements ): static
325
+ {
326
+ $ clone = clone $ this ;
327
+
328
+ foreach ($ elements as $ element ) {
329
+ $ clone = $ clone ->blockElement ($ element );
330
+ }
331
+
332
+ return $ clone ;
333
+ }
334
+
295
335
/**
296
336
* Configures the given element as dropped.
297
337
*
@@ -310,6 +350,29 @@ public function dropElement(string $element): static
310
350
return $ clone ;
311
351
}
312
352
353
+ /**
354
+ * Configures the given elements as dropped.
355
+ *
356
+ * Dropped elements are elements the sanitizer should remove from the input, including
357
+ * their children.
358
+ *
359
+ * Note: when using an empty configuration, all unknown elements are dropped
360
+ * automatically. This method let you drop elements that were allowed earlier
361
+ * in the configuration.
362
+ *
363
+ * @param list<string> $elements
364
+ */
365
+ public function dropElements (array $ elements ): static
366
+ {
367
+ $ clone = clone $ this ;
368
+
369
+ foreach ($ elements as $ element ) {
370
+ $ clone = $ clone ->dropElement ($ element );
371
+ }
372
+
373
+ return $ clone ;
374
+ }
375
+
313
376
/**
314
377
* Configures the given attribute as allowed.
315
378
*
@@ -339,6 +402,30 @@ public function allowAttribute(string $attribute, array|string $allowedElements)
339
402
return $ clone ;
340
403
}
341
404
405
+ /**
406
+ * Configures the given attributes as allowed.
407
+ *
408
+ * Allowed attributes are attributes the sanitizer should retain from the input.
409
+ *
410
+ * A list of allowed elements for these attributes can be passed as a second argument.
411
+ * Passing "*" will allow all currently allowed elements to use this attribute.
412
+ *
413
+ * To configure each attribute for a specific element, please use the allowAttribute method instead.
414
+ *
415
+ * @param list<string> $attributes
416
+ * @param list<string>|string $allowedElements
417
+ */
418
+ public function allowAttributes (array $ attributes , array |string $ allowedElements ): static
419
+ {
420
+ $ clone = clone $ this ;
421
+
422
+ foreach ($ attributes as $ attribute ) {
423
+ $ clone = $ clone ->allowAttribute ($ attribute , $ allowedElements );
424
+ }
425
+
426
+ return $ clone ;
427
+ }
428
+
342
429
/**
343
430
* Configures the given attribute as dropped.
344
431
*
@@ -367,6 +454,32 @@ public function dropAttribute(string $attribute, array|string $droppedElements):
367
454
return $ clone ;
368
455
}
369
456
457
+ /**
458
+ * Configures the given attributes as dropped.
459
+ *
460
+ * Dropped attributes are attributes the sanitizer should remove from the input.
461
+ *
462
+ * A list of elements on which to drop these attributes can be passed as a second argument.
463
+ * Passing "*" will drop this attribute from all currently allowed elements.
464
+ *
465
+ * Note: when using an empty configuration, all unknown attributes are dropped
466
+ * automatically. This method let you drop attributes that were allowed earlier
467
+ * in the configuration.
468
+ *
469
+ * @param list<string> $attributes
470
+ * @param list<string>|string $droppedElements
471
+ */
472
+ public function dropAttributes (array $ attributes , array |string $ droppedElements ): static
473
+ {
474
+ $ clone = clone $ this ;
475
+
476
+ foreach ($ attributes as $ attribute ) {
477
+ $ clone = $ clone ->dropAttribute ($ attribute , $ droppedElements );
478
+ }
479
+
480
+ return $ clone ;
481
+ }
482
+
370
483
/**
371
484
* Forcefully set the value of a given attribute on a given element.
372
485
*
0 commit comments