This commit is contained in:
icefox 2025-12-22 17:54:16 -03:00
commit a5ce423afe
No known key found for this signature in database
30 changed files with 1807 additions and 0 deletions

View file

@ -0,0 +1,47 @@
<?php
namespace Tests\Aspects;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)]
class TrackingAspect
{
public static array $calls = [];
public function before(object|string $target, mixed ...$args): void
{
self::$calls[] = ['event' => 'before', 'args' => $args];
}
public function after(object|string $target, mixed $result): mixed
{
self::$calls[] = ['event' => 'after', 'result' => $result];
return $result;
}
public static function clearCalls(): void
{
self::$calls = [];
}
public static function getLastBefore(): ?array
{
foreach (array_reverse(self::$calls) as $call) {
if ($call['event'] === 'before') {
return $call;
}
}
return null;
}
public static function getLastAfter(): ?array
{
foreach (array_reverse(self::$calls) as $call) {
if ($call['event'] === 'after') {
return $call;
}
}
return null;
}
}