jitesoft/annotations

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Custom annotations.

1.1.0 2019-05-05 09:15 UTC

This package is auto-updated.

Last update: 2021-07-05 14:32:26 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' ] */