29 lines
871 B
PHP
29 lines
871 B
PHP
<?php
|
|
namespace Patchouli;
|
|
|
|
abstract class SingleInstance {
|
|
private static $instance = null;
|
|
|
|
public static function getInstance(): self {
|
|
if(self::$instance === null)
|
|
self::$instance = new static;
|
|
return self::$instance;
|
|
}
|
|
|
|
public function __call(string $name, array $args) {
|
|
if($name[0] === '_') {
|
|
trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR);
|
|
return;
|
|
}
|
|
return $this->{'_' . $name}(...$args);
|
|
}
|
|
|
|
public static function __callStatic(string $name, array $args) {
|
|
if($name[0] === '_') {
|
|
trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR);
|
|
return;
|
|
}
|
|
return self::getInstance()->{'_' . $name}(...$args);
|
|
}
|
|
}
|