\Phabstractic\PatternsSingletonTrait

The SingletonTrait trait

Encapsulates all the necessary functions to implement a singleton static class.

CHANGELOG

1.0: Documented SingletonTrait - May 4th, 2013 2.0: Reproduced Singleton for Primus - April 2nd, 2015 2.0.1: Un-finalized constructor function for objects requiring public constructor 2.0.2: Used local version of RunTimeException - April 11th, 2015 3.0: formatted for inclusion in phabstractic - July 7th, 2016

Summary

Methods
Properties
Constants
hardened()
instantiate()
No public properties found
No constants found
init()
$instance
N/A
__construct()
__clone()
No private properties found
N/A

Properties

$instance

$instance : mixed

The single instance of the class

Type

mixed — The singular instance

Methods

hardened()

hardened() : boolean

Test if the instance already exists

If it exists then it can't be instantiated with arguments

Returns

boolean —

True if instantiated

instantiate()

instantiate() : mixed

Gets The Singular Instance of the Singleton

This can be called with an array of 'options' (those really are supplied to the given instance). If there's an attempt to 'reconfigure' the singleton instance with new options a RuntimeException is thrown.

Throws

\Phabstractic\Patterns\Phabstractic\Patterns\Exception\RuntimeException

when instance is already defined and configured when given new configuration options

Returns

mixed —

The instance of the singleton class, the class itself

init()

init() 

Singleton Instance Construction Function

This is the method that will be overriden to configure the instance

__construct()

__construct() 

Private Constructor

Prevents instantiation using 'new'. To provide a constructor on a containing class use init()

__clone()

__clone() 

You don't clone a singleton