2016-07-28 16 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); 

或者我不明白的問題

相關問題