auth icon indicating copy to clipboard operation
auth copied to clipboard

Auth注解不支持PHP8的注解形式

Open awen1988 opened this issue 2 years ago • 1 comments

好像目前还不支持PHP8的注解形式

awen1988 avatar Mar 22 '22 04:03 awen1988

好像目前还不支持PHP8的注解形式

`<?php

declare (strict_types=1); /**

  • This file is part of hyperf-ext/auth.
  • @link https://github.com/hyperf-ext/auth
  • @contact [email protected]
  • @license https://github.com/hyperf-ext/auth/blob/master/LICENSE */ namespace HyperfExt\Auth\Aspect;

use Hyperf\Di\Annotation\Aspect; use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Aop\AbstractAspect; use Hyperf\Di\Aop\ProceedingJoinPoint; use HyperfExt\Auth\Annotations\Auth; use HyperfExt\Auth\Contracts\AuthenticatableInterface; use HyperfExt\Auth\Exceptions\AuthenticationException;

#[Aspect] class AuthAspect extends AbstractAspect {

public $annotations = [Auth::class];

#[Inject]
protected \\HyperfExt\Auth\Contracts\AuthManagerInterface $auth;

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
    $annotation = $proceedingJoinPoint->getAnnotationMetadata();
    $authAnnotation = $annotation->class[Auth::class] ?? $annotation->method[Auth::class];
    $guards = empty($authAnnotation->guards) ? [null] : $authAnnotation->guards;
    $passable = $authAnnotation->passable;
    foreach ($guards as $name) {
        $guard = $this->auth->guard($name);
        if (!$guard->user() instanceof AuthenticatableInterface and !$passable) {
            throw new AuthenticationException('Unauthenticated.', $guards);
        }
    }
    return $proceedingJoinPoint->process();
}

}`

ljyljy0211 avatar Apr 20 '23 09:04 ljyljy0211