2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Util;
|
|
|
|
|
|
|
|
/**
|
2017-08-31 11:32:49 +02:00
|
|
|
* Classe astratta per la generazione di oggetti istanziabili una singola volta.
|
|
|
|
*
|
2017-08-04 16:28:16 +02:00
|
|
|
* @since 2.3
|
|
|
|
*/
|
2017-08-07 13:07:18 +02:00
|
|
|
abstract class Singleton
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2017-08-31 11:32:49 +02:00
|
|
|
/** @var Util\Singleton Oggetti istanziati */
|
2017-08-07 13:07:18 +02:00
|
|
|
protected static $instance = [];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-08-31 11:32:49 +02:00
|
|
|
/**
|
|
|
|
* Protected constructor to prevent creating a new instance of the <b>Singleton</b> via the `new` operator from outside of this class.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
protected function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restituisce l'istanza della classe in oggetto.
|
|
|
|
*
|
|
|
|
* @return Singleton
|
|
|
|
*/
|
|
|
|
public static function getInstance()
|
|
|
|
{
|
2017-08-31 11:32:49 +02:00
|
|
|
$class = get_called_class();
|
2017-08-07 13:07:18 +02:00
|
|
|
|
2017-08-28 12:16:14 +02:00
|
|
|
if (!isset(self::$instance[$class])) {
|
2017-08-07 13:07:18 +02:00
|
|
|
self::$instance[$class] = new static();
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
return self::$instance[$class];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-08-31 11:32:49 +02:00
|
|
|
/**
|
|
|
|
* Private clone method to prevent cloning of the instance of the <b>Singleton</b> instance.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
private function __clone()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-31 11:32:49 +02:00
|
|
|
/**
|
|
|
|
* Private unserialize method to prevent unserializing of the <b>Singleton</b> instance.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
private function __wakeup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|