Promote some constructors

This commit is contained in:
Dylan K. Taylor
2022-05-17 22:34:58 +01:00
parent 8e767da29e
commit d4b7f66e15
30 changed files with 144 additions and 218 deletions

View File

@ -136,11 +136,7 @@ use const SORT_NUMERIC;
class NetworkSession{
private \PrefixedLogger $logger;
private Server $server;
private ?Player $player = null;
private NetworkSessionManager $manager;
private string $ip;
private int $port;
private ?PlayerInfo $info = null;
private ?int $ping = null;
@ -163,37 +159,31 @@ class NetworkSession{
* @phpstan-var \SplQueue<CompressBatchPromise>
*/
private \SplQueue $compressedQueue;
private Compressor $compressor;
private bool $forceAsyncCompression = true;
private PacketPool $packetPool;
private PacketSerializerContext $packetSerializerContext;
private ?InventoryManager $invManager = null;
private PacketSender $sender;
private PacketBroadcaster $broadcaster;
/**
* @var \Closure[]|ObjectSet
* @phpstan-var ObjectSet<\Closure() : void>
*/
private ObjectSet $disposeHooks;
public function __construct(Server $server, NetworkSessionManager $manager, PacketPool $packetPool, PacketSender $sender, PacketBroadcaster $broadcaster, Compressor $compressor, string $ip, int $port){
$this->server = $server;
$this->manager = $manager;
$this->sender = $sender;
$this->broadcaster = $broadcaster;
$this->ip = $ip;
$this->port = $port;
public function __construct(
private Server $server,
private NetworkSessionManager $manager,
private PacketPool $packetPool,
private PacketSender $sender,
private PacketBroadcaster $broadcaster,
private Compressor $compressor,
private string $ip,
private int $port
){
$this->logger = new \PrefixedLogger($this->server->getLogger(), $this->getLogPrefix());
$this->compressedQueue = new \SplQueue();
$this->compressor = $compressor;
$this->packetPool = $packetPool;
//TODO: allow this to be injected
$this->packetSerializerContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());

View File

@ -56,11 +56,9 @@ final class GlobalItemTypeDictionary{
return new self(new ItemTypeDictionary($params));
}
private ItemTypeDictionary $dictionary;
public function __construct(ItemTypeDictionary $dictionary){
$this->dictionary = $dictionary;
}
public function __construct(
private ItemTypeDictionary $dictionary
){}
public function getDictionary() : ItemTypeDictionary{ return $this->dictionary; }
}

View File

@ -27,13 +27,10 @@ use pocketmine\snooze\SleeperNotifier;
use raklib\server\ipc\InterThreadChannelWriter;
final class SnoozeAwarePthreadsChannelWriter implements InterThreadChannelWriter{
private \Threaded $buffer;
private SleeperNotifier $notifier;
public function __construct(\Threaded $buffer, SleeperNotifier $notifier){
$this->buffer = $buffer;
$this->notifier = $notifier;
}
public function __construct(
private \Threaded $buffer,
private SleeperNotifier $notifier
){}
public function write(string $str) : void{
$this->buffer[] = $str;