PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.8.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.8.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Page_Cache / Meta / Sanitization / Collection.php

Collection.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.8.0, at src/Performance/Page_Cache/Meta/Sanitization/Collection.php

59 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * A collection of meta sanitizers.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Page_Cache\Meta\Sanitization;
11
12 use Countable;
13 use SolidWP\Performance\Page_Cache\Meta\Meta;
14 use SolidWP\Performance\Page_Cache\Meta\Sanitization\Contracts\Sanitizer;
15
16 /**
17 * A collection of meta sanitizers.
18 *
19 * @package SolidWP\Performance
20 */
21 final class Collection implements Countable {
22
23 /**
24 * @var Sanitizer[]
25 */
26 private array $sanitizers;
27
28 /**
29 * @param Sanitizer[] $sanitizers The meta sanitizers.
30 */
31 public function __construct( array $sanitizers ) {
32 $this->sanitizers = $sanitizers;
33 }
34
35 /**
36 * Run the Meta through the collection of sanitizers.
37 *
38 * @param Meta $meta The Meta object.
39 *
40 * @return Meta The sanitized Meta object.
41 */
42 public function sanitize( Meta $meta ): Meta {
43 return array_reduce(
44 $this->sanitizers,
45 static fn( Meta $carry, Sanitizer $sanitizer ) => $sanitizer->sanitize( $carry ),
46 $meta
47 );
48 }
49
50 /**
51 * The number of sanitizers in the collection.
52 *
53 * @return int
54 */
55 public function count(): int {
56 return count( $this->sanitizers );
57 }
58 }
59