summaryrefslogtreecommitdiffstats
path: root/library/Director/RestApi/RestApiParams.php
blob: 741eeed114d7fb7dd81bf104698f8b5133cadf67 (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 Icinga\Module\Director\RestApi;

use Icinga\Module\Director\Data\Exporter;
use Icinga\Web\Request;
use InvalidArgumentException;

class RestApiParams
{
    public static function applyParamsToExporter(Exporter $exporter, Request $request, $shortObjectType = null)
    {
        $params = $request->getUrl()->getParams();
        $resolved = (bool) $params->get('resolved', false);
        $withNull = $params->shift('withNull');
        if ($params->get('withServices')) {
            if ($shortObjectType !== 'host') {
                throw new InvalidArgumentException('withServices is available for Hosts only');
            }
            $exporter->enableHostServices();
        }
        /** @var ?string $properties */
        $properties = $params->shift('properties');
        if ($properties) {
            $exporter->filterProperties(preg_split('/\s*,\s*/', $properties, -1, PREG_SPLIT_NO_EMPTY));
        }
        $exporter->resolveObjects($resolved);
        $exporter->showDefaults($withNull);
    }
}