mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
add plugin:pack command and pack events
This commit is contained in:
51
src/ZM/Plugin/Traits/PluginPackTrait.php
Normal file
51
src/ZM/Plugin/Traits/PluginPackTrait.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Plugin\Traits;
|
||||
|
||||
trait PluginPackTrait
|
||||
{
|
||||
protected mixed $on_pack = null;
|
||||
|
||||
protected mixed $on_pack_filter = null;
|
||||
|
||||
/**
|
||||
* 设置插件被打包前执行的回调函数
|
||||
*
|
||||
* @param callable $callback 回调函数
|
||||
* @return void
|
||||
*/
|
||||
public function onPack(callable $callback): void
|
||||
{
|
||||
$this->on_pack = $callback;
|
||||
}
|
||||
|
||||
public function filterPack(callable $callback): void
|
||||
{
|
||||
$this->on_pack_filter = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function emitPack(): void
|
||||
{
|
||||
if (is_callable($this->on_pack)) {
|
||||
($this->on_pack)();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param string $file 文件名称,由 PluginManager 传入
|
||||
* @return bool 返回 False 代表该文件不需要打包
|
||||
*/
|
||||
public function emitFilterPack(string $file): bool
|
||||
{
|
||||
if (is_callable($this->on_pack_filter)) {
|
||||
return (bool) ($this->on_pack_filter)($file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user