改名
This commit is contained in:
@@ -13,6 +13,7 @@ use HttpServer\Route\Router;
|
|||||||
use Snowflake\Error\Logger;
|
use Snowflake\Error\Logger;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
use Swoole\Coroutine;
|
||||||
use Swoole\Error;
|
use Swoole\Error;
|
||||||
use Swoole\Http\Request;
|
use Swoole\Http\Request;
|
||||||
use Swoole\Http\Response;
|
use Swoole\Http\Response;
|
||||||
@@ -51,7 +52,7 @@ class OnRequest extends Callback
|
|||||||
public function onHandler(Request $request, Response $response): mixed
|
public function onHandler(Request $request, Response $response): mixed
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
defer(function () {
|
Coroutine::defer(function () {
|
||||||
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
||||||
});
|
});
|
||||||
/** @var HResponse $response */
|
/** @var HResponse $response */
|
||||||
|
|||||||
+15
-15
@@ -19,7 +19,7 @@ class Event extends BaseObject
|
|||||||
|
|
||||||
public bool $isVide = true;
|
public bool $isVide = true;
|
||||||
|
|
||||||
private array $_events = [];
|
private static array $_events = [];
|
||||||
|
|
||||||
const EVENT_ERROR = 'WORKER:ERROR';
|
const EVENT_ERROR = 'WORKER:ERROR';
|
||||||
const EVENT_STOP = 'WORKER:STOP';
|
const EVENT_STOP = 'WORKER:STOP';
|
||||||
@@ -73,8 +73,8 @@ class Event extends BaseObject
|
|||||||
*/
|
*/
|
||||||
public function on($name, $callback, $parameter = [], $isAppend = false)
|
public function on($name, $callback, $parameter = [], $isAppend = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->_events[$name])) {
|
if (!isset(static::$_events[$name])) {
|
||||||
$this->_events[$name] = [];
|
static::$_events[$name] = [];
|
||||||
}
|
}
|
||||||
if ($callback instanceof \Closure) {
|
if ($callback instanceof \Closure) {
|
||||||
$callback = \Closure::bind($callback, Snowflake::app());
|
$callback = \Closure::bind($callback, Snowflake::app());
|
||||||
@@ -87,10 +87,10 @@ class Event extends BaseObject
|
|||||||
if ($this->exists($name, $callback)) {
|
if ($this->exists($name, $callback)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!empty($this->_events[$name]) && $isAppend === true) {
|
if (!empty(static::$_events[$name]) && $isAppend === true) {
|
||||||
array_unshift($this->_events[$name], [$callback, $parameter]);
|
array_unshift(static::$_events[$name], [$callback, $parameter]);
|
||||||
} else {
|
} else {
|
||||||
$this->_events[$name][] = [$callback, $parameter];
|
static::$_events[$name][] = [$callback, $parameter];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,15 +101,15 @@ class Event extends BaseObject
|
|||||||
*/
|
*/
|
||||||
public function of($name, $callback): void
|
public function of($name, $callback): void
|
||||||
{
|
{
|
||||||
if (!isset($this->_events[$name])) {
|
if (!isset(static::$_events[$name])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($this->_events[$name] as $index => $event) {
|
foreach (static::$_events[$name] as $index => $event) {
|
||||||
[$handler, $parameter] = $event;
|
[$handler, $parameter] = $event;
|
||||||
if ($handler !== $callback) {
|
if ($handler !== $callback) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unset($this->_events[$name][$index]);
|
unset(static::$_events[$name][$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class Event extends BaseObject
|
|||||||
if (!$this->exists($name)) {
|
if (!$this->exists($name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
unset($this->_events[$name]);
|
unset(static::$_events[$name]);
|
||||||
return $this->exists($name);
|
return $this->exists($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,13 +135,13 @@ class Event extends BaseObject
|
|||||||
*/
|
*/
|
||||||
public function exists($name, $callback = null): bool
|
public function exists($name, $callback = null): bool
|
||||||
{
|
{
|
||||||
if (!isset($this->_events[$name])) {
|
if (!isset(static::$_events[$name])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($callback === null) {
|
if ($callback === null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
foreach ($this->_events[$name] as $event) {
|
foreach (static::$_events[$name] as $event) {
|
||||||
[$handler, $parameter] = $event;
|
[$handler, $parameter] = $event;
|
||||||
if ($handler === $callback) {
|
if ($handler === $callback) {
|
||||||
return true;
|
return true;
|
||||||
@@ -163,9 +163,9 @@ class Event extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($handler)) {
|
if (empty($handler)) {
|
||||||
return $this->_events[$name];
|
return static::$_events[$name];
|
||||||
}
|
}
|
||||||
foreach ($this->_events[$name] as $event) {
|
foreach (static::$_events[$name] as $event) {
|
||||||
[$callback, $parameter] = $event;
|
[$callback, $parameter] = $event;
|
||||||
if ($callback === $handler) {
|
if ($callback === $handler) {
|
||||||
return [$event];
|
return [$event];
|
||||||
@@ -177,7 +177,7 @@ class Event extends BaseObject
|
|||||||
|
|
||||||
public function clean()
|
public function clean()
|
||||||
{
|
{
|
||||||
$this->_events = [];
|
static::$_events = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user