diff --git a/HttpServer/Server.php b/HttpServer/Server.php index ac750640..549fff1e 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -184,18 +184,10 @@ class Server extends Application $application = Snowflake::app(); foreach ($processes as $name => $process) { - $class = Snowflake::createObject($process); - if (!method_exists($class, 'onHandler')) { - continue; - } - $this->debug(sprintf('Process %s', $process)); - $system = new Process([$class, 'onHandler'], ...[false, 1, true]); - if (Snowflake::isLinux()) { - $system->name($name); - } + $system = new $process(Snowflake::app(), $name); $this->baseServer->addProcess($system); - $application->set(get_class($class), $system); + $application->set(get_class($process), $system); } } diff --git a/System/Process/Process.php b/System/Process/Process.php index 4f7b30a4..b0102596 100644 --- a/System/Process/Process.php +++ b/System/Process/Process.php @@ -7,6 +7,7 @@ namespace Snowflake\Process; use Snowflake\Abstracts\Component; use Snowflake\Application; use Snowflake\Exception\ComponentException; +use Snowflake\Snowflake; use Swoole\Coroutine\Socket; use Swoole\Process\Pool; @@ -14,7 +15,28 @@ use Swoole\Process\Pool; * Class Process * @package Snowflake\Snowflake\Service */ -abstract class Process extends Component +abstract class Process extends \Swoole\Process { + /** @var Application $application */ + protected $application; + + + /** + * Process constructor. + * @param $application + * @param $name + * @throws \Exception + */ + public function __construct($application, $name) + { + parent::__construct([$this, 'onHandler'], false, 1, true); + $this->application = $application; + if (Snowflake::isLinux()) { + $this->name($name); + } + Snowflake::setWorkerId($this->pid); + } + + }