PluginProbe
Authorizer / 3.14.2
Authorizer v3.14.2
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / src / authorizer / abstract-class-singleton.php

abstract-class-singleton.php in Authorizer 3.14.2, at src/authorizer/abstract-class-singleton.php

53 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Authorizer
4 *
5 * @license GPL-2.0+
6 * @link https://github.com/uhm-coe/authorizer
7 * @package authorizer
8 */
9
10 namespace Authorizer;
11
12 /**
13 * Base class that all other classes extend (provides static accessor variable).
14 */
15 abstract class Singleton {
16 /**
17 * Instances of any child classes.
18 *
19 * @var object[] Array of objects of any instantiated child classes.
20 */
21 private static $instances = array();
22
23
24 /**
25 * Access the singleton instance of the requested class (create a new one if
26 * needed).
27 *
28 * @return object Object of the requested class.
29 */
30 public static function get_instance() {
31 $class = get_called_class();
32 if ( ! isset( self::$instances[ $class ] ) ) {
33 self::$instances[ $class ] = new static();
34 }
35
36 return self::$instances[ $class ];
37 }
38
39
40 /**
41 * Disable constructor to prevent creation of multiple instances (protected
42 * so we can create a new instance within get_instance() though).
43 */
44 protected function __construct() {
45 }
46
47 /**
48 * Disable cloning of singletons.
49 */
50 private function __clone() {
51 }
52 }
53