modify
This commit is contained in:
@@ -179,7 +179,7 @@ class Loader extends BaseObject
|
||||
}
|
||||
$this->appendFileToDirectory($path->getRealPath(), $replace->getName());
|
||||
|
||||
$_array = ['handler' => $replace->newInstance(), 'target' => [], 'methods' => [], 'property' => []];
|
||||
$_array = ['handler' => $replace->getName(), 'target' => [], 'methods' => [], 'property' => []];
|
||||
foreach ($replace->getAttributes() as $attribute) {
|
||||
if ($attribute->getName() == Attribute::class) {
|
||||
continue;
|
||||
@@ -401,21 +401,22 @@ class Loader extends BaseObject
|
||||
if ($annotations === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$target = new $annotations['handler']();
|
||||
foreach ($annotations['target'] ?? [] as $value) {
|
||||
$value->execute([$annotations['handler']]);
|
||||
$value->execute([$target]);
|
||||
}
|
||||
|
||||
$_className = $annotations['handler']::class;
|
||||
foreach ($annotations['methods'] as $name => $attribute) {
|
||||
foreach ($attribute as $value) {
|
||||
if ($value instanceof Relation) {
|
||||
$annotation->addRelate($_className, $value->name, $name);
|
||||
$annotation->addRelate($target::class, $value->name, $name);
|
||||
} else if ($value instanceof Get) {
|
||||
$annotation->addGets($_className, $value->name, $name);
|
||||
$annotation->addGets($target::class, $value->name, $name);
|
||||
} else if ($value instanceof Set) {
|
||||
$annotation->addSets($_className, $value->name, $name);
|
||||
$annotation->addSets($target::class, $value->name, $name);
|
||||
} else {
|
||||
$value->execute([$annotations['handler'], $name]);
|
||||
$value->execute([$target, $name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use HttpServer\Abstracts\Callback;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Coroutine\System;
|
||||
use Swoole\Server;
|
||||
|
||||
@@ -32,10 +33,7 @@ class OnWorkerStart extends Callback
|
||||
putenv('state=start');
|
||||
putenv('worker=' . $worker_id);
|
||||
|
||||
$content = System::readFile(storage('runtime.php'));
|
||||
|
||||
$annotation = Snowflake::app()->getAnnotation();
|
||||
$annotation->setLoader(unserialize($content));
|
||||
$annotation = $this->settings();
|
||||
if ($worker_id < $server->setting['worker_num']) {
|
||||
$this->onWorker($server, $annotation);
|
||||
} else {
|
||||
@@ -44,6 +42,21 @@ class OnWorkerStart extends Callback
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Annotation\Annotation
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function settings(): Annotation
|
||||
{
|
||||
$content = System::readFile(storage('runtime.php'));
|
||||
|
||||
$annotation = Snowflake::app()->getAnnotation();
|
||||
$annotation->setLoader(unserialize($content));
|
||||
|
||||
return $annotation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param int $worker_id
|
||||
|
||||
@@ -115,7 +115,11 @@ class Server extends HttpService
|
||||
|
||||
Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION);
|
||||
|
||||
Coroutine::set(['enable_deadlock_check' => false]);
|
||||
$settings['enable_deadlock_check'] = false;
|
||||
$settings['exit_condition'] = function () {
|
||||
return Coroutine::stats()['coroutine_num'] === 0;
|
||||
};
|
||||
Coroutine::set($settings);
|
||||
|
||||
return $this->execute($baseServer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user