jitesoft/annotations

1.1.0 2019-05-05 09:15 UTC

This package is auto-updated.

Last update: 2024-09-05 21:21:43 UTC


README

此项目包含在各种项目中使用的自定义注解。

请随意使用、添加、修改等,接受PR!

实现的注解

作用域

作用域旨在用于控制器中的自定义作用域注解。
Scopes注解接受一个字符串数组,然后可以检索出来以与特定用户的作用域进行匹配检查。

<?php

use Jitesoft\Annotations\Scopes;

/**
 * @Scopes({"read:resource"})
 */
class MyController {    
    /**
    * @Scopes({"delete:resource"})
    */
    public function deleteSomething() {}
}

// Read the annotation class with the doctrine annotation reader:
AnnotationRegistry::registerLoader('class_exists');

$this->reader = new AnnotationReader();
$class        = new ReflectionClass(Test_MethodScope::class);
$method       = $class->getMethod('deleteSomething');
$methodScopes = $this->reader->getMethodAnnotation($method, Scopes::class);
$classScopes  = $this->reader->getClassAnnotation($class, Scopes::class);


var_dump($methodScopes->getScopes()); /** [ 'delete:resource' ] */
var_dump($classScopes->getScopes());  /** [ 'read:resource' ] */