PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.0
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.0
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / classes / Traits / InstanceGetterTrait.php

InstanceGetterTrait.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.0, at classes/Traits/InstanceGetterTrait.php

42 lines 837 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Imagify\Traits;
3
4 /**
5 * Trait that simulates a singleton pattern.
6 * The idea is more to ease the instance retrieval than to prevent multiple instances.
7 * This is temporary, until we get a DI container.
8 *
9 * @since 1.9
10 * @since 1.9.4 Renamed into InstanceGetterTrait.
11 * @author Grégory Viguier
12 */
13 trait InstanceGetterTrait {
14
15 /**
16 * The "not-so-single" instance of the class.
17 *
18 * @var ?object
19 * @since 1.9
20 * @access protected
21 * @author Grégory Viguier
22 */
23 protected static $instance = null;
24
25 /**
26 * Get the main Instance.
27 *
28 * @since 1.9
29 * @access protected
30 * @author Grégory Viguier
31 *
32 * @return object Main instance.
33 */
34 public static function get_instance() {
35 if ( ! isset( static::$instance ) ) {
36 static::$instance = new static();
37 }
38
39 return static::$instance;
40 }
41 }
42