PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / trunk
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution vtrunk
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 / Preload / State / State_Entry.php

State_Entry.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution trunk, at src/Performance/Preload/State/State_Entry.php

100 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The State Entry Object. Use the State object to manipulate this.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Preload\State;
11
12 use InvalidArgumentException;
13 use SolidWP\Performance\Preload\State\Enums\Source;
14 use SolidWP\Performance\Preload\State\Enums\Status;
15
16 /**
17 * This object represents the current state of the preloader
18 * and is stored, retrieved and modified as the preloader changes.
19 *
20 * @see State
21 *
22 * @package SolidWP\Performance
23 */
24 final class State_Entry {
25
26 /**
27 * The unique ID of the current preloader.
28 *
29 * @var string
30 */
31 public string $id;
32
33 /**
34 * The source that started the preloader.
35 *
36 * @see Source
37 *
38 * @var string
39 */
40 public string $source;
41
42 /**
43 * The current status of the preloader.
44 *
45 * @see Status
46 *
47 * @var string
48 */
49 public string $status;
50
51 /**
52 * Whether we are force preloading the entire site.
53 *
54 * @var bool
55 */
56 public bool $force = false;
57
58 /**
59 * The human-readable duration set when the preloader is complete.
60 *
61 * @var string|null
62 */
63 public ?string $duration;
64
65 /**
66 * @param string $id The unique ID of the current preloader.
67 * @param string $source The source that started the preloader, e.g. web/cli.
68 * @param string $status The current status of the preloader.
69 * @param bool $force Whether we are force preloading the entire site.
70 * @param string|null $duration The human-readable duration set when the preloader is complete.
71 *
72 * @throws InvalidArgumentException If an invalid id, source or status is provided.
73 */
74 public function __construct(
75 string $id,
76 string $source,
77 string $status,
78 bool $force = false,
79 ?string $duration = null
80 ) {
81 if ( empty( $id ) ) {
82 throw new InvalidArgumentException( 'The $id argument cannot be empty.' );
83 }
84
85 if ( ! Source::is_valid( $source ) ) {
86 throw new InvalidArgumentException( 'Invalid $source argument.' );
87 }
88
89 if ( ! Status::is_valid( $status ) ) {
90 throw new InvalidArgumentException( 'Invalid $status argument.' );
91 }
92
93 $this->id = $id;
94 $this->source = $source;
95 $this->status = $status;
96 $this->force = $force;
97 $this->duration = $duration;
98 }
99 }
100