.
This commit is contained in:
commit
a5ce423afe
30 changed files with 1807 additions and 0 deletions
60
tests/Aspects/ConfigurableAspect.php
Normal file
60
tests/Aspects/ConfigurableAspect.php
Normal 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 = [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue