Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.4"
ini-values: memory_limit=-1
tools: composer:v2
- name: "Cache dependencies"
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.composer/cache
vendor
key: "php-7.4"
restore-keys: "php-7.4"
key: "php-8.4"
restore-keys: "php-8.4"
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Static analysis"
uses: chindit/actions-phpstan@master
run: "vendor/bin/phpstan analyse"
6 changes: 3 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
- "lowest"
- "highest"
php-version:
- "7.4"
- "8.4"
operating-system:
- "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -32,7 +32,7 @@ jobs:
tools: composer:v2, cs2pr

- name: "Cache dependencies"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: |
~/.composer/cache
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
phpunit.xml
tests/Fixtures/project/var/cache/*
build/
/.phpunit.result.cache
31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
"license": "MIT",

"require": {
"php": "^8.0",
"doctrine/annotations": "^1.11.1",
"doctrine/cache": "^1.10",
"lanfix/goaop-parser-reflection": "^4.0",
"jakubledl/dissect": "~1.0",
"laminas/laminas-code": "^4.0",
"symfony/finder": "^4.4|^5.1|^6.0"
"php": "^8.4.0",
"ext-tokenizer": "*",
"goaop/parser-reflection": "4.x-dev",
"goaop/dissect": "^3.0",
"laminas/laminas-code": "^4.13",
"symfony/finder": "^5.4 || ^6.4 || ^7.0"
},

"require-dev": {
"adlawson/vfs": "^0.12.1",
"doctrine/orm": "^2.5",
"phpstan/phpstan": "^0.12.64",
"phpunit/phpunit": "^9.5",
"symfony/console": "^4.4|^5.1",
"symfony/filesystem": "^4.4|^5.1",
"symfony/process": "^4.4|^5.1",
"doctrine/orm": "^2.5 || ^3.0",
"phpstan/phpstan": "^1.10.57",
"phpunit/phpunit": "^10.5.10",
"symfony/console": "^6.4 || ^7.0",
"symfony/filesystem": "^6.4 || ^7.0",
"symfony/process": "^6.4 || ^7.0",
"tracy/tracy": "^2.10",
"webmozart/glob": "^4.1"
},

Expand Down Expand Up @@ -54,14 +54,15 @@
"Go\\Tests\\TestProject\\": "tests/Fixtures/project/src/"
},
"files": [
"tests/functions.php"
"tests/functions.php",
"tests/Go/Stubs/ClassWithoutNamespace.php"
]
},

"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
"dev-master": "4.0-dev"
}
},
"config": {
Expand Down
27 changes: 0 additions & 27 deletions demos/Demo/Annotation/Cacheable.php

This file was deleted.

15 changes: 6 additions & 9 deletions demos/Demo/Aspect/CachingAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace Demo\Aspect;

use Demo\Annotation\Cacheable;
use Demo\Attribute\Cacheable;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Around;
use Go\Lang\Attribute\Around;

/**
* Caching aspect
Expand All @@ -29,12 +29,9 @@ class CachingAspect implements Aspect
* then invoke original method and store it's result in the cache.
*
* Real-life examples will use APC or Memcache to store value in the cache
*
* @return mixed Result of invocation
*
* @Around("@execution(Demo\Annotation\Cacheable)")
*/
public function aroundCacheable(MethodInvocation $invocation)
#[Around('@execution(Demo\Attribute\Cacheable)')]
protected function aroundCacheable(MethodInvocation $invocation): mixed
{
static $memoryCache = [];

Expand All @@ -44,8 +41,8 @@ public function aroundCacheable(MethodInvocation $invocation)
$class = is_object($obj) ? get_class($obj) : $obj;
$key = $class . ':' . $invocation->getMethod()->name;
if (!isset($memoryCache[$key])) {
// We can use ttl value from annotation, but Doctrine annotations doesn't work under GAE
echo "Ttl is: ", $invocation->getMethod()->getAnnotation(Cacheable::class)->time, PHP_EOL;
$attributeArgs = $invocation->getMethod()->getAttributes(Cacheable::class)[0]->getArguments();
echo "Ttl is: ", $attributeArgs['time'], PHP_EOL;

$memoryCache[$key] = $invocation->proceed();
}
Expand Down
8 changes: 3 additions & 5 deletions demos/Demo/Aspect/DeclareErrorAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Demo\Aspect;

use Go\Aop\Aspect;
use Go\Lang\Annotation\DeclareError;
use Go\Lang\Attribute\DeclareError;

/**
* This aspect can be very useful for development to generate an error when executing prohibited methods
Expand All @@ -22,15 +22,13 @@ class DeclareErrorAspect implements Aspect
{
/**
* Message to show when calling the method
*
* @DeclareError("@execution(Demo\Annotation\Deprecated)", level=16384) // E_USER_DEPRECATED
*/
#[DeclareError('@execution(Demo\Attribute\Deprecated)', level: E_USER_DEPRECATED)]
protected string $message = 'Method is deprecated and should not be called in debug mode';

/**
* Prevent developers from using this method by always generating a warning
*
* @DeclareError("execution(public Demo\Example\ErrorDemo->notSoGoodMethod(*))", level=512) // E_USER_WARNING
*/
#[DeclareError('execution(public Demo\Example\ErrorDemo->notSoGoodMethod(*))', level: E_USER_WARNING)]
protected string $badMethod = 'Method can generate division by zero! Do not use it!';
}
9 changes: 3 additions & 6 deletions demos/Demo/Aspect/DynamicMethodsAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
use Go\Lang\Attribute\Before;

