Skip to content

Commit

Permalink
Add event constants and change email address.
Browse files Browse the repository at this point in the history
  • Loading branch information
juneszh committed Sep 13, 2023
1 parent 3491a7c commit 7d596a2
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/ConsoleChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
23 changes: 14 additions & 9 deletions src/Admin/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -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',
Expand Down Expand Up @@ -108,15 +113,15 @@ 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
* @throws InvalidArgumentException
* @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', '');
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Admin/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/FormOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
23 changes: 14 additions & 9 deletions src/Admin/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -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',
Expand Down Expand Up @@ -153,15 +158,15 @@ 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
* @throws InvalidArgumentException
* @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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/TableButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/TableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/TableExpand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/TableStatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/TableSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the Alight package.
*
* (c) June So <[email protected]>
* (c) June So <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down

0 comments on commit 7d596a2

Please sign in to comment.