request()->user() ?? throw new UnexpectedValueException('Client API transformers require an authenticated user.'); } /** * Determine if the API key loaded onto the transformer has permission * to access a different resource. This is used when including other * models on a transformation request. * * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ protected function authorize(string $ability, ?Server $server = null): bool { throw_unless($server instanceof Server, InvalidArgumentException::class, 'Expected a server when authorizing client transformer includes.'); return $this->getUser()->can($ability, [$server]); } /** * @template T of BaseClientTransformer * * @param class-string $abstract * @return T */ protected function makeTransformer(string $abstract): self { throw_unless(is_subclass_of($abstract, self::class), InvalidTransformerLevelException::class, "Transformer [$abstract] must extend ".self::class.'.'); return parent::makeTransformer($abstract); } }