Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
73.33% |
11 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_Sitemap_Buffer_Factory | |
84.62% |
11 / 13 |
|
0.00% |
0 / 1 |
7.18 | |
0.00% |
0 / 1 |
| create | |
84.62% |
11 / 13 |
|
0.00% |
0 / 1 |
7.18 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Factory class for creating sitemap buffers. |
| 4 | * |
| 5 | * @since 14.6 |
| 6 | * @package automattic/jetpack |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit( 0 ); |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Creates the appropriate sitemap buffer based on available PHP extensions. |
| 15 | * |
| 16 | * @since 14.6 |
| 17 | */ |
| 18 | class Jetpack_Sitemap_Buffer_Factory { |
| 19 | |
| 20 | /** |
| 21 | * Create a new sitemap buffer instance. |
| 22 | * |
| 23 | * @since 14.6 |
| 24 | * |
| 25 | * @param string $type The type of sitemap buffer ('page', 'image', 'video', etc.). |
| 26 | * @param int $item_limit The maximum number of items in the buffer. |
| 27 | * @param int $byte_limit The maximum number of bytes in the buffer. |
| 28 | * @param string $time The initial datetime of the buffer. |
| 29 | * |
| 30 | * @return Jetpack_Sitemap_Buffer|null The created buffer or null if type is invalid. |
| 31 | */ |
| 32 | public static function create( $type, $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) { |
| 33 | |
| 34 | /** |
| 35 | * Hook to allow for XMLWriter usage. |
| 36 | * |
| 37 | * Temporary filter to disallow XMLWriter usage. |
| 38 | * |
| 39 | * @since 14.7 |
| 40 | * @since 15.2 Update default to true. |
| 41 | * @module sitemaps |
| 42 | * |
| 43 | * @param bool $use_xmlwriter Whether to use XMLWriter. Current default is true. |
| 44 | */ |
| 45 | $use_xmlwriter = apply_filters( 'jetpack_sitemap_use_xmlwriter', true ); |
| 46 | |
| 47 | // First try XMLWriter if available |
| 48 | if ( $use_xmlwriter && class_exists( 'XMLWriter' ) ) { |
| 49 | $class_name = 'Jetpack_Sitemap_Buffer_' . ucfirst( $type ) . '_XMLWriter'; |
| 50 | if ( class_exists( $class_name ) ) { |
| 51 | return new $class_name( $item_limit, $byte_limit, $time ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Then try DOMDocument |
| 56 | if ( class_exists( 'DOMDocument' ) ) { |
| 57 | $class_name = 'Jetpack_Sitemap_Buffer_' . ucfirst( $type ); |
| 58 | if ( class_exists( $class_name ) ) { |
| 59 | return new $class_name( $item_limit, $byte_limit, $time ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Finally fall back to the basic implementation |
| 64 | $class_name = 'Jetpack_Sitemap_Buffer_' . ucfirst( $type ) . '_Fallback'; |
| 65 | if ( class_exists( $class_name ) ) { |
| 66 | return new $class_name( $item_limit, $byte_limit, $time ); |
| 67 | } |
| 68 | |
| 69 | return null; |
| 70 | } |
| 71 | } |