vendor/ezsystems/ezplatform-user/src/lib/UserSetting/UserSettingArrayAccessor.php line 17

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace EzSystems\EzPlatformUser\UserSetting;
  8. use ArrayAccess;
  9. use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
  10. /**
  11.  * @internal
  12.  */
  13. class UserSettingArrayAccessor implements ArrayAccess
  14. {
  15.     /** @var \EzSystems\EzPlatformUser\UserSetting\UserSettingService */
  16.     protected $userSettingService;
  17.     /**
  18.      * @param \EzSystems\EzPlatformUser\UserSetting\UserSettingService $userSettingService
  19.      */
  20.     public function __construct(UserSettingService $userSettingService)
  21.     {
  22.         $this->userSettingService $userSettingService;
  23.     }
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     public function offsetExists($offset): bool
  28.     {
  29.         // @todo refactor once UserSettingService supports this natively
  30.         return null !== $this->userSettingService->getUserSetting($offset);
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function offsetGet($offset): string
  36.     {
  37.         return $this->userSettingService->getUserSetting($offset)->value;
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function offsetSet($offset$value): void
  43.     {
  44.         $this->userSettingService->setUserSetting($offset$value);
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function offsetUnset($offset): void
  50.     {
  51.         // UserSettingService doesn't provide this feature
  52.         throw new NotImplementedException('offsetUnset');
  53.     }
  54. }