Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get name of a repository var in Symfony

I have a function that checks if a user has access to a repository.

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

The Call

/* Get Client */
$client = $em->getRepository('AppBundle:Client')->find($request->get('clientId'));

/* Get ACL */
$this->get('global_functions')->getACL($client, 'VIEW');

What I'd like to get

I would like to see the name of the repository the user has been denied to, like this:

$this->get('log')->writeLog('Access denied to $REPOSITORYNAME.', __LINE__, 3);

in this case $REPOSITORYNAME should be AppBundle:Client or even only Client

Is that at all possible? is there a way t

like image 957
PrimuS Avatar asked Jan 18 '26 04:01

PrimuS


1 Answers

May be so

$this->get('log')->writeLog('Access denied to '.get_class($repository).'.', __LINE__, 3);

or

$class = get_class($repository);
$this->get('log')->writeLog('Access denied to '.substr($class, strrpos($class, '\\') + 1).'.', __LINE__, 3);

or I didn't understand question

like image 65
Max P. Avatar answered Jan 20 '26 18:01

Max P.