我有一个功能可以检查用户是否有权访问存储库。
public function getACL($repository, $granted){
if (false === $this->authorizationChecker->isGranted($granted, $repository)) {
$this->get('log')->writeLog('Access denied.', __LINE__, 3);
return new JsonResponse(array(
'result' => 'error',
'message' => 'Not allowed'
));
}
return true;
}
调用
/* Get Client */
$client = $em->getRepository('AppBundle:Client')->find($request->get('clientId'));
/* Get ACL */
$this->get('global_functions')->getACL($client, 'VIEW');
我想要什么
我想查看用户被拒绝访问的存储库的名称,如下所示:
$this->get('log')->writeLog('Access denied to $REPOSITORYNAME.', __LINE__, 3);
在这种情况下
$REPOSITORYNAME
应该是 AppBundle:Client
甚至只有 Client
这可能吗?
有没有办法
最佳答案
也许是这样
$this->get('log')->writeLog('Access denied to '.get_class($repository).'.', __LINE__, 3);
或者
$class = get_class($repository);
$this->get('log')->writeLog('Access denied to '.substr($class, strrpos($class, '\\') + 1).'.', __LINE__, 3);
或者我不明白问题
关于php - 在 Symfony 中获取存储库变量的名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38630973/