2016-07-28 13 views
3

私は、ユーザがリポジトリにアクセスできるかどうかをチェックする機能を持っています。symfonyのリポジトリ名の取得

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

または私はすべての

関連する問題