Completed
Push — master ( 282f78...6dce89 )
by Sam
05:20
created

YamlResolver::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of PHP DNS Server.
4
 *
5
 * (c) Yif Swery <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace yswery\DNS\Resolver;
12
13
use Symfony\Component\Yaml\Yaml;
14
use yswery\DNS\UnsupportedTypeException;
15
16
/**
17
 * Store dns records in yaml files.
18
 */
19
class YamlResolver extends JsonResolver
20
{
21
    /**
22
     * YamlResolver constructor.
23
     *
24
     * @param array $files
25
     * @param int   $defaultTtl
26
     *
27
     * @throws UnsupportedTypeException
28
     */
29
    public function __construct(array $files, $defaultTtl = 300)
30
    {
31
        parent::__construct([], $defaultTtl);
32
33
        foreach ($files as $file) {
34
            $zone = Yaml::parseFile($file);
35
            $resourceRecords = $this->isLegacyFormat($zone) ? $this->processLegacyZone($zone) : $this->processZone($zone);
36
            $this->addZone($resourceRecords);
37
        }
38
    }
39
}
40