mc-cms-namelessmc/core/classes/Core/Instanceable.php
tadhgboyle 0c80570609
Enable StyleCI (#3475)
* 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>
2024-03-09 11:19:55 +00:00

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();
}
}