mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 17:29:44 +00:00
Require Closures in more places instead of callable
Non-closure callables have strange context-dependent behaviour and are slower to call than a closure. It's possible to use Closure::fromCallable() in the origin scope, which guarantees that the callable will remain callable no matter where it's used.
This commit is contained in:
parent
2720ff9607
commit
7eb8d8e366
@ -27,7 +27,7 @@ use pocketmine\utils\Utils;
|
|||||||
use function array_push;
|
use function array_push;
|
||||||
|
|
||||||
class CompressBatchPromise{
|
class CompressBatchPromise{
|
||||||
/** @var callable[] */
|
/** @var \Closure[] */
|
||||||
private $callbacks = [];
|
private $callbacks = [];
|
||||||
|
|
||||||
/** @var string|null */
|
/** @var string|null */
|
||||||
@ -36,7 +36,7 @@ class CompressBatchPromise{
|
|||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $cancelled = false;
|
private $cancelled = false;
|
||||||
|
|
||||||
public function onResolve(callable ...$callbacks) : void{
|
public function onResolve(\Closure ...$callbacks) : void{
|
||||||
$this->checkCancelled();
|
$this->checkCancelled();
|
||||||
foreach($callbacks as $callback){
|
foreach($callbacks as $callback){
|
||||||
Utils::validateCallableSignature(function(CompressBatchPromise $promise){}, $callback);
|
Utils::validateCallableSignature(function(CompressBatchPromise $promise){}, $callback);
|
||||||
@ -64,7 +64,7 @@ class CompressBatchPromise{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return callable[]
|
* @return \Closure[]
|
||||||
*/
|
*/
|
||||||
public function getResolveCallbacks() : array{
|
public function getResolveCallbacks() : array{
|
||||||
return $this->callbacks;
|
return $this->callbacks;
|
||||||
|
@ -187,13 +187,13 @@ class Internet{
|
|||||||
* @param float|int $timeout The maximum connect timeout and timeout in seconds, correct to ms.
|
* @param float|int $timeout The maximum connect timeout and timeout in seconds, correct to ms.
|
||||||
* @param string[] $extraHeaders extra headers to send as a plain string array
|
* @param string[] $extraHeaders extra headers to send as a plain string array
|
||||||
* @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map
|
* @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map
|
||||||
* @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle.
|
* @param \Closure|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle.
|
||||||
*
|
*
|
||||||
* @return array a plain array of three [result body : string, headers : array[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values
|
* @return array a plain array of three [result body : string, headers : array[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values
|
||||||
*
|
*
|
||||||
* @throws InternetException if a cURL error occurs
|
* @throws InternetException if a cURL error occurs
|
||||||
*/
|
*/
|
||||||
public static function simpleCurl(string $page, $timeout = 10, array $extraHeaders = [], array $extraOpts = [], ?callable $onSuccess = null) : array{
|
public static function simpleCurl(string $page, $timeout = 10, array $extraHeaders = [], array $extraOpts = [], ?\Closure $onSuccess = null) : array{
|
||||||
if(!self::$online){
|
if(!self::$online){
|
||||||
throw new InternetException("Cannot execute web request while offline");
|
throw new InternetException("Cannot execute web request while offline");
|
||||||
}
|
}
|
||||||
|
@ -134,9 +134,9 @@ class BlockTransaction{
|
|||||||
* The callable signature should be the same as the below dummy function.
|
* The callable signature should be the same as the below dummy function.
|
||||||
* @see BlockTransaction::dummyValidator()
|
* @see BlockTransaction::dummyValidator()
|
||||||
*
|
*
|
||||||
* @param callable $validator
|
* @param \Closure $validator
|
||||||
*/
|
*/
|
||||||
public function addValidator(callable $validator) : void{
|
public function addValidator(\Closure $validator) : void{
|
||||||
Utils::validateCallableSignature([$this, 'dummyValidator'], $validator);
|
Utils::validateCallableSignature([$this, 'dummyValidator'], $validator);
|
||||||
$this->validators[] = $validator;
|
$this->validators[] = $validator;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user