This repository has been archived on 2023-10-21. You can view files and clone it, but cannot push or open issues or pull requests.
patchouli/src/SingleInstance.php
2020-12-23 01:45:39 +00:00

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