mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 17:20:02 +00:00
Cleaned up MainLogger registration and declared a typehint
Remove null hint from MainLogger::getLogger() so static analysis doesn't complain everywhere just make sure you register the logger before trying to use MainLogger::getLogger() on a different thread!
This commit is contained in:
parent
08b8debd78
commit
b5790d19bf
@ -38,9 +38,7 @@ class AsyncWorker extends Worker{
|
|||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
$this->registerClassLoader();
|
$this->registerClassLoader();
|
||||||
if(MainLogger::getLogger() === null){
|
$this->logger->registerStatic();
|
||||||
$this->logger->registerStatic();
|
|
||||||
}
|
|
||||||
|
|
||||||
gc_enable();
|
gc_enable();
|
||||||
ini_set("memory_limit", '-1');
|
ini_set("memory_limit", '-1');
|
||||||
|
@ -54,22 +54,22 @@ class MainLogger extends \AttachableThreadedLogger{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return MainLogger|null
|
* @return MainLogger
|
||||||
*/
|
*/
|
||||||
public static function getLogger(){
|
public static function getLogger() : MainLogger{
|
||||||
return static::$logger;
|
return static::$logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns the MainLogger instance to the {@link MainLogger#logger} static property. Because static properties are
|
* Assigns the MainLogger instance to the {@link MainLogger#logger} static property.
|
||||||
* thread-local, this must be called from the body of every Thread if you want the logger to be accessible via
|
*
|
||||||
* {@link MainLogger#getLogger}.
|
* WARNING: Because static properties are thread-local, this MUST be called from the body of every Thread if you
|
||||||
|
* want the logger to be accessible via {@link MainLogger#getLogger}.
|
||||||
*/
|
*/
|
||||||
public function registerStatic(){
|
public function registerStatic(){
|
||||||
if(static::$logger instanceof MainLogger){
|
if(static::$logger === null){
|
||||||
throw new \RuntimeException("MainLogger has been already registered");
|
static::$logger = $this;
|
||||||
}
|
}
|
||||||
static::$logger = $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emergency($message){
|
public function emergency($message){
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit ddac19dbbdd9e8b71611ab7fb91069619fcba6f9
|
Subproject commit 6daeb27e507323053e81d48b7f5742968829cfbc
|
Loading…
x
Reference in New Issue
Block a user