goaop / framework

:gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development
go.aopphp.com
MIT License
1.66k stars 163 forks source link

[Feature] Pointcut namespace refactoring #500

Closed lisachenko closed 5 months ago

lisachenko commented 5 months ago

Previous Pointcut system wasn't type-safe, consisted of mix of different PointFilters and Poincuts, which resulted in extra code duplication, tricky checks and absence of strict typing of arguments.

For version 4 of framework, following major Pointcut interface will be used with it's main matches method:

    /**
     * Performs matching of point of code, returns true if point matches
     *
     * @param ReflectionClass<T>|ReflectionFileNamespace $context 
     * @param ReflectionMethod|ReflectionProperty|ReflectionFunction|null $reflector
     * @param null|(string&class-string<T>)|(object&T) $instanceOrScope
     * @param null|array<mixed>  $arguments
     *
     * @template T of object
     */
    public function matches(
        ReflectionClass|ReflectionFileNamespace                $context,
        ReflectionMethod|ReflectionProperty|ReflectionFunction $reflector = null,
        object|string                                          $instanceOrScope = null,
        array                                                  $arguments = null
    ): bool;

Pointcut matching is now always performed via single interface by checking first context, then context + reflector and finally, for dynamic pointcuts it checks context + reflector + instance + arguments of invocation.

Pay an attention, that in current version of framework, position of $context and $reflector has been switched to have more natural matching.

scrutinizer-notifier commented 5 months ago

A new inspection was created.