Commit 6a9ba77d by feixiang

权限注解

parent 8af01f20
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:32
*/
namespace Hdll\Services\Common\Bean\Annotation;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target("ALL")
* Class Auth
* @package App\Bean\Annotation
*/
class Auth
{
private $name='';
private $scope=0;
private $option='==';
public function __construct(array $values)
{
if (isset($values['value'])) {
$this->name = $values['value'];
}
if (isset($values['name'])) {
$this->name = $values['name'];
}
if (isset($values['scope'])) {
$this->scope = $values['scope'];
}
if (isset($values['option'])) {
$this->option = $values['option'];
}
}
public function setName($name)
{
$this->name = $name;
}
public function setScope($scope)
{
$this->scope = $scope;
}
public function setOption($option)
{
$this->option = $option;
}
public function getName() : string
{
return $this->name;
}
public function getScope()
{
return $this->scope;
}
public function getOption()
{
return $this->option;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:44
*/
namespace Hdll\Services\Common\Bean\Collector;
use App\Bean\Annotation\Auth;
use Swoft\Bean\CollectorInterface;
class AuthCollector implements CollectorInterface
{
/**
* @var array
*/
private static $auth = [];
public static function collect(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
if ($objectAnnotation instanceof Auth) {
$scope = $objectAnnotation->getScope();
$option = $objectAnnotation->getOption();
if ( $methodName ==='' ) {
self::$auth[$className]['scope'] = $scope;
self::$auth[$className]['option'] = $option;
} else {
self::$auth[$className]['methods'][$methodName]['scope'] = $scope;
self::$auth[$className]['methods'][$methodName]['option'] = $option;
}
}
}
public static function getCollector()
{
return self::$auth;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:43
*/
namespace Hdll\Services\Common\Bean\Parser;
use App\Bean\Collector\AuthCollector;
use Swoft\Bean\Annotation\Scope;
use Swoft\Bean\Parser\AbstractParser;
/**
* @uses AuthParser
* Class AuthParser
* @package App\Bean\Parser
*/
class AuthParser extends AbstractParser
{
public function parser(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
$beanName = $className;
$scope = Scope::SINGLETON;
AuthCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
return [$beanName, $scope, ""];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/13
* Time: 13:28
*/
namespace Hdll\Services\Common\Bean\Wrapper;
use App\Bean\Annotation\Auth;
use Swoft\Bean\Wrapper\AbstractWrapper;
class AuthWrapper extends AbstractWrapper
{
/**
* @var array 解析哪些注解(类级)
*/
protected $classAnnotations = [
Auth::class
];
/**
* @var array 解析哪些注解(属性级)
*/
protected $propertyAnnotations = [
Auth::class
]
;
/**
* @var array 解析哪些注解(方法级)
*/
protected $methodAnnotations = [
Auth::class
];
/**
* 是否解析类注解
* @param array $annotations
* @return bool
*/
public function isParseClassAnnotations(array $annotations): bool
{
return true;
}
/**
* 是否解析属性注解
* @param array $annotations
* @return bool
*/
public function isParsePropertyAnnotations(array $annotations): bool
{
return false;
}
/**
* 是否解析方法注解
* @param array $annotations
* @return bool
*/
public function isParseMethodAnnotations(array $annotations): bool
{
return true;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment