Transition to spl_object_id()

This commit is contained in:
Dylan K. Taylor 2019-01-26 15:06:38 +00:00
parent 1e708db26c
commit d378371cc8
15 changed files with 59 additions and 59 deletions

View File

@ -156,7 +156,7 @@ use function microtime;
use function min;
use function preg_match;
use function round;
use function spl_object_hash;
use function spl_object_id;
use function strlen;
use function strpos;
use function strtolower;
@ -3247,7 +3247,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @return int
*/
public function getWindowId(Inventory $inventory) : int{
return $this->windows[spl_object_hash($inventory)] ?? ContainerIds::NONE;
return $this->windows[spl_object_id($inventory)] ?? ContainerIds::NONE;
}
/**
@ -3297,7 +3297,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
$this->windowIndex[$cnt] = $inventory;
$this->windows[spl_object_hash($inventory)] = $cnt;
$this->windows[spl_object_id($inventory)] = $cnt;
if($inventory->open($this)){
if($isPermanent){
$this->permanentWindows[$cnt] = true;
@ -3319,7 +3319,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @throws \InvalidArgumentException if trying to remove a fixed inventory window without the `force` parameter as true
*/
public function removeWindow(Inventory $inventory, bool $force = false){
$id = $this->windows[$hash = spl_object_hash($inventory)] ?? null;
$id = $this->windows[$hash = spl_object_id($inventory)] ?? null;
if($id !== null and !$force and isset($this->permanentWindows[$id])){
throw new \InvalidArgumentException("Cannot remove fixed window $id (" . get_class($inventory) . ") from " . $this->getName());

View File

@ -134,7 +134,6 @@ use function register_shutdown_function;
use function rename;
use function round;
use function sleep;
use function spl_object_hash;
use function spl_object_id;
use function sprintf;
use function str_repeat;
@ -1436,7 +1435,7 @@ class Server{
foreach(explode(";", $permissions) as $permission){
foreach(PermissionManager::getInstance()->getPermissionSubscriptions($permission) as $permissible){
if($permissible instanceof CommandSender and $permissible->hasPermission($permission)){
$recipients[spl_object_hash($permissible)] = $permissible; // do not send messages directly, or some might be repeated
$recipients[spl_object_id($permissible)] = $permissible; // do not send messages directly, or some might be repeated
}
}
}
@ -1900,14 +1899,14 @@ class Server{
}
public function addPlayer(Player $player){
$this->players[spl_object_hash($player)] = $player;
$this->players[spl_object_id($player)] = $player;
}
/**
* @param Player $player
*/
public function removePlayer(Player $player){
unset($this->players[spl_object_hash($player)]);
unset($this->players[spl_object_id($player)]);
}
public function addOnlinePlayer(Player $player){

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine;
use function spl_object_hash;
use function spl_object_id;
class ThreadManager extends \Volatile{
@ -46,7 +46,7 @@ class ThreadManager extends \Volatile{
*/
public function add($thread){
if($thread instanceof Thread or $thread instanceof Worker){
$this->{spl_object_hash($thread)} = $thread;
$this->{spl_object_id($thread)} = $thread;
}
}
@ -55,7 +55,7 @@ class ThreadManager extends \Volatile{
*/
public function remove($thread){
if($thread instanceof Thread or $thread instanceof Worker){
unset($this->{spl_object_hash($thread)});
unset($this->{spl_object_id($thread)});
}
}

View File

@ -28,7 +28,7 @@ use pocketmine\plugin\RegisteredListener;
use pocketmine\utils\Utils;
use function array_fill_keys;
use function in_array;
use function spl_object_hash;
use function spl_object_id;
class HandlerList{
/**
@ -120,10 +120,10 @@ class HandlerList{
if(!in_array($listener->getPriority(), EventPriority::ALL, true)){
return;
}
if(isset($this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)])){
if(isset($this->handlerSlots[$listener->getPriority()][spl_object_id($listener)])){
throw new \InvalidStateException("This listener is already registered to priority {$listener->getPriority()} of event {$this->class}");
}
$this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)] = $listener;
$this->handlerSlots[$listener->getPriority()][spl_object_id($listener)] = $listener;
}
/**
@ -150,8 +150,8 @@ class HandlerList{
}
}
}elseif($object instanceof RegisteredListener){
if(isset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)])){
unset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)]);
if(isset($this->handlerSlots[$object->getPriority()][spl_object_id($object)])){
unset($this->handlerSlots[$object->getPriority()][spl_object_id($object)]);
}
}
}

View File

@ -37,7 +37,7 @@ use function array_slice;
use function count;
use function max;
use function min;
use function spl_object_hash;
use function spl_object_id;
abstract class BaseInventory implements Inventory{
@ -420,11 +420,11 @@ abstract class BaseInventory implements Inventory{
}
public function onOpen(Player $who) : void{
$this->viewers[spl_object_hash($who)] = $who;
$this->viewers[spl_object_id($who)] = $who;
}
public function onClose(Player $who) : void{
unset($this->viewers[spl_object_hash($who)]);
unset($this->viewers[spl_object_id($who)]);
}
public function onSlotChange(int $index, Item $before, bool $send) : void{

View File

@ -34,6 +34,7 @@ use function count;
use function get_class;
use function min;
use function spl_object_hash;
use function spl_object_id;
/**
* This InventoryTransaction only allows doing Transaction between one / two inventories
@ -85,7 +86,7 @@ class InventoryTransaction{
* @param InventoryAction $action
*/
public function addAction(InventoryAction $action) : void{
if(!isset($this->actions[$hash = spl_object_hash($action)])){
if(!isset($this->actions[$hash = spl_object_id($action)])){
$this->actions[$hash] = $action;
$action->onAddToTransaction($this);
}else{
@ -100,7 +101,7 @@ class InventoryTransaction{
* @param Inventory $inventory
*/
public function addInventory(Inventory $inventory) : void{
if(!isset($this->inventories[$hash = spl_object_hash($inventory)])){
if(!isset($this->inventories[$hash = spl_object_id($inventory)])){
$this->inventories[$hash] = $inventory;
}
}
@ -188,7 +189,7 @@ class InventoryTransaction{
}
foreach($list as $action){
unset($this->actions[spl_object_hash($action)]);
unset($this->actions[spl_object_id($action)]);
}
if(!$targetItem->equalsExact($sourceItem)){

View File

@ -27,7 +27,7 @@ use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\InventoryTransaction;
use pocketmine\item\Item;
use pocketmine\Player;
use function spl_object_hash;
use function spl_object_id;
/**
* Represents an action causing a change in an inventory slot.
@ -110,7 +110,7 @@ class SlotChangeAction extends InventoryAction{
*/
public function onExecuteSuccess(Player $source) : void{
$viewers = $this->inventory->getViewers();
unset($viewers[spl_object_hash($source)]);
unset($viewers[spl_object_id($source)]);
$this->inventory->sendSlot($this->inventorySlot, $viewers);
}

View File

@ -30,7 +30,7 @@ use pocketmine\event\server\NetworkInterfaceRegisterEvent;
use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\PacketPool;
use function spl_object_hash;
use function spl_object_id;
class Network{
/** @var NetworkInterface[] */
@ -105,7 +105,7 @@ class Network{
$ev->call();
if(!$ev->isCancelled()){
$interface->start();
$this->interfaces[$hash = spl_object_hash($interface)] = $interface;
$this->interfaces[$hash = spl_object_id($interface)] = $interface;
if($interface instanceof AdvancedNetworkInterface){
$this->advancedInterfaces[$hash] = $interface;
$interface->setNetwork($this);
@ -119,7 +119,7 @@ class Network{
*/
public function unregisterInterface(NetworkInterface $interface) : void{
(new NetworkInterfaceUnregisterEvent($interface))->call();
unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]);
unset($this->interfaces[$hash = spl_object_id($interface)], $this->advancedInterfaces[$hash]);
}
/**
@ -183,6 +183,6 @@ class Network{
}
public function scheduleSessionTick(NetworkSession $session) : void{
$this->updateSessions[spl_object_hash($session)] = $session;
$this->updateSessions[spl_object_id($session)] = $session;
}
}

View File

@ -42,7 +42,7 @@ use function addcslashes;
use function count;
use function implode;
use function rtrim;
use function spl_object_hash;
use function spl_object_id;
use function substr;
use function unserialize;
use const PTHREADS_INHERIT_CONSTANTS;
@ -121,14 +121,14 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
public function closeSession(string $identifier, string $reason) : void{
if(isset($this->sessions[$identifier])){
$session = $this->sessions[$identifier];
unset($this->identifiers[spl_object_hash($session)]);
unset($this->identifiers[spl_object_id($session)]);
unset($this->sessions[$identifier]);
$session->onClientDisconnect($reason);
}
}
public function close(NetworkSession $session, string $reason = "unknown reason") : void{
if(isset($this->identifiers[$h = spl_object_hash($session)])){
if(isset($this->identifiers[$h = spl_object_id($session)])){
unset($this->sessions[$this->identifiers[$h]]);
$this->interface->closeSession($this->identifiers[$h], $reason);
unset($this->identifiers[$h]);
@ -143,7 +143,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
public function openSession(string $identifier, string $address, int $port, int $clientID) : void{
$session = new NetworkSession($this->server, $this, $address, $port);
$this->sessions[$identifier] = $session;
$this->identifiers[spl_object_hash($session)] = $identifier;
$this->identifiers[spl_object_id($session)] = $identifier;
}
public function handleEncapsulated(string $identifier, EncapsulatedPacket $packet, int $flags) : void{
@ -227,7 +227,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
}
public function putPacket(NetworkSession $session, string $payload, bool $immediate = true) : void{
if(isset($this->identifiers[$h = spl_object_hash($session)])){
if(isset($this->identifiers[$h = spl_object_id($session)])){
$identifier = $this->identifiers[$h];
$pk = new EncapsulatedPacket();

View File

@ -26,7 +26,7 @@ namespace pocketmine\permission;
use pocketmine\plugin\Plugin;
use pocketmine\plugin\PluginException;
use pocketmine\timings\Timings;
use function spl_object_hash;
use function spl_object_id;
class PermissibleBase implements Permissible{
/** @var ServerOperator */
@ -117,7 +117,7 @@ class PermissibleBase implements Permissible{
}
$result = new PermissionAttachment($plugin, $this->parent ?? $this);
$this->attachments[spl_object_hash($result)] = $result;
$this->attachments[spl_object_id($result)] = $result;
if($name !== null and $value !== null){
$result->setPermission($name, $value);
}
@ -131,8 +131,8 @@ class PermissibleBase implements Permissible{
* @param PermissionAttachment $attachment
*/
public function removeAttachment(PermissionAttachment $attachment){
if(isset($this->attachments[spl_object_hash($attachment)])){
unset($this->attachments[spl_object_hash($attachment)]);
if(isset($this->attachments[spl_object_id($attachment)])){
unset($this->attachments[spl_object_id($attachment)]);
if(($ex = $attachment->getRemovalCallback()) !== null){
$ex->attachmentRemoved($attachment);
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\permission;
use pocketmine\timings\Timings;
use function count;
use function spl_object_hash;
use function spl_object_id;
class PermissionManager{
/** @var PermissionManager|null */
@ -146,7 +146,7 @@ class PermissionManager{
if(!isset($this->permSubs[$permission])){
$this->permSubs[$permission] = [];
}
$this->permSubs[$permission][spl_object_hash($permissible)] = $permissible;
$this->permSubs[$permission][spl_object_id($permissible)] = $permissible;
}
/**
@ -155,7 +155,7 @@ class PermissionManager{
*/
public function unsubscribeFromPermission(string $permission, Permissible $permissible){
if(isset($this->permSubs[$permission])){
unset($this->permSubs[$permission][spl_object_hash($permissible)]);
unset($this->permSubs[$permission][spl_object_id($permissible)]);
if(count($this->permSubs[$permission]) === 0){
unset($this->permSubs[$permission]);
}
@ -167,7 +167,7 @@ class PermissionManager{
*/
public function unsubscribeFromAllPermissions(Permissible $permissible) : void{
foreach($this->permSubs as $permission => &$subs){
unset($subs[spl_object_hash($permissible)]);
unset($subs[spl_object_id($permissible)]);
if(empty($subs)){
unset($this->permSubs[$permission]);
}
@ -189,9 +189,9 @@ class PermissionManager{
*/
public function subscribeToDefaultPerms(bool $op, Permissible $permissible){
if($op){
$this->defSubsOp[spl_object_hash($permissible)] = $permissible;
$this->defSubsOp[spl_object_id($permissible)] = $permissible;
}else{
$this->defSubs[spl_object_hash($permissible)] = $permissible;
$this->defSubs[spl_object_id($permissible)] = $permissible;
}
}
@ -201,9 +201,9 @@ class PermissionManager{
*/
public function unsubscribeFromDefaultPerms(bool $op, Permissible $permissible){
if($op){
unset($this->defSubsOp[spl_object_hash($permissible)]);
unset($this->defSubsOp[spl_object_id($permissible)]);
}else{
unset($this->defSubs[spl_object_hash($permissible)]);
unset($this->defSubs[spl_object_id($permissible)]);
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\plugin;
use LogLevel;
use pocketmine\Server;
use function spl_object_hash;
use function spl_object_id;
class PluginLogger implements \AttachableLogger{
@ -35,11 +35,11 @@ class PluginLogger implements \AttachableLogger{
private $attachments = [];
public function addAttachment(\LoggerAttachment $attachment){
$this->attachments[spl_object_hash($attachment)] = $attachment;
$this->attachments[spl_object_id($attachment)] = $attachment;
}
public function removeAttachment(\LoggerAttachment $attachment){
unset($this->attachments[spl_object_hash($attachment)]);
unset($this->attachments[spl_object_id($attachment)]);
}
public function removeAttachments(){

View File

@ -27,7 +27,7 @@ use pocketmine\utils\Utils;
use function array_keys;
use function assert;
use function count;
use function spl_object_hash;
use function spl_object_id;
use function time;
use const PHP_INT_MAX;
use const PTHREADS_INHERIT_CONSTANTS;
@ -97,7 +97,7 @@ class AsyncPool{
*/
public function addWorkerStartHook(\Closure $hook) : void{
Utils::validateCallableSignature(function(int $worker) : void{}, $hook);
$this->workerStartHooks[spl_object_hash($hook)] = $hook;
$this->workerStartHooks[spl_object_id($hook)] = $hook;
foreach($this->workers as $i => $worker){
$hook($i);
}
@ -109,7 +109,7 @@ class AsyncPool{
* @param \Closure $hook
*/
public function removeWorkerStartHook(\Closure $hook) : void{
unset($this->workerStartHooks[spl_object_hash($hook)]);
unset($this->workerStartHooks[spl_object_id($hook)]);
}
/**

View File

@ -25,7 +25,7 @@ namespace pocketmine\scheduler;
use function is_scalar;
use function serialize;
use function spl_object_hash;
use function spl_object_id;
use function unserialize;
/**
@ -256,7 +256,7 @@ abstract class AsyncTask extends \Threaded{
*/
self::$threadLocalStorage = new \ArrayObject();
}
self::$threadLocalStorage[spl_object_hash($this)] = $complexData;
self::$threadLocalStorage[spl_object_id($this)] = $complexData;
}
/**
@ -270,16 +270,16 @@ abstract class AsyncTask extends \Threaded{
* @throws \InvalidArgumentException if no data were stored by this AsyncTask instance.
*/
protected function fetchLocal(){
if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[spl_object_hash($this)])){
if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[spl_object_id($this)])){
throw new \InvalidArgumentException("No matching thread-local data found on this thread");
}
return self::$threadLocalStorage[spl_object_hash($this)];
return self::$threadLocalStorage[spl_object_id($this)];
}
final public function __destruct(){
$this->reallyDestruct();
if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_hash($this)])){
if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_id($this)])){
unset(self::$threadLocalStorage[$h]);
if(self::$threadLocalStorage->count() === 0){
self::$threadLocalStorage = null;

View File

@ -29,7 +29,7 @@ use function count;
use function fwrite;
use function microtime;
use function round;
use function spl_object_hash;
use function spl_object_id;
use const PHP_EOL;
class TimingsHandler{
@ -154,7 +154,7 @@ class TimingsHandler{
$this->name = $name;
$this->parent = $parent;
self::$HANDLERS[spl_object_hash($this)] = $this;
self::$HANDLERS[spl_object_id($this)] = $this;
}
public function startTiming(){
@ -195,6 +195,6 @@ class TimingsHandler{
}
public function remove(){
unset(self::$HANDLERS[spl_object_hash($this)]);
unset(self::$HANDLERS[spl_object_id($this)]);
}
}