summaryrefslogtreecommitdiffstats
path: root/library/Director/RestApi/RestApiParams.php
blob: c237ac512b676f3fc54d196e68da08817b92206c (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
<?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();
        }
        $properties = $params->shift('properties');
        if ($properties !== null && strlen($properties)) {
            $exporter->filterProperties(preg_split('/\s*,\s*/', $properties, -1, PREG_SPLIT_NO_EMPTY));
        }
        $exporter->resolveObjects($resolved);
        $exporter->showDefaults($withNull);
    }
}