AspectContext
This commit is contained in:
parent
6050e3bb72
commit
d35c3df06d
8 changed files with 70 additions and 19 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace Tests\Aspects;
|
||||
|
||||
use Attribute;
|
||||
use IceFox\Aspect\AspectContext;
|
||||
use RuntimeException;
|
||||
|
||||
#[Attribute(Attribute::TARGET_METHOD)]
|
||||
|
|
@ -11,14 +12,19 @@ class ThrowingAspect
|
|||
public static bool $throwInBefore = false;
|
||||
public static bool $throwInAfter = false;
|
||||
|
||||
public function before(object|string $target, mixed ...$args): void
|
||||
public function __construct(
|
||||
private readonly AspectContext $context,
|
||||
) {
|
||||
}
|
||||
|
||||
public function before(mixed ...$args): void
|
||||
{
|
||||
if (self::$throwInBefore) {
|
||||
throw new RuntimeException('Exception thrown in before()');
|
||||
}
|
||||
}
|
||||
|
||||
public function after(object|string $target, mixed $result): mixed
|
||||
public function after(mixed $result): mixed
|
||||
{
|
||||
if (self::$throwInAfter) {
|
||||
throw new RuntimeException('Exception thrown in after()');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue