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 / Cron / Schedule_Collection.php

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

68 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Holds a collection of schedule objects.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Cron;
11
12 /**
13 * Holds a collection of schedule objects.
14 *
15 * @package SolidWP\Performance
16 */
17 final class Schedule_Collection {
18
19 /**
20 * @var array<string, Schedule>
21 */
22 private array $schedules;
23
24 /**
25 * @param Schedule ...$schedules The schedule objects.
26 */
27 public function __construct( Schedule ...$schedules ) {
28 foreach ( $schedules as $schedule ) {
29 $this->schedules[ $schedule->name() ] = $schedule;
30 }
31 }
32
33 /**
34 * Get all schedules in the collection.
35 *
36 * @return array<string, Schedule>
37 */
38 public function all(): array {
39 return $this->schedules;
40 }
41
42 /**
43 * Get the schedules formatted for the cron_schedules filter.
44 *
45 * @return array<array<string, array{interval: int, display: string}>>
46 */
47 public function to_array(): array {
48 return array_reduce(
49 $this->all(),
50 function ( array $carry, Schedule $schedule ) {
51 return array_merge( $carry, $schedule->get() );
52 },
53 []
54 );
55 }
56
57 /**
58 * Retrieve a specific schedule by name.
59 *
60 * @param string $name The schedule name.
61 *
62 * @return Schedule|null
63 */
64 public function get( string $name ): ?Schedule {
65 return $this->schedules[ $name ] ?? null;
66 }
67 }
68