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;
7
8use League\Fractal;
9
10class TransformerAbstract extends Fractal\TransformerAbstract
11{
12 protected $permissions = [];
13 protected $requiredPermission;
14
15 public function getPermissions()
16 {
17 return $this->permissions;
18 }
19
20 public function getRequiredPermission()
21 {
22 return $this->requiredPermission;
23 }
24
25 protected function callIncludeMethod(Fractal\Scope $scope, $includeName, $data)
26 {
27 if (!$this->hasPermission($includeName, $data)) {
28 return false;
29 }
30
31 return parent::callIncludeMethod($scope, $includeName, $data);
32 }
33
34 protected function hasPermission($include, $data)
35 {
36 $permissionRequired = $this->permissions[$include] ?? null;
37
38 return $permissionRequired === null || priv_check($permissionRequired, $data)->can();
39 }
40}