mirror of
https://github.com/danog/LibDNSJson.git
synced 2024-11-30 04:19:14 +01:00
Parse multi-field records
This commit is contained in:
parent
24908c65f4
commit
7d5e07815d
@ -127,6 +127,7 @@ class JsonDecoder
|
||||
$labels[] = $last;
|
||||
}
|
||||
$domainName->setLabels($labels);
|
||||
/* @var \LibDNS\Records\Resource $resource */
|
||||
$resource = $this->resourceBuilder->build($record['type']);
|
||||
$resource->setName($domainName);
|
||||
//$resource->setClass($meta['class']);
|
||||
@ -134,12 +135,14 @@ class JsonDecoder
|
||||
|
||||
$data = $resource->getData();
|
||||
|
||||
$typeDef = $data->getTypeDefinition();
|
||||
$record['data'] = explode(' ', $record['data'], $typeDef->count());
|
||||
|
||||
$fieldDef = $index = null;
|
||||
foreach ($resource->getData()->getTypeDefinition() as $index => $fieldDef) {
|
||||
foreach ($data->getTypeDefinition() as $index => $fieldDef) {
|
||||
$field = $this->typeBuilder->build($fieldDef->getType());
|
||||
$this->decodeType($field, $record['data']);
|
||||
$this->decodeType($field, $record['data'][$index]);
|
||||
$data->setField($index, $field);
|
||||
break; // For now parse only one field
|
||||
}
|
||||
|
||||
return $resource;
|
||||
|
@ -83,6 +83,10 @@ class JsonDecoderTest extends TestCase
|
||||
'{"Status": 0,"TC": false,"RD": true, "RA": true, "AD": false,"CD": false,"Question":[{"name": "amphp.org.", "type": 15}],"Answer":[{"name": "amphp.org.", "type": 15, "TTL": 86400, "data": "0 mail.negativeion.net."}]}',
|
||||
3,
|
||||
],
|
||||
[
|
||||
'{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "daniil.it.","type": 6}],"Answer":[ {"name": "daniil.it.","type": 6,"TTL": 3493,"data": "cruz.ns.cloudflare.com. dns.cloudflare.com. 2031387933 10000 2400 604800 3600"}]}',
|
||||
3,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user