Newscoop\Services\UserService::getCurrentUser PHP Метод

getCurrentUser() публичный Метод

Get current user
public getCurrentUser ( ) : User
Результат Newscoop\Entity\User
    public function getCurrentUser()
    {
        if ($this->currentUser === null) {
            if ($this->auth->hasIdentity()) {
                $this->currentUser = $this->getRepository()->find($this->auth->getIdentity());
            } elseif ($this->security->getToken()) {
                if ($this->security->getToken()->getUser()) {
                    $currentUser = $this->security->getToken()->getUser();
                    if ($this->security->isGranted('IS_AUTHENTICATED_FULLY') || $this->security->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
                        $this->currentUser = $currentUser;
                    } else {
                        throw new AuthenticationException();
                    }
                } else {
                    throw new AuthenticationException();
                }
            }
        }
        return $this->currentUser;
    }

Usage Example

 public function let($die, \Doctrine\ORM\EntityManager $em, \Symfony\Component\Routing\Router $router, UserService $userService, \Newscoop\Entity\Repository\AutoIdRepository $repository, \Newscoop\Entity\User $user)
 {
     $em->getRepository('Newscoop\\Entity\\AutoId')->willReturn($repository);
     $em->persist(Argument::any())->willReturn(true);
     $em->flush(Argument::any())->willReturn(true);
     $em->remove(Argument::any())->willReturn(true);
     $repository->getNextTranslationPhraseId()->willReturn('7');
     $user->hasPermission('AddFile')->willReturn(true);
     $userService->getCurrentUser()->willReturn($user);
     $this->beConstructedWith(array('file_base_url' => "files/", 'file_directory' => realpath(__DIR__ . '/../../../newscoop/public/files') . '/', 'file_num_dirs_level_1' => 1000, 'file_num_dirs_level_2' => 1000), $em, $router, $userService);
 }
All Usage Examples Of Newscoop\Services\UserService::getCurrentUser