Skip to content

Commit

Permalink
[archived branch]
Browse files Browse the repository at this point in the history
The README.md file was significantly simplified by removing all previous contents including its build, description, usage and contributing sections. The only remaining lines briefly state that the branch failed in its attempt to have its own custom memory management, and it is being temporarily kept for the sake of record keeping.
  • Loading branch information
koriym committed Jun 28, 2024
1 parent 088148d commit 7548145
Showing 1 changed file with 2 additions and 129 deletions.
131 changes: 2 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,131 +1,4 @@
# Ray.Aop PHP Extension

[![Build and Test PHP Extension](https://github.com/ray-di/ext-rayaop/actions/workflows/build.yml/badge.svg)](https://github.com/ray-di/ext-rayaop/actions/workflows/build.yml)

<img src="https://ray-di.github.io/images/logo.svg" alt="ray-di logo" width="150px;">

A PHP extension that provides Aspect-Oriented Programming (AOP) functionality for method interception.

## Features

- Intercept method calls on specific classes
- Apply custom logic before and after method execution
- Modify method arguments and return values

## Requirements

- PHP 8.0 or higher
- php-dev package installed

## Installation

2.Compile the extension:

```
phpize
./configure
make
```

3. Install the extension:

```
sudo make install
```

4. Add the following line to your php.ini file:

```
extension=rayaop.so
```

## About this Extension

This PECL extension is designed to enhance the performance of Ray.Aop by eliminating the need for CodeGen, resulting in faster execution speeds. While it is primarily created for Ray.Aop, it can also be used to implement custom AOP solutions independently of Ray.Aop.

By using this extension, developers can achieve high-performance method interception without the overhead of generating and compiling additional code.

## Usage

### Defining an Interceptor

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

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

class MyInterceptor implements Ray\Aop\MethodInterceptorInterface
{
public function intercept(object $object, string $method, array $params): mixed
{
echo "Intercepted: " . get_class($object) . "::{$method}\n";
echo "Arguments: " . json_encode($params) . "\n";

// Call the original method
$result = call_user_func_array([$object, $method], $params);

echo "Method execution completed.\n";

return $result;
}
}
```

### Registering an Interceptor

Use the `method_intercept` function to register an interceptor for a specific class and method:

```php
$interceptor = new MyInterceptor();
method_intercept('TestClass', 'testMethod', $interceptor);
```

### Example

```php
class TestClass
{
public function testMethod($arg)
{
echo "TestClass::testMethod($arg) called\n";
return "Result: $arg";
}
}

$test = new TestClass();
$result = $test->testMethod("test");
echo "Result: $result\n";
```

## Running Tests

To run the tests, use the following command:

```
php -dextension=./modules/rayaop.so test/rayaop_test.php
```

## Build Script

You can use the build.sh script for various build operations:

```sh
./build.sh clean # Clean the build environment
./build.sh prepare # Prepare the build environment
./build.sh build # Build the extension
./build.sh run # Run the extension
./build.sh all # Execute all the above steps
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
- このブランチは独自のcustom memory managementを保持しようとして失敗したブランチです。
- 記録のために一時的に残します。

0 comments on commit 7548145

Please sign in to comment.