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,60 @@
<?php
namespace Tests\Aspects;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)]
class ConfigurableAspect
{
public static array $executionLog = [];
public function __construct(
public readonly string $prefix = 'default',
public readonly int $multiplier = 1,
public readonly bool $enabled = true,
) {
}
public function before(object|string $target, mixed ...$args): void
{
if ($this->enabled) {
self::$executionLog[] = [
'event' => 'before',
'prefix' => $this->prefix,
'multiplier' => $this->multiplier,
'args' => $args,
];
}
}
public function after(object|string $target, mixed $result): mixed
{
if (!$this->enabled) {
return $result;
}
self::$executionLog[] = [
'event' => 'after',
'prefix' => $this->prefix,
'multiplier' => $this->multiplier,
'result' => $result,
];
// Modify result based on constructor parameters
if (is_int($result)) {
return $result * $this->multiplier;
}
if (is_string($result)) {
return $this->prefix . $result;
}
return $result;
}
public static function reset(): void
{
self::$executionLog = [];
}
}