src/ApiBundle/Api/Annotation/Access.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace ApiBundle\Api\Annotation;
use Biz\Common\CommonException;
/**
* @Annotation
* @Target({"METHOD"})
*/
class Access
{
private $roles;
private $rolesArray = array('ROLE_USER');
public function __construct(array $data)
{
foreach ($data as $key => $value) {
$method = 'set'.str_replace('_', '', $key);
if (!method_exists($this, $method)) {
throw CommonException::NOTFOUND_METHOD();
}
$this->$method($value);
}
}
public function setRoles($roles)
{
$this->roles = $roles;
}
/**
* @param $currentUserRoles
*
* @return bool
*/
public function canAccess($currentUserRoles)
{
$roles = $this->rolesArray = explode(',', $this->roles);
if (empty($roles)) {
return true;
}
foreach ($roles as $role) {
if (in_array($role, $currentUserRoles)) {
return true;
}
}
return false;
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。