Files
torebki-fabiola.pl/wp-content/plugins/beapi-maintenance-mode/classes/singleton.php
2026-03-05 13:07:40 +01:00

49 lines
798 B
PHP

<?php namespace BEAPI\Maintenance_Mode;
trait Singleton {
/**
* @var self
*/
protected static $instance;
/**
* @return self
*/
final public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new static;
}
return self::$instance;
}
/**
* Constructor protected from the outside
*/
final private function __construct() {
$this->init();
}
/**
* Add init function by default
* Implement this method in your child class
* If you want to have actions send at construct
*/
protected function init() {}
/**
* prevent the instance from being cloned
*
* @return void
*/
final private function __clone() {
}
/**
* prevent from being unserialized
*
* @return void
*/
final private function __wakeup() {}
}