From f230c0902fd63b35dff73cb8203d0e1c422f59b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 13 Apr 2021 19:19:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Snowflake.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/System/Snowflake.php b/System/Snowflake.php index c01c4df9..e1a0a738 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -6,6 +6,8 @@ namespace Snowflake; use Annotation\Annotation; +use Database\ActiveRecord; +use Database\Collection; use Exception; use HttpServer\IInterface\Task; @@ -483,6 +485,26 @@ class Snowflake const WORKER = 'worker'; + /** + * @param string $event + * @param null $data + * @return false|string + */ + public static function param(string $event, $data = NULL): bool|string + { + if (is_object($data)) { + if ($data instanceof ActiveRecord || $data instanceof Collection) { + $data = $data->getAttributes(); + } else { + $data = get_object_vars($data); + } + } + if (!is_array($data)) $data = ['data' => $data]; + return json_encode(array_merge(['callback' => $event], $data)); + } + + + /** * @return string|null */