Skip to content

Commit

Permalink
Replace InterceptedInterface with MethodInterceptorInterface
Browse files Browse the repository at this point in the history
The interface `InterceptedInterface` used for method interception has been replaced with `MethodInterceptorInterface`. This is reflected across all the relevant modules, documentation and function calls. Existing code using `InterceptedInterface` should transition to use `MethodInterceptorInterface`.
  • Loading branch information
koriym committed Jun 27, 2024
1 parent e7ae323 commit 3d6a6eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ By using this extension, developers can achieve high-performance method intercep

### Defining an Interceptor

Create a class that implements the `Ray\Aop\InterceptedInterface`:
Create a class that implements the `Ray\Aop\MethodInterceptorInterface`:

```php
namespace Ray\Aop {
interface InterceptedInterface
interface MethodInterceptorInterface
{
public function intercept(object $object, string $method, array $params): mixed;
}
}

class MyInterceptor implements Ray\Aop\InterceptedInterface
class MyInterceptor implements Ray\Aop\MethodInterceptorInterface
{
public function intercept(object $object, string $method, array $params): mixed
{
Expand Down
6 changes: 3 additions & 3 deletions docs/policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
- Zend Engineのフックを利用して、指定されたクラスとメソッドの呼び出しをインターセプトする機能を実装します。
- オリジナルのメソッド呼び出しをラップし、インターセプトハンドラーを呼び出すメカニズムを構築します。

## 2. InterceptedInterfaceの実装
## 2. MethodInterceptorInterfaceの実装

- PHPユーザーランドで定義されるInterceptedInterfaceをC言語レベルで処理できるようにします
- PHPユーザーランドで定義されるMethodInterceptorInterfaceをC言語レベルで処理できるようにします
- interceptメソッドの呼び出しを適切に処理し、ユーザー定義のインターセプトロジックを実行できるようにします。

## 3. method_intercept関数の実装

- クラス名、メソッド名、InterceptedInterfaceオブジェクトを受け取り、インターセプション情報を内部で管理する仕組みを作ります。
- クラス名、メソッド名、MethodInterceptorInterfaceオブジェクトを受け取り、インターセプション情報を内部で管理する仕組みを作ります。
- 登録されたインターセプション情報を効率的に保存し、高速にアクセスできるデータ構造を設計します。

## 4. パフォーマンスの最適化
Expand Down
14 changes: 7 additions & 7 deletions rayaop.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Ray\Aop {
interface InterceptedInterface
{
public function intercept(object $object, string $method, array $params): mixed;
}
}
// namespace Ray\Aop {
// interface MethodInterceptorInterface
// {
// public function intercept(object $object, string $method, array $params): mixed;
// }
// }

namespace {
class Intercepted implements Ray\Aop\InterceptedInterface
class Intercepted implements Ray\Aop\MethodInterceptorInterface
{
public function intercept(object $object, string $method, array $params): mixed
{
Expand Down
8 changes: 4 additions & 4 deletions src/rayaop.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void rayaop_zend_execute_ex(zend_execute_data *execute_data)
ZEND_BEGIN_ARG_INFO_EX(arginfo_method_intercept, 0, 0, 3)
ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, method_name, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, interceptor, Ray\\Aop\\InterceptedInterface, 0)
ZEND_ARG_OBJ_INFO(0, interceptor, Ray\\Aop\\MethodInterceptorInterface, 0)
ZEND_END_ARG_INFO()

PHP_FUNCTION(method_intercept)
Expand All @@ -128,12 +128,12 @@ PHP_FUNCTION(method_intercept)
ZEND_PARSE_PARAMETERS_END();

if (!zend_ce_ray_aop_interceptedinterface) {
php_error_docref(NULL, E_WARNING, "Ray\\Aop\\InterceptedInterface is not defined");
php_error_docref(NULL, E_WARNING, "Ray\\Aop\\MethodInterceptorInterface is not defined");
RETURN_FALSE;
}

if (!instanceof_function(Z_OBJCE_P(intercepted), zend_ce_ray_aop_interceptedinterface)) {
php_error_docref(NULL, E_WARNING, "Interceptor must implement Ray\\Aop\\InterceptedInterface");
php_error_docref(NULL, E_WARNING, "Interceptor must implement Ray\\Aop\\MethodInterceptorInterface");
RETURN_FALSE;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ PHP_FUNCTION(method_intercept)
PHP_MINIT_FUNCTION(rayaop)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Ray\\Aop\\InterceptedInterface", NULL);
INIT_CLASS_ENTRY(ce, "Ray\\Aop\\MethodInterceptorInterface", NULL);
zend_ce_ray_aop_interceptedinterface = zend_register_internal_interface(&ce);

original_zend_execute_ex = zend_execute_ex;
Expand Down

0 comments on commit 3d6a6eb

Please sign in to comment.