Skip to content

2.16.0

Compare
Choose a tag to compare
@koriym koriym released this 07 Jul 05:48
· 14 commits to 2.x since this release

Ray.Aop 2.16 "Tanabata" Release Notes

This version brings significant changes to the API, simplifying usage and improving integration with the new PECL extension.

Major Changes

New Aspect Class

The most significant change is the introduction of the Aspect class, which simplifies the configuration process:

use Ray\Aop\Aspect;
use Ray\Aop\Matcher;

$aspect = new Aspect();
$aspect->bind(
    (new Matcher())->any(),
    (new Matcher())->annotatedWith(NotOnWeekends::class),
    [new WeekendBlocker()]
);

$billing = $aspect->newInstance(RealBillingService::class);
echo $billing->chargeOrder(); // Interceptors applied 

This replaces the previous approach using Pointcut, Bind, and Weaver classes:

// Old approach (2.0.0 to pre-2.16.0)
$pointcut = new Pointcut(
    (new Matcher())->any(),
    (new Matcher())->annotatedWith(NotOnWeekends::class),
    [new WeekendBlocker()]
);
$bind = (new Bind)->bind(RealBillingService::class, [$pointcut]);
$billing = (new Weaver($bind, $tmpDir))->newInstance(RealBillingService::class, []);

PECL Extension Integration

Ray.Aop 2.16 seamlessly integrates with the new PECL extension. When the extension is installed, you can use the weave method:

$aspect = new Aspect();
$aspect->bind(
    (new Matcher())->any(),
    (new Matcher())->annotatedWith(NotOnWeekends::class),
    [new WeekendBlocker()]
);
$aspect->weave(__DIR__ . '/src'); // Weave the aspects 

$billing = new RealBillingService();
echo $billing->chargeOrder(); // Interceptors applied 

This applies aspects to all classes in a directory, allowing you to use the normal new keyword for instantiation.

Changes

  1. The Pointcut, Bind, and Weaver classes are no longer used directly. Instead, use the new Aspect class.
  2. The newInstance method is now part of the Aspect class, not Weaver.

Additional Notes

  • The PECL extension is optional.
  • Existing interceptors and matchers should continue to work without modifications.

We believe these changes will make Ray.Aop easier to use and more powerful. As always, we appreciate your feedback and contributions!

What's Changed

  • Add PHP class diagram by @koriym in #213
  • PECL extension support and introduce newly refined main class "Aspect" by @koriym in #214
Tanabata BEAR.Sunday

Full Changelog: 2.15.2...2.16.0