Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AuthorizeAttributeHandler
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 __construct
n/a
0 / 0
n/a
0 / 0
1
 attributeClass
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 targets
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace Dynart\Micro\AttributeHandler;
4
5use Dynart\Micro\Attribute\Authorize;
6use Dynart\Micro\AttributeHandlerInterface;
7use Dynart\Micro\JwtAuthInterface;
8
9class AuthorizeAttributeHandler implements AttributeHandlerInterface {
10
11    public function __construct(private JwtAuthInterface $jwtAuth) {}
12
13    public function attributeClass(): string {
14        return Authorize::class;
15    }
16
17    public function targets(): array {
18        return [AttributeHandlerInterface::TARGET_CLASS, AttributeHandlerInterface::TARGET_METHOD];
19    }
20
21    public function handle(string $className, mixed $subject, object $attribute): void {
22        if ($subject instanceof \ReflectionClass) {
23            $this->jwtAuth->addClassAuthorization($className, $attribute->permission);
24        } elseif ($subject instanceof \ReflectionMethod) {
25            $this->jwtAuth->addMethodAuthorization($className, $subject->getName(), $attribute->permission);
26        }
27    }
28}