From 3ee8b90e78bf3f006c22e63086e672ab2a0261cd Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Tue, 2 Aug 2022 18:57:47 +0800 Subject: [PATCH] add filter --- beike/Admin/Repositories/PermissionRepo.php | 22 ++++++++--------- beike/Helpers.php | 26 +++++++++++++++++++++ composer.json | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/beike/Admin/Repositories/PermissionRepo.php b/beike/Admin/Repositories/PermissionRepo.php index 4c555028..369dbbb8 100644 --- a/beike/Admin/Repositories/PermissionRepo.php +++ b/beike/Admin/Repositories/PermissionRepo.php @@ -50,8 +50,7 @@ class PermissionRepo ['title' => '税费类别', 'permissions' => $this->getTaxClassPermissions()], ['title' => '货币管理', 'permissions' => $this->getCurrencyPermissions()], ]; - - return $permissions; + return hook_filter('role.all_permissions', $permissions); } @@ -64,7 +63,7 @@ class PermissionRepo { $routes = ['orders_index', 'orders_create', 'orders_edit', 'orders_update', 'orders_delete']; $items = $this->getPermissionList('order', $routes); - return $items; + return hook_filter('role.order_permissions', $items); } @@ -77,7 +76,7 @@ class PermissionRepo { $routes = ['products_index', 'products_create', 'products_edit', 'products_update', 'products_delete']; $items = $this->getPermissionList('product', $routes); - return $items; + return hook_filter('role.product_permissions', $items); } @@ -90,7 +89,7 @@ class PermissionRepo { $routes = ['customers_index', 'customers_create', 'customers_edit', 'customers_update', 'customers_delete']; $items = $this->getPermissionList('customer', $routes); - return $items; + return hook_filter('role.customer_permissions', $items); } @@ -101,10 +100,11 @@ class PermissionRepo */ private function getSettingPermissions(): array { - return [ + $items = [ ['code' => 'settings_index', 'name' => trans('setting.settings_index'), 'selected' => $this->hasPermission('settings_index')], ['code' => 'design_index', 'name' => trans('setting.design_index'), 'selected' => $this->hasPermission('design_index')], ]; + return hook_filter('role.setting_permissions', $items); } @@ -117,7 +117,7 @@ class PermissionRepo { $routes = ['plugins_index', 'plugins_import', 'plugins_update', 'plugins_edit', 'plugins_install', 'plugins_update_status', 'plugins_uninstall']; $items = $this->getPermissionList('plugin', $routes); - return $items; + return hook_filter('role.plugin_permissions', $items); } @@ -130,7 +130,7 @@ class PermissionRepo { $routes = ['regions_index', 'regions_create', 'regions_edit', 'regions_update', 'regions_delete']; $items = $this->getPermissionList('region', $routes); - return $items; + return hook_filter('role.region_permissions', $items); } @@ -143,7 +143,7 @@ class PermissionRepo { $routes = ['tax_rates_index', 'tax_rates_create', 'tax_rates_edit', 'tax_rates_update', 'tax_rates_delete']; $items = $this->getPermissionList('tax_rate', $routes); - return $items; + return hook_filter('role.tax_rate_permissions', $items); } @@ -156,7 +156,7 @@ class PermissionRepo { $routes = ['tax_classes_index', 'tax_classes_create', 'tax_classes_edit', 'tax_classes_update', 'tax_classes_delete']; $items = $this->getPermissionList('tax_class', $routes); - return $items; + return hook_filter('role.tax_class_permissions', $items); } @@ -169,7 +169,7 @@ class PermissionRepo { $routes = ['currencies_index', 'currencies_create', 'currencies_edit', 'currencies_update', 'currencies_delete']; $items = $this->getPermissionList('currency', $routes); - return $items; + return hook_filter('role.currency_permissions', $items); } diff --git a/beike/Helpers.php b/beike/Helpers.php index 3963601d..80ccd9ef 100644 --- a/beike/Helpers.php +++ b/beike/Helpers.php @@ -348,6 +348,32 @@ function create_directories($directoryPath) } +/** + * hook filter 埋点 + * + * @param $hookKey + * @param $hookValue + * @return mixed + */ +function hook_filter($hookKey, $hookValue) +{ + return Eventy::filter($hookKey, $hookValue); +} + + +/** + * hook action 埋点 + * + * @param $hookKey + * @param $hookValue + * @return mixed + */ +function hook_action($hookKey, $hookValue) +{ + Eventy::action($hookKey, $hookValue); +} + + /** * 添加 Filter * diff --git a/composer.json b/composer.json index 133f518c..55d2bc14 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["framework", "laravel"], "license": "MIT", "require": { - "php": "^7.3|^8.0", + "php": "^7.4|^8.0", "ext-json": "*", "ext-zip": "*", "diglactic/laravel-breadcrumbs": "^7.2",