PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.12
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.12
4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 All 135 releases
optimole-wp / inc / v2 / PageProfiler / Storage / Base.php

Base.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 4.2.12, at inc/v2/PageProfiler/Storage/Base.php

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace OptimoleWP\PageProfiler\Storage;
4
5 /**
6 * Abstract base class for storage implementations.
7 *
8 * This class defines the interface for storage operations that concrete
9 * implementations must provide.
10 */
11 abstract class Base {
12
13 /**
14 * Store data with the given key.
15 *
16 * @param string $key The unique identifier for the data.
17 * @param array $data The data to store.
18 */
19 abstract public function store( string $key, array $data );
20
21 /**
22 * Retrieve data by key.
23 *
24 * @param string $key The unique identifier for the data to retrieve.
25 * @return array<string, mixed>|false The stored data or false if not found.
26 */
27 abstract public function get( string $key );
28
29 /**
30 * Coerce a stored profiler payload to an array.
31 *
32 * Object-cache backends that JSON-decode without associative arrays return stdClass.
33 * Nested objects (e.g. `af`, `bg`, `lcp`) are converted recursively.
34 *
35 * @param mixed $value Raw storage value.
36 * @return array<string|int, mixed>|false
37 */
38 public static function normalize_value( $value ) {
39 if ( false === $value || null === $value ) {
40 return false;
41 }
42
43 if ( is_object( $value ) ) {
44 $value = get_object_vars( $value );
45 }
46
47 if ( ! is_array( $value ) ) {
48 return false;
49 }
50
51 foreach ( $value as $key => $item ) {
52 if ( is_object( $item ) || is_array( $item ) ) {
53 $normalized_item = self::normalize_value( $item );
54 $value[ $key ] = ( false !== $normalized_item ) ? $normalized_item : [];
55 }
56 }
57
58 return $value;
59 }
60
61 /**
62 * Delete data by key.
63 *
64 * @param string $key The unique identifier for the data to delete.
65 */
66 abstract public function delete( string $key );
67
68 /**
69 * Delete all stored data.
70 */
71 abstract public function delete_all();
72 }
73