firefly-iii/app/Transformers/UserTransformer.php

79 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* UserTransformer.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Transformers;
2018-02-13 11:24:06 -06:00
use FireflyIII\Models\Role;
2018-12-20 15:03:34 -06:00
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Log;
/**
* Class UserTransformer
*/
class UserTransformer extends AbstractTransformer
{
2018-12-20 15:03:34 -06:00
/** @var UserRepositoryInterface */
private $repository;
/**
2018-02-17 03:47:06 -06:00
* UserTransformer constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
2018-12-20 15:03:34 -06:00
$this->repository = app(UserRepositoryInterface::class);
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
}
}
/**
2018-02-17 03:47:06 -06:00
* Transform user.
*
* @param User $user
*
* @return array
*/
public function transform(User $user): array
{
return [
2018-02-11 00:46:34 -06:00
'id' => (int)$user->id,
'created_at' => $user->created_at->toAtomString(),
2018-12-12 13:30:25 -06:00
'updated_at' => $user->updated_at->toAtomString(),
2018-02-11 00:46:34 -06:00
'email' => $user->email,
2018-08-06 12:14:30 -05:00
'blocked' => 1 === (int)$user->blocked,
2018-12-03 00:18:05 -06:00
'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code,
2018-12-20 15:03:34 -06:00
'role' => $this->repository->getRoleByUser($user),
2018-02-11 00:46:34 -06:00
'links' => [
[
'rel' => 'self',
2018-02-11 00:46:34 -06:00
'uri' => '/users/' . $user->id,
],
],
];
}
2018-03-05 12:35:58 -06:00
}