jitesoft / annotations
Custom annotations.
1.1.0
2019-05-05 09:15 UTC
Requires
- doctrine/annotations: ^1.6
Requires (Dev)
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer_tests: ^2.0
This package is auto-updated.
Last update: 2024-11-05 21:45:35 UTC
README
This project contains custom annotations used in various projects.
Feel free to use, add, modify or whatever, PR's accepted!
Implemented annotations:
Scopes
Scopes are intended to be used on custom scope annotations in controllers.
The Scopes annotation takes a array of strings which can then be fetched to check with a specific users scope.
<?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' ] */