PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.5.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.5.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / woocommerce / action-scheduler / classes / ActionScheduler_Versions.php

ActionScheduler_Versions.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.5.4, at vendor/woocommerce/action-scheduler/classes/ActionScheduler_Versions.php

78 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_Versions
5 */
6 class ActionScheduler_Versions {
7 /**
8 * @var ActionScheduler_Versions
9 */
10 private static $instance = NULL;
11
12 /** @var array<string, callable> */
13 private $versions = array();
14
15 /**
16 * Register version's callback.
17 *
18 * @param string $version_string Action Scheduler version.
19 * @param callable $initialization_callback Callback to initialize the version.
20 */
21 public function register( $version_string, $initialization_callback ) {
22 if ( isset($this->versions[$version_string]) ) {
23 return FALSE;
24 }
25 $this->versions[$version_string] = $initialization_callback;
26 return TRUE;
27 }
28
29 /**
30 * Get all versions.
31 */
32 public function get_versions() {
33 return $this->versions;
34 }
35
36 /**
37 * Get latest version registered.
38 */
39 public function latest_version() {
40 $keys = array_keys($this->versions);
41 if ( empty($keys) ) {
42 return false;
43 }
44 uasort( $keys, 'version_compare' );
45 return end($keys);
46 }
47
48 /**
49 * Get callback for latest registered version.
50 */
51 public function latest_version_callback() {
52 $latest = $this->latest_version();
53 if ( empty($latest) || !isset($this->versions[$latest]) ) {
54 return '__return_null';
55 }
56 return $this->versions[$latest];
57 }
58
59 /**
60 * @return ActionScheduler_Versions
61 * @codeCoverageIgnore
62 */
63 public static function instance() {
64 if ( empty(self::$instance) ) {
65 self::$instance = new self();
66 }
67 return self::$instance;
68 }
69
70 /**
71 * @codeCoverageIgnore
72 */
73 public static function initialize_latest_version() {
74 $self = self::instance();
75 call_user_func($self->latest_version_callback());
76 }
77 }
78