|
@@ -11,6 +11,7 @@ use SixShop\Core\Contracts\ExtensionInterface;
|
|
|
use think\Event;
|
|
use think\Event;
|
|
|
use think\exception\ClassNotFoundException;
|
|
use think\exception\ClassNotFoundException;
|
|
|
use function SixShop\Core\extension_name_list;
|
|
use function SixShop\Core\extension_name_list;
|
|
|
|
|
+use function SixShop\Core\running_in_console;
|
|
|
|
|
|
|
|
readonly class HookAttributeService
|
|
readonly class HookAttributeService
|
|
|
{
|
|
{
|
|
@@ -39,7 +40,12 @@ readonly class HookAttributeService
|
|
|
foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
|
foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
|
|
$attributes = $method->getAttributes(Hook::class);
|
|
$attributes = $method->getAttributes(Hook::class);
|
|
|
foreach ($attributes as $attr) {
|
|
foreach ($attributes as $attr) {
|
|
|
- $hookNameList = (array)$attr->newInstance()->hook;
|
|
|
|
|
|
|
+ $hookInstance = $attr->newInstance();
|
|
|
|
|
+ if ($hookInstance->isConsole && !running_in_console()) {
|
|
|
|
|
+ // 仅执行在控制台
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $hookNameList = (array)$hookInstance->hook;
|
|
|
foreach ($hookNameList as $hookName) {
|
|
foreach ($hookNameList as $hookName) {
|
|
|
$this->event->listen($hookName, [$hookClass, $method->getName()]);
|
|
$this->event->listen($hookName, [$hookClass, $method->getName()]);
|
|
|
}
|
|
}
|