1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Transformers\OAuth;
7
8use App\Models\OAuth\Client;
9use App\Transformers\TransformerAbstract;
10use App\Transformers\UserCompactTransformer;
11
12class ClientTransformer extends TransformerAbstract
13{
14 protected array $availableIncludes = [
15 'redirect',
16 'secret',
17 'user',
18 ];
19
20 protected $permissions = [
21 'redirect' => 'IsOwnClient',
22 'secret' => 'IsOwnClient',
23 ];
24
25 public function transform(Client $client)
26 {
27 return [
28 'id' => $client->id,
29 'name' => $client->name,
30 'password_client' => $client->password_client,
31 'personal_access_client' => $client->personal_access_client,
32 'scopes' => $client->scopes,
33 'user_id' => $client->user_id,
34 ];
35 }
36
37 public function includeUser(Client $client)
38 {
39 return $this->item($client->user, new UserCompactTransformer());
40 }
41
42 public function includeRedirect(Client $client)
43 {
44 return $this->primitive($client->redirect);
45 }
46
47 public function includeSecret(Client $client)
48 {
49 return $this->primitive($client->secret);
50 }
51}