aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/ConfigValues/ConfigValuesShow.php
blob: fd385a38bf9f87a69ba8648c4c12f2993df444c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace JsonApi\Routes\ConfigValues;

use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\JsonApiController;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class ConfigValuesShow extends JsonApiController
{
    use HelperTrait;

    protected $allowedIncludePaths = [];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        list($rangeId, $field) = $this->parseId($args['id']);
        $range = $this->getRange($rangeId);
        if (!Authority::canShowConfigValue($this->getUser($request), $range)) {
            throw new AuthorizationFailedException();
        }
        $configValue = $this->findOrFakeConfigValue($range, $field);

        return $this->getContentResponse($configValue);
    }
}