before params as associative array
This commit is contained in:
parent
d35c3df06d
commit
6946059f07
11 changed files with 154 additions and 8 deletions
|
|
@ -15,7 +15,7 @@ class BasicAspect
|
|||
) {
|
||||
}
|
||||
|
||||
public function before(mixed ...$args): void
|
||||
public function before(array $args): void
|
||||
{
|
||||
$this->object = end($args);
|
||||
$this->object->before = true;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ConfigurableAspect
|
|||
) {
|
||||
}
|
||||
|
||||
public function before(mixed ...$args): void
|
||||
public function before(array $args): void
|
||||
{
|
||||
if ($this->enabled) {
|
||||
self::$executionLog[] = [
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class LoggingAspect
|
|||
) {
|
||||
}
|
||||
|
||||
public function before(mixed ...$args): void
|
||||
public function before(array $args): void
|
||||
{
|
||||
self::$logs[] = ['type' => 'logging_before', 'args' => $args];
|
||||
}
|
||||
|
|
|
|||
35
tests/Aspects/ParameterKeyAspect.php
Normal file
35
tests/Aspects/ParameterKeyAspect.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Aspects;
|
||||
|
||||
use Attribute;
|
||||
use IceFox\Aspect\AspectContext;
|
||||
|
||||
#[Attribute(Attribute::TARGET_METHOD)]
|
||||
class ParameterKeyAspect
|
||||
{
|
||||
public static array $capturedKeys = [];
|
||||
public static array $capturedArgs = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly AspectContext $context,
|
||||
) {
|
||||
}
|
||||
|
||||
public function before(array $args): void
|
||||
{
|
||||
self::$capturedKeys = array_keys($args);
|
||||
self::$capturedArgs = $args;
|
||||
}
|
||||
|
||||
public function after(mixed $result): mixed
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function reset(): void
|
||||
{
|
||||
self::$capturedKeys = [];
|
||||
self::$capturedArgs = [];
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ class ThrowingAspect
|
|||
) {
|
||||
}
|
||||
|
||||
public function before(mixed ...$args): void
|
||||
public function before(array $args): void
|
||||
{
|
||||
if (self::$throwInBefore) {
|
||||
throw new RuntimeException('Exception thrown in before()');
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class TrackingAspect
|
|||
) {
|
||||
}
|
||||
|
||||
public function before(mixed ...$args): void
|
||||
public function before(array $args): void
|
||||
{
|
||||
self::$calls[] = ['event' => 'before', 'args' => $args];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue