summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Common/Configuration/Parser/ListParser.php
blob: f27b16597b08ed07d1d6d1092c31499859ef1bb1 (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
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Common\Configuration\Parser;

class ListParser
{
    private const DEFAULT_SEPARATOR = ',';

    /**
     * @param string|array $value
     */
    public static function parse($value): array
    {
        if (is_array($value)) {
            return $value;
        }
        if (trim($value) === '') {
            return [];
        }

        return array_map(
            fn ($value) => trim($value),
            explode(self::DEFAULT_SEPARATOR, $value)
        );
    }
}