mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
* Create StyleCI config file * Disable `phpdoc_separation` * Apply fixes from StyleCI (#3476) Co-authored-by: StyleCI Bot <bot@styleci.io> * style: styleci fixes --------- Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Sam <samerton@users.noreply.github.com>
30 lines
689 B
PHP
30 lines
689 B
PHP
<?php
|
|
|
|
/**
|
|
* Allows classes to extend this to make singleton instances easily.
|
|
*
|
|
* @package NamelessMC\Core
|
|
* @author Aberdeener
|
|
* @version 2.0.0-pr13
|
|
* @license MIT
|
|
*/
|
|
class Instanceable
|
|
{
|
|
/**
|
|
* Stores instances of classes with their class name as key.
|
|
*
|
|
* @var array<class-string, static>
|
|
*/
|
|
private static array $_instances = [];
|
|
|
|
/**
|
|
* Get or make an instance of the class this was called on.
|
|
*
|
|
* @return static Instance of the class this was called on.
|
|
*/
|
|
final public static function getInstance()
|
|
{
|
|
/** @phpstan-ignore-next-line */
|
|
return self::$_instances[static::class] ??= new static();
|
|
}
|
|
}
|