OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
42
app/Core/Events/Concerns/InteractsWithEvents.php
Normal file
42
app/Core/Events/Concerns/InteractsWithEvents.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Events\Concerns;
|
||||
|
||||
use Leantime\Core\Events\EventDispatcher;
|
||||
|
||||
/**
|
||||
* Shared behavior for class-based domain events.
|
||||
*
|
||||
* Provides the static dispatch() ergonomic and a default empty legacyHooks() so events
|
||||
* introduced after the class-based system don't need to declare one:
|
||||
*
|
||||
* TicketUpdated::dispatch(ticketId: $id);
|
||||
*
|
||||
* Do NOT combine with Laravel's Dispatchable trait — both define dispatch(), and the
|
||||
* Dispatchable version routes through the generic object path instead of the
|
||||
* LeantimeEvent fast path.
|
||||
*/
|
||||
trait InteractsWithEvents
|
||||
{
|
||||
/**
|
||||
* Default: no legacy string names. Override during the migration window with the
|
||||
* exact historical leantime.* name of the CURRENT emit site — rebuilt from a
|
||||
* `legacyHook: __FUNCTION__` constructor discriminator when several methods
|
||||
* historically fired the same raw hook (see the LeantimeEvent docblock).
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function legacyHooks(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct and dispatch this event through the Leantime event dispatcher.
|
||||
* Arguments (named arguments included) are forwarded to the constructor.
|
||||
*/
|
||||
public static function dispatch(mixed ...$args): void
|
||||
{
|
||||
EventDispatcher::dispatch_event(new static(...$args));
|
||||
}
|
||||
}
|
||||
57
app/Core/Events/Concerns/InteractsWithFilters.php
Normal file
57
app/Core/Events/Concerns/InteractsWithFilters.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Events\Concerns;
|
||||
|
||||
use Leantime\Core\Events\EventDispatcher;
|
||||
|
||||
/**
|
||||
* Shared behavior for class-based filters.
|
||||
*
|
||||
* Provides the static dispatch() / instance apply() ergonomics and sensible defaults
|
||||
* for the LeantimeFilter contract:
|
||||
*
|
||||
* $tickets = TodoWidgetTasksFilter::dispatch(tickets: $tickets, userId: $userId);
|
||||
*
|
||||
* The default payload() returns the $payload property; filter classes that name their
|
||||
* payload something more meaningful (e.g. public array $tickets) override payload().
|
||||
*/
|
||||
trait InteractsWithFilters
|
||||
{
|
||||
/**
|
||||
* Default: no legacy string names. Override during the migration window with the
|
||||
* exact historical leantime.* name of the CURRENT emit site — rebuilt from a
|
||||
* `legacyHook: __FUNCTION__` constructor discriminator when several methods
|
||||
* historically ran the same raw hook (see the LeantimeFilter docblock).
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function legacyHooks(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default payload accessor. Override when the payload property has a domain name.
|
||||
*/
|
||||
public function payload(): mixed
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the filter and run the pipeline, returning the filtered payload.
|
||||
* Arguments (named arguments included) are forwarded to the constructor.
|
||||
*/
|
||||
public static function dispatch(mixed ...$args): mixed
|
||||
{
|
||||
return EventDispatcher::dispatch_class_filter(new static(...$args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the pipeline for an already-constructed filter, returning the filtered payload.
|
||||
*/
|
||||
public function apply(): mixed
|
||||
{
|
||||
return EventDispatcher::dispatch_class_filter($this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user