2016-07-28 86 views
3

我有一个函数检查用户是否有权访问存储库。在Symfony中获取存储库var的名称

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

这是否可能? 是有办法牛逼

+1

首先,你不处理库在这里,但它是从库中检索到的'Client'(实体)的一个实例。同时检查'get_class()'函数。 –

回答

2

可能是这样

$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); 

或者我不明白的问题

相关问题