|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * This file is part of MineAdmin. |
| 6 | + * |
| 7 | + * @link https://www.mineadmin.com |
| 8 | + * @document https://doc.mineadmin.com |
| 9 | + |
| 10 | + * @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE |
| 11 | + */ |
| 12 | + |
| 13 | +namespace Mine\Security\Http; |
| 14 | + |
| 15 | +use Hyperf\Context\Traits\CoroutineProxy; |
| 16 | +use Hyperf\Database\Model\Builder; |
| 17 | +use Mine\SecurityBundle\Contract\UserInterface; |
| 18 | +use Mine\SecurityBundle\Security; |
| 19 | +use Psr\Container\ContainerInterface; |
| 20 | + |
| 21 | +use function Hyperf\Support\call; |
| 22 | + |
| 23 | +class CurrentUserProxy implements UserInterface |
| 24 | +{ |
| 25 | + use CoroutineProxy; |
| 26 | + |
| 27 | + protected string $proxyKey = 'secret.http.proxy'; |
| 28 | + |
| 29 | + private Security $security; |
| 30 | + |
| 31 | + public function __construct( |
| 32 | + private string $scene, |
| 33 | + private ContainerInterface $container |
| 34 | + ) { |
| 35 | + $this->security = $this->container->get(Security::class); |
| 36 | + } |
| 37 | + |
| 38 | + public function __get($name) |
| 39 | + { |
| 40 | + return $this->getAttributes()[$name] ?? null; |
| 41 | + } |
| 42 | + |
| 43 | + public function getEntity(): UserInterface |
| 44 | + { |
| 45 | + return $this->getSecurity()->getToken()->user($this->scene); |
| 46 | + } |
| 47 | + |
| 48 | + public function getIdentifier(): string |
| 49 | + { |
| 50 | + return call([$this->getEntity(), __FUNCTION__]); |
| 51 | + } |
| 52 | + |
| 53 | + public function getIdentifierName(): string |
| 54 | + { |
| 55 | + return call([$this->getEntity(), __FUNCTION__]); |
| 56 | + } |
| 57 | + |
| 58 | + public function getRememberToken(): string |
| 59 | + { |
| 60 | + return call([$this->getEntity(), __FUNCTION__]); |
| 61 | + } |
| 62 | + |
| 63 | + public function setRememberToken(string $token): void |
| 64 | + { |
| 65 | + call([$this->getEntity(), __FUNCTION__], func_get_args()); |
| 66 | + } |
| 67 | + |
| 68 | + public function getRememberTokenName(): string |
| 69 | + { |
| 70 | + return call([$this->getEntity(), __FUNCTION__]); |
| 71 | + } |
| 72 | + |
| 73 | + public function getPassword(): string |
| 74 | + { |
| 75 | + return call([$this->getEntity(), __FUNCTION__]); |
| 76 | + } |
| 77 | + |
| 78 | + public function setPassword(string $password): void |
| 79 | + { |
| 80 | + call([$this->getEntity(), __FUNCTION__]); |
| 81 | + } |
| 82 | + |
| 83 | + public function getSecurityBuilder(): Builder |
| 84 | + { |
| 85 | + return call([$this->getEntity(), __FUNCTION__]); |
| 86 | + } |
| 87 | + |
| 88 | + public function setAttribute(string $key, mixed $value) |
| 89 | + { |
| 90 | + return call([$this->getEntity(), __FUNCTION__]); |
| 91 | + } |
| 92 | + |
| 93 | + public function getAttributes(): array |
| 94 | + { |
| 95 | + return call([$this->getEntity(), __FUNCTION__]); |
| 96 | + } |
| 97 | + |
| 98 | + protected function getSecurity(): Security |
| 99 | + { |
| 100 | + return $this->security; |
| 101 | + } |
| 102 | +} |
0 commit comments