/**
* Aspect that intercepts specific magic methods, declared with __call and __callStatic
Expand All @@ -26,9 +26,8 @@ class DynamicMethodsAspect implements Aspect
*
* Unlike traditional "execution" pointcut, "dynamic" is checking the name of method in
* the runtime, allowing to write interceptors for __call more transparently.
*
* @Before("dynamic(public Demo\Example\DynamicMethodsDemo->save*(*))")
*/
#[Before('dynamic(public Demo\Example\DynamicMethodsDemo->save*(*))')]
public function beforeMagicMethodExecution(MethodInvocation $invocation): void
{
// we need to unpack args from invocation args
Expand All @@ -45,10 +44,8 @@ public function beforeMagicMethodExecution(MethodInvocation $invocation): void

/**
* This advice intercepts an execution of methods via __callStatic
*
* @param MethodInvocation $invocation
* @Before("dynamic(public Demo\Example\DynamicMethodsDemo::find*(*))")
*/
#[Before('dynamic(public Demo\Example\DynamicMethodsDemo::find*(*))')]
public function beforeMagicStaticMethodExecution(MethodInvocation $invocation): void
{
// we need to unpack args from invocation args
Expand Down
9 changes: 3 additions & 6 deletions demos/Demo/Aspect/FluentInterfaceAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Around;
use Go\Lang\Attribute\Around;

/**
* Fluent interface aspect provides an easy way to reuse "chain" interface for classes
Expand All @@ -29,12 +29,9 @@ class FluentInterfaceAspect implements Aspect
{
/**
* Fluent interface advice
*
* @Around("within(Demo\Aspect\FluentInterface+) && execution(public **->set*(*))")
*
* @return mixed Result of invocation
*/
protected function aroundMethodExecution(MethodInvocation $invocation)
#[Around('within(Demo\Aspect\FluentInterface+) && execution(public **->set*(*))')]
protected function aroundMethodExecution(MethodInvocation $invocation): mixed
{
$result = $invocation->proceed();

Expand Down
12 changes: 4 additions & 8 deletions demos/Demo/Aspect/FunctionInterceptorAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Go\Aop\Aspect;
use Go\Aop\Intercept\FunctionInvocation;
use Go\Lang\Annotation\Around;
use Go\Lang\Attribute\Around;

/**
* Function interceptor can intercept an access to the system functions
Expand All @@ -23,12 +23,9 @@ class FunctionInterceptorAspect implements Aspect
{
/**
* This advice intercepts an access to the array_*** function in Demo\Example\ namespace
*
* @Around("execution(Demo\Example\array_*(*))")
*
* @return mixed
*/
public function aroundArrayFunctions(FunctionInvocation $invocation)
#[Around('execution(Demo\Example\array_*(*))')]
public function aroundArrayFunctions(FunctionInvocation $invocation): mixed
{
echo 'Calling Around Interceptor for ',
$invocation,
Expand All @@ -41,9 +38,8 @@ public function aroundArrayFunctions(FunctionInvocation $invocation)

/**
* This advice intercepts an access to the file_get_contents() function
*
* @Around("execution(Demo\Example\file_get_contents(*))")
*/
#[Around('execution(Demo\Example\file_get_contents(*))')]
public function aroundFileGetContents(FunctionInvocation $invocation): string
{
echo 'Calling Around Interceptor for ',
Expand Down
18 changes: 7 additions & 11 deletions demos/Demo/Aspect/HealthyLiveAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use Demo\Example\HumanDemo;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Pointcut;
use Go\Lang\Attribute\After;
use Go\Lang\Attribute\Before;
use Go\Lang\Attribute\Pointcut;

/**
* Healthy live aspect
Expand All @@ -26,18 +26,16 @@ class HealthyLiveAspect implements Aspect
{
/**
* Pointcut for eat method
*
* @Pointcut("execution(public Demo\Example\HumanDemo->eat(*))")
*/
#[Pointcut('execution(public Demo\Example\HumanDemo->eat(*))')]
protected function humanEat(): void
{
}

/**
* Washing hands before eating
*
* @Before("$this->humanEat")
*/
#[Before('$this->humanEat')]
protected function washUpBeforeEat(MethodInvocation $invocation): void
{
/** @var $person HumanDemo */
Expand All @@ -47,9 +45,8 @@ protected function washUpBeforeEat(MethodInvocation $invocation): void

/**
* Method that advices to clean the teeth after eating
*
* @After("$this->humanEat")
*/
#[After('$this->humanEat')]
protected function cleanTeethAfterEat(MethodInvocation $invocation): void
{
/** @var $person HumanDemo */
Expand All @@ -59,9 +56,8 @@ protected function cleanTeethAfterEat(MethodInvocation $invocation): void

/**
* Method that advice to clean the teeth before going to sleep
*
* @Before("execution(public Demo\Example\HumanDemo->sleep(*))")
*/
#[Before('execution(public Demo\Example\HumanDemo->sleep(*))')]
protected function cleanTeethBeforeSleep(MethodInvocation $invocation): void
{
/** @var $person HumanDemo */
Expand Down
21 changes: 9 additions & 12 deletions demos/Demo/Aspect/IntroductionAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

namespace Demo\Aspect;

use Demo\Aspect\Introduce\SerializableImpl;
use Go\Aop\Aspect;
use Go\Lang\Annotation\DeclareParents;
use Go\Lang\Attribute\DeclareParents;
use Serializable;

/**
* Introduction aspect can dynamically add new interfaces and traits to the class
Expand All @@ -22,16 +24,11 @@ class IntroductionAspect implements Aspect
{
/**
* Add a single interface and trait to the class.
*
* You can also give several interfaces/traits via []
*
* @DeclareParents(
* value="within(Demo\Example\IntroductionDemo)",
* interface="Serializable",
* defaultImpl="Demo\Aspect\Introduce\SerializableImpl"
* )
*
* @var null
*/
protected $introduction;
#[DeclareParents(
'within(Demo\Example\IntroductionDemo)',
interface: Serializable::class,
trait: SerializableImpl::class
)]
protected null $introduction;
}
Loading