Merge branch 'release/3.2' into release/3.3

This commit is contained in:
Dylan K. Taylor 2018-10-31 18:55:18 +00:00
commit 2d88058710
3 changed files with 24 additions and 1 deletions

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\scheduler;
use pocketmine\utils\Utils;
abstract class Task{
/** @var TaskHandler */
@ -46,6 +48,10 @@ abstract class Task{
return -1;
}
public function getName() : string{
return Utils::getNiceClassName($this);
}
/**
* @param TaskHandler|null $taskHandler
*/

View File

@ -66,7 +66,7 @@ class TaskHandler{
$this->taskId = $taskId;
$this->delay = $delay;
$this->period = $period;
$this->taskName = get_class($task);
$this->taskName = $task->getName();
$this->ownerName = $ownerName ?? "Unknown";
$this->timings = Timings::getScheduledTaskTimings($this, $period);
$this->task->setHandler($this);

View File

@ -52,6 +52,23 @@ class Utils{
}
}
/**
* Returns a readable identifier for the class of the given object. Sanitizes class names for closures.
*
* @param object $obj
*
* @return string
* @throws \ReflectionException
*/
public static function getNiceClassName(object $obj) : string{
$reflect = new \ReflectionClass($obj);
if($reflect->isAnonymous()){
return "anonymous@" . self::cleanPath($reflect->getFileName()) . "#L" . $reflect->getStartLine();
}
return $reflect->getName();
}
/**
* Gets this machine / server instance unique ID
* Returns a hash, the first 32 characters (or 16 if raw)