feat : Proxy payment
This commit is contained in:
54
app/Aspect/Test/Proxy/LoggingAspect.php
Normal file
54
app/Aspect/Test/Proxy/LoggingAspect.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Aspect\Test\Proxy;
|
||||
|
||||
use App\Interface\Test\Decorator\LoggerInterface;
|
||||
use App\Service\Test\Proxy\Payment\PaymentService;
|
||||
use Hyperf\Di\Annotation\Aspect;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Di\Aop\AbstractAspect;
|
||||
use Hyperf\Di\Aop\ProceedingJoinPoint;
|
||||
use Hyperf\Di\Exception\Exception;
|
||||
use Throwable;
|
||||
|
||||
#[Aspect]
|
||||
class LoggingAspect extends AbstractAspect
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
#[Inject]
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
|
||||
/**
|
||||
* @var array|string[]
|
||||
*/
|
||||
public array $classes = [
|
||||
PaymentService::class , '::pay',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param ProceedingJoinPoint $proceedingJoinPoint
|
||||
* @return mixed
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function process(ProceedingJoinPoint $proceedingJoinPoint): mixed
|
||||
{
|
||||
$amount = $proceedingJoinPoint->arguments['keys']['amount'];
|
||||
|
||||
$this->logger->log('Attempting payment of '.$amount.' for '.$proceedingJoinPoint->methodName);
|
||||
|
||||
try {
|
||||
$result = $proceedingJoinPoint->process();
|
||||
|
||||
$this->logger->log('Payment of '.$amount.'succeeded');
|
||||
|
||||
return $result;
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->error('Payment of '.$amount.' failed: '.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user