🔖 Version 1.0.0-beta
This commit is contained in:
parent
c93a06972b
commit
460a811554
26 changed files with 2480 additions and 771 deletions
50
Civi/Mailinglistsync/Singleton.php
Normal file
50
Civi/Mailinglistsync/Singleton.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Civi\Mailinglistsync;
|
||||
|
||||
use Civi\Mailinglistsync\Exceptions\ContactSyncException;
|
||||
use Civi\Mailinglistsync\Exceptions\MailinglistException;
|
||||
use CRM_Mailinglistsync_ExtensionUtil as E;
|
||||
|
||||
trait Singleton {
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Protect singleton from being instantiated.
|
||||
*/
|
||||
protected function __construct() {}
|
||||
|
||||
/**
|
||||
* Protect singleton from being cloned.
|
||||
*/
|
||||
protected function __clone() {}
|
||||
|
||||
/**
|
||||
* Protect unserialize method to prevent cloning of the instance.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
throw new ContactSyncException(
|
||||
"Cannot unserialize a singleton.",
|
||||
MailinglistException::ERROR_CODE_UNSERIALIZE_SINGLETON
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singleton instance.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue