mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Beware threads/workers might not inherit \pocketmine\PATH
if the inherit flags don't include PTHREADS_INHERIT_CONSTANTS, this code would fail. Store the Composer autoloader path in advance instead.
This commit is contained in:
parent
c601816586
commit
82948726ed
@ -30,6 +30,9 @@ abstract class Thread extends \Thread{
|
||||
|
||||
/** @var \ClassLoader */
|
||||
protected $classLoader;
|
||||
/** @var string|null */
|
||||
protected $composerAutoloaderPath;
|
||||
|
||||
protected $isKilled = false;
|
||||
|
||||
public function getClassLoader(){
|
||||
@ -37,6 +40,8 @@ abstract class Thread extends \Thread{
|
||||
}
|
||||
|
||||
public function setClassLoader(\ClassLoader $loader = null){
|
||||
$this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH;
|
||||
|
||||
if($loader === null){
|
||||
$loader = Server::getInstance()->getLoader();
|
||||
}
|
||||
@ -51,7 +56,9 @@ abstract class Thread extends \Thread{
|
||||
* (unless you are using a custom autoloader).
|
||||
*/
|
||||
public function registerClassLoader(){
|
||||
require(\pocketmine\PATH . "vendor/autoload.php");
|
||||
if($this->composerAutoloaderPath !== null){
|
||||
require $this->composerAutoloaderPath;
|
||||
}
|
||||
if($this->classLoader !== null){
|
||||
$this->classLoader->register(false);
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ abstract class Worker extends \Worker{
|
||||
|
||||
/** @var \ClassLoader */
|
||||
protected $classLoader;
|
||||
/** @var string|null */
|
||||
protected $composerAutoloaderPath;
|
||||
|
||||
protected $isKilled = false;
|
||||
|
||||
@ -38,6 +40,8 @@ abstract class Worker extends \Worker{
|
||||
}
|
||||
|
||||
public function setClassLoader(\ClassLoader $loader = null){
|
||||
$this->composerAutoloaderPath = \pocketmine\COMPOSER_AUTOLOADER_PATH;
|
||||
|
||||
if($loader === null){
|
||||
$loader = Server::getInstance()->getLoader();
|
||||
}
|
||||
@ -52,7 +56,9 @@ abstract class Worker extends \Worker{
|
||||
* (unless you are using a custom autoloader).
|
||||
*/
|
||||
public function registerClassLoader(){
|
||||
require(\pocketmine\PATH . "vendor/autoload.php");
|
||||
if($this->composerAutoloaderPath !== null){
|
||||
require $this->composerAutoloaderPath;
|
||||
}
|
||||
if($this->classLoader !== null){
|
||||
$this->classLoader->register(false);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user