"Fossies" - the Fresh Open Source Software Archive

Member "neos-development-collection-7.0.1/Neos.Neos/Classes/Service/UserService.php" (23 Feb 2021, 3507 Bytes) of package /linux/www/neos-development-collection-7.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "UserService.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 namespace Neos\Neos\Service;
    3 
    4 /*
    5  * This file is part of the Neos.Neos package.
    6  *
    7  * (c) Contributors of the Neos Project - www.neos.io
    8  *
    9  * This package is Open Source Software. For the full copyright and license
   10  * information, please view the LICENSE file which was distributed with this
   11  * source code.
   12  */
   13 
   14 use Neos\Flow\Annotations as Flow;
   15 use Neos\Neos\Domain\Model\User;
   16 use Neos\ContentRepository\Domain\Model\Workspace;
   17 use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
   18 use Neos\Neos\Utility\User as UserUtility;
   19 
   20 /**
   21  * The user service provides general context information about the currently
   22  * authenticated backend user.
   23  *
   24  * The methods getters of this class are accessible via the "context.userInformation" variable in security policies
   25  * and thus are implicitly considered to be part of the public API. This UserService should be replaced by
   26  * \Neos\Neos\Domain\Service\UserService in the long run.
   27  *
   28  * @Flow\Scope("singleton")
   29  * @api
   30  */
   31 class UserService
   32 {
   33 
   34     /**
   35      * @Flow\Inject
   36      * @var \Neos\Neos\Domain\Service\UserService
   37      */
   38     protected $userDomainService;
   39 
   40     /**
   41      * @Flow\Inject
   42      * @var WorkspaceRepository
   43      */
   44     protected $workspaceRepository;
   45 
   46     /**
   47      * @Flow\InjectConfiguration("userInterface.defaultLanguage")
   48      * @var string
   49      */
   50     protected $defaultLanguageIdentifier;
   51 
   52     /**
   53      * @Flow\Inject
   54      * @var \Neos\Flow\Security\Context
   55      */
   56     protected $securityContext;
   57 
   58     /**
   59      * Returns the current backend user
   60      *
   61      * @return User
   62      * @api
   63      */
   64     public function getBackendUser()
   65     {
   66         return $this->userDomainService->getCurrentUser();
   67     }
   68 
   69     /**
   70      * Returns the current user's personal workspace or null if no user is logged in
   71      *
   72      * @return Workspace
   73      * @api
   74      */
   75     public function getPersonalWorkspace()
   76     {
   77         $workspaceName = $this->getPersonalWorkspaceName();
   78         if ($workspaceName !== null) {
   79             return $this->workspaceRepository->findOneByName($workspaceName);
   80         }
   81     }
   82 
   83     /**
   84      * Returns the name of the currently logged in user's personal workspace (even if that might not exist at that time).
   85      * If no user is logged in this method returns null.
   86      *
   87      * @return string
   88      * @api
   89      */
   90     public function getPersonalWorkspaceName()
   91     {
   92         $currentUser = $this->userDomainService->getCurrentUser();
   93 
   94         if (!$currentUser instanceof User) {
   95             return null;
   96         }
   97 
   98         $username = $this->userDomainService->getUsername(
   99             $currentUser,
  100             $this->securityContext->getAccount()->getAuthenticationProviderName()
  101         );
  102         return ($username === null ? null : UserUtility::getPersonalWorkspaceNameForUsername($username));
  103     }
  104 
  105     /**
  106      * Returns the stored preferences of a user
  107      *
  108      * @param string $preference
  109      * @return mixed
  110      * @api
  111      */
  112     public function getUserPreference($preference)
  113     {
  114         $user = $this->getBackendUser();
  115         if ($user && $user->getPreferences()) {
  116             return $user->getPreferences()->get($preference) ?: null;
  117         }
  118     }
  119 
  120     /**
  121      * Returns the interface language the user selected. Will fall back to the default language defined in settings
  122      *
  123      * @return string
  124      * @api
  125      */
  126     public function getInterfaceLanguage()
  127     {
  128         return $this->getUserPreference('interfaceLanguage') ?: $this->defaultLanguageIdentifier;
  129     }
  130 }