Skip to content

Commit

Permalink
Merge pull request #492 from samsonasik/patch-1
Browse files Browse the repository at this point in the history
[Step 1] Bump requirement to PHP 8.2 and parser-reflection 4.0.0-RC1
  • Loading branch information
lisachenko authored Mar 31, 2024
2 parents 501d013 + 872633c commit 91dbacb
Show file tree
Hide file tree
Showing 118 changed files with 622 additions and 954 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "PHPStan analysis"

on:
pull_request:
push:

jobs:
Expand All @@ -12,7 +13,7 @@ jobs:
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.2"
ini-values: memory_limit=-1
tools: composer:v2
- name: "Cache dependencies"
Expand All @@ -21,8 +22,8 @@ jobs:
path: |
~/.composer/cache
vendor
key: "php-7.4"
restore-keys: "php-7.4"
key: "php-8.2"
restore-keys: "php-8.2"
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Static analysis"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "PHPUnit tests"

on:
pull_request:
push:

jobs:
Expand All @@ -15,7 +16,7 @@ jobs:
- "lowest"
- "highest"
php-version:
- "7.4"
- "8.2"
operating-system:
- "ubuntu-latest"

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
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@
"license": "MIT",

"require": {
"php": "^7.4.0",
"doctrine/annotations": "^1.11.1",
"doctrine/cache": "^1.10",
"goaop/parser-reflection": "^3.0.1",
"jakubledl/dissect": "~1.0",
"laminas/laminas-code": "^4.0",
"symfony/finder": "^4.4|^5.1"
"php": "^8.2.0",
"goaop/parser-reflection": "4.x-dev",
"goaop/dissect": "^3.0",
"laminas/laminas-code": "^4.13",
"symfony/finder": "^5.1"
},

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

Expand Down Expand Up @@ -61,7 +60,7 @@
"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;
}
5 changes: 2 additions & 3 deletions demos/Demo/Aspect/LoggingAspect.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;

/**
* Logging aspect
Expand All @@ -32,9 +32,8 @@ class LoggingAspect implements Aspect
* Also you can choose "After" or "Around" advice to access an return value from method.
*
* To inject logger into this aspect you can look at Warlock framework with DI+AOP
*
* @Before("@execution(Demo\Annotation\Loggable)")
*/
#[Before("@execution(Demo\Attribute\Loggable)")]
public function beforeMethodExecution(MethodInvocation $invocation): void
{
echo 'Calling Before Interceptor for ',
Expand Down
Loading

0 comments on commit 91dbacb

Please sign in to comment.