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:
Dylan K. Taylor 2018-01-30 14:50:19 +00:00
parent c601816586
commit 82948726ed
2 changed files with 15 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);
}