diff --git a/src/Admin.php b/src/Admin.php index 61c1f57..be09d48 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Auth.php b/src/Admin/Auth.php index 20a307e..1053904 100644 --- a/src/Admin/Auth.php +++ b/src/Admin/Auth.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Config.php b/src/Admin/Config.php index 16a34ec..f25d321 100644 --- a/src/Admin/Config.php +++ b/src/Admin/Config.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Console.php b/src/Admin/Console.php index 5122474..7854919 100644 --- a/src/Admin/Console.php +++ b/src/Admin/Console.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/ConsoleChart.php b/src/Admin/ConsoleChart.php index b6fde15..d1cc05c 100644 --- a/src/Admin/ConsoleChart.php +++ b/src/Admin/ConsoleChart.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Controller.php b/src/Admin/Controller.php index 7f765ed..8a76077 100755 --- a/src/Admin/Controller.php +++ b/src/Admin/Controller.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Form.php b/src/Admin/Form.php index 83e9824..4ac1c93 100755 --- a/src/Admin/Form.php +++ b/src/Admin/Form.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -27,6 +27,11 @@ class Form public static array $config = []; private static string $form; + public const + EVENT_RENDER = 'render', + EVENT_REQUEST = 'request', + EVENT_RESPONSE = 'response'; + public const TYPE_PASSWORD = 'password', TYPE_MONEY = 'money', @@ -108,7 +113,7 @@ public static function field(string $key): FormField * Form page render * * @param string $table - * @param null|callable $middleware function(string $action, array &$data){} + * @param null|callable $callback function(string $event, array &$data){} * @throws Exception * @throws ErrorException * @throws InvalidArgumentException @@ -116,7 +121,7 @@ public static function field(string $key): FormField * @throws GlobalInvalidArgumentException * @throws PDOException */ - public static function render(string $table, ?callable $middleware = null) + public static function render(string $table, ?callable $callback = null) { $_id = Request::request('_id', 0); $_form = Request::request('_form', ''); @@ -158,16 +163,16 @@ public static function render(string $table, ?callable $middleware = null) 'field' => $field, ]; - if (is_callable($middleware)) { - $middleware('render', $renderData); + if (is_callable($callback)) { + $callback(self::EVENT_RENDER, $renderData); } Response::render(Admin::path() . '/src/Admin/View.phtml', ['title' => $_title, 'script' => Admin::globalScript('Form', $renderData)]); } else { $sqlData = self::dataFilter($field, Request::request()); - if (is_callable($middleware)) { - $middleware('request', $sqlData); + if (is_callable($callback)) { + $callback(self::EVENT_REQUEST, $sqlData); } $rsId = 0; @@ -190,8 +195,8 @@ public static function render(string $table, ?callable $middleware = null) if ($rsId || $rsIds) { Model::userLog($userId, true); - if (is_callable($middleware)) { - $middleware('response', $resData); + if (is_callable($callback)) { + $callback(self::EVENT_RESPONSE, $resData); } } diff --git a/src/Admin/FormField.php b/src/Admin/FormField.php index 02903f8..c4196f3 100755 --- a/src/Admin/FormField.php +++ b/src/Admin/FormField.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/FormOption.php b/src/Admin/FormOption.php index 959a4da..942c3db 100755 --- a/src/Admin/FormOption.php +++ b/src/Admin/FormOption.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Menu.php b/src/Admin/Menu.php index aa7fd4a..fcefe56 100644 --- a/src/Admin/Menu.php +++ b/src/Admin/Menu.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/MenuItem.php b/src/Admin/MenuItem.php index b537e3a..9101047 100644 --- a/src/Admin/MenuItem.php +++ b/src/Admin/MenuItem.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Model.php b/src/Admin/Model.php index cd0e734..bec0047 100755 --- a/src/Admin/Model.php +++ b/src/Admin/Model.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/Table.php b/src/Admin/Table.php index 12e320c..85e2872 100755 --- a/src/Admin/Table.php +++ b/src/Admin/Table.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -28,6 +28,11 @@ class Table public static array $config = []; private static int $buttonIndex = 0; + public const + EVENT_RENDER = 'render', + EVENT_REQUEST = 'request', + EVENT_RESPONSE = 'response'; + public const ACTION_FORM = 'form', ACTION_PAGE = 'page', @@ -153,7 +158,7 @@ public static function statistic(string $key): TableStatistic * Table page render * * @param string $table - * @param null|callable $middleware function(string $action, array &$data){} + * @param null|callable $callback function(string $event, array &$data){} * @throws Exception * @throws ErrorException * @throws InvalidArgumentException @@ -161,7 +166,7 @@ public static function statistic(string $key): TableStatistic * @throws GlobalInvalidArgumentException * @throws PDOException */ - public static function render(string $table, ?callable $middleware = null) + public static function render(string $table, ?callable $callback = null) { $userId = Auth::getUserId(); $userInfo = Model::getUserInfo($userId); @@ -256,8 +261,8 @@ public static function render(string $table, ?callable $middleware = null) 'statistic' => Table::$config['statistic'] ?? [], ]; - if (is_callable($middleware)) { - $middleware('render', $renderData); + if (is_callable($callback)) { + $callback(self::EVENT_RENDER, $renderData); } Model::userLog($userId); @@ -290,8 +295,8 @@ public static function render(string $table, ?callable $middleware = null) $searchData = self::searchFilter($column, Request::request()); - if (is_callable($middleware)) { - $middleware('request', $searchData); + if (is_callable($callback)) { + $callback(self::EVENT_REQUEST, $searchData); } $count = Model::tableCount($table, $searchData); @@ -302,8 +307,8 @@ public static function render(string $table, ?callable $middleware = null) 'list' => $list, ]; - if (is_callable($middleware)) { - $middleware('response', $resData); + if (is_callable($callback)) { + $callback(self::EVENT_RESPONSE, $resData); } Response::api(0, null, $resData); diff --git a/src/Admin/TableButton.php b/src/Admin/TableButton.php index 7d5bffe..c151ba1 100755 --- a/src/Admin/TableButton.php +++ b/src/Admin/TableButton.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/TableColumn.php b/src/Admin/TableColumn.php index c1c36c0..d014caa 100755 --- a/src/Admin/TableColumn.php +++ b/src/Admin/TableColumn.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/TableExpand.php b/src/Admin/TableExpand.php index 05eeec1..3084b5f 100755 --- a/src/Admin/TableExpand.php +++ b/src/Admin/TableExpand.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/TableStatistic.php b/src/Admin/TableStatistic.php index ef2f0be..e10cac2 100644 --- a/src/Admin/TableStatistic.php +++ b/src/Admin/TableStatistic.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Admin/TableSummary.php b/src/Admin/TableSummary.php index 1e3c6a6..cf59357 100644 --- a/src/Admin/TableSummary.php +++ b/src/Admin/TableSummary.php @@ -5,7 +5,7 @@ /* * This file is part of the Alight package. * - * (c) June So + * (c) June So * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code.