/var/www/html_fr/wp-content/plugins/yaymail/src/Utils/SingletonTrait.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
namespace YayMail\Utils;

trait 
SingletonTrait {
    private static 
$instance;

    public static function 
get_instance( ...$args ) {
        
$class get_called_class();
        if ( ! 
$class::$instance ) {
            
$class::$instance = new $class( ...$args );
        }

        return 
$class::$instance;
    }

    
/** Singletons should not be cloneable. */
    
protected function __clone() { }

    
/** Singletons should not be restorable from strings. */
    
public function __wakeup() {
        throw new 
\Exception'Cannot unserialize a singleton.' );
    }
}