|  | 
|  | 1 | +<?php | 
|  | 2 | + | 
|  | 3 | +/** | 
|  | 4 | + * This file is part of the Phalcon API. | 
|  | 5 | + * | 
|  | 6 | + * (c) Phalcon Team <[email protected]> | 
|  | 7 | + * | 
|  | 8 | + * For the full copyright and license information, please view | 
|  | 9 | + * the LICENSE file that was distributed with this source code. | 
|  | 10 | + */ | 
|  | 11 | + | 
|  | 12 | +declare(strict_types=1); | 
|  | 13 | + | 
|  | 14 | +namespace Phalcon\Api\Domain\DataSource\User; | 
|  | 15 | + | 
|  | 16 | +use Phalcon\Api\Domain\Exceptions\InvalidConfigurationArgumentException; | 
|  | 17 | + | 
|  | 18 | +/** | 
|  | 19 | + * @method int    getId() | 
|  | 20 | + * @method int    getStatus() | 
|  | 21 | + * @method string getUsername() | 
|  | 22 | + * @method string getPassword() | 
|  | 23 | + * | 
|  | 24 | + * @phpstan-import-type TUserRecord from UserTypes | 
|  | 25 | + * @phpstan-import-type TUserTransport from UserTypes | 
|  | 26 | + */ | 
|  | 27 | +final class UserTransport | 
|  | 28 | +{ | 
|  | 29 | +    /** @var TUserTransport */ | 
|  | 30 | +    private array $store; | 
|  | 31 | + | 
|  | 32 | +    /** | 
|  | 33 | +     * @param TUserRecord $input | 
|  | 34 | +     */ | 
|  | 35 | +    public function __construct(array $input) | 
|  | 36 | +    { | 
|  | 37 | +        $this->store = [ | 
|  | 38 | +            'id'       => (int)($input['usr_id'] ?? 0), | 
|  | 39 | +            'status'   => (int)($input['usr_status_flag'] ?? 0), | 
|  | 40 | +            'username' => (string)($input['usr_username'] ?? ''), | 
|  | 41 | +            'password' => (string)($input['usr_password'] ?? ''), | 
|  | 42 | +        ]; | 
|  | 43 | +    } | 
|  | 44 | + | 
|  | 45 | +    /** | 
|  | 46 | +     * @param string       $name | 
|  | 47 | +     * @param array<mixed> $arguments | 
|  | 48 | +     * | 
|  | 49 | +     * @return int|string | 
|  | 50 | +     */ | 
|  | 51 | +    public function __call(string $name, array $arguments): int | string | 
|  | 52 | +    { | 
|  | 53 | +        return match ($name) { | 
|  | 54 | +            'getId'       => $this->store['id'], | 
|  | 55 | +            'getStatus'   => $this->store['status'], | 
|  | 56 | +            'getUsername' => $this->store['username'], | 
|  | 57 | +            'getPassword' => $this->store['password'], | 
|  | 58 | +            default       => throw new InvalidConfigurationArgumentException( | 
|  | 59 | +                'The ' . $name . ' method is not supported. [' | 
|  | 60 | +                . json_encode($arguments) . ']', | 
|  | 61 | +            ), | 
|  | 62 | +        }; | 
|  | 63 | +    } | 
|  | 64 | + | 
|  | 65 | +    public function isEmpty(): bool | 
|  | 66 | +    { | 
|  | 67 | +        return 0 === $this->store['id']; | 
|  | 68 | +    } | 
|  | 69 | + | 
|  | 70 | +    /** | 
|  | 71 | +     * @return array<int, TUserTransport> | 
|  | 72 | +     */ | 
|  | 73 | +    public function toArray(): array | 
|  | 74 | +    { | 
|  | 75 | +        return [$this->store['id'] => $this->store]; | 
|  | 76 | +    } | 
|  | 77 | +} | 
0 commit comments