Skip to content

Commit

Permalink
Add Ray.Aop InterceptHandler to spec.md
Browse files Browse the repository at this point in the history
The documentation has been updated to include the Ray.Aop InterceptHandler implementation in the `spec.md` file. This should provide clear guidance on how to properly use and implement Ray.Aop's InterceptHandler.
  • Loading branch information
koriym committed Jul 6, 2024
1 parent 8d9518f commit ca46f7e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ class MyInterceptor implements MethodInterceptorInterface
}
```

1.1 For Ray.Aop

```php
<?php

namespace Ray\Aop;

class InterceptHandler implements InterceptHandlerInterface {

/** @var array<string, Interceptor> */
public function __construct(private array $interceptors)
{}

public function intercept(object $object, string $method, array $params): mixed {
// Ray.Aopの場合
if (! isset($this->interceptors[get_class($object)][$method])) {
throw new \LogicException('Interceptors not found');
}
$interceptors = $this->interceptors[get_class($object)][$method];
$invocation = new ReflectiveMethodInvocation($object, $method, $params, $interceptors);

return $invocation->proceed();
}
}

method_intercept('MyClass', 'myMethod', $interceptHandler);
```

2. **Registering an Intercept Handler**:
Use the `method_intercept` function to register an intercept handler for a specific class and method.

Expand Down

0 comments on commit ca46f7e

Please sign in to comment.