2019-06-10 21:04:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2019-06-11 20:07:46 +02:00
|
|
|
* Creates Decoder objects.
|
2019-06-10 21:04:10 +02:00
|
|
|
*
|
|
|
|
* @author Chris Wright <https://github.com/DaveRandom>
|
|
|
|
* @copyright Copyright (c) Chris Wright <https://github.com/DaveRandom>,
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
2019-06-11 20:07:46 +02:00
|
|
|
|
2019-06-10 21:04:10 +02:00
|
|
|
namespace Amp\DoH;
|
|
|
|
|
|
|
|
use \LibDNS\Messages\MessageFactory;
|
2019-06-11 20:07:46 +02:00
|
|
|
use \LibDNS\Packets\PacketFactory;
|
2019-06-10 21:04:10 +02:00
|
|
|
use \LibDNS\Records\QuestionFactory;
|
|
|
|
use \LibDNS\Records\RDataBuilder;
|
|
|
|
use \LibDNS\Records\RDataFactory;
|
2019-06-11 20:07:46 +02:00
|
|
|
use \LibDNS\Records\RecordCollectionFactory;
|
|
|
|
use \LibDNS\Records\ResourceBuilder;
|
|
|
|
use \LibDNS\Records\ResourceFactory;
|
|
|
|
use \LibDNS\Records\TypeDefinitions\FieldDefinitionFactory;
|
|
|
|
use \LibDNS\Records\TypeDefinitions\TypeDefinitionFactory;
|
|
|
|
use \LibDNS\Records\TypeDefinitions\TypeDefinitionManager;
|
2019-06-10 21:04:10 +02:00
|
|
|
use \LibDNS\Records\Types\TypeBuilder;
|
|
|
|
use \LibDNS\Records\Types\TypeFactory;
|
|
|
|
use LibDNS\Decoder\DecodingContextFactory;
|
|
|
|
|
|
|
|
/**
|
2019-06-11 20:07:46 +02:00
|
|
|
* Creates JsonDecoder objects.
|
2019-06-10 21:04:10 +02:00
|
|
|
*
|
|
|
|
* @author Chris Wright <https://github.com/DaveRandom>
|
|
|
|
*/
|
|
|
|
class JsonDecoderFactory
|
|
|
|
{
|
|
|
|
/**
|
2019-06-11 20:07:46 +02:00
|
|
|
* Create a new JsonDecoder object.
|
2019-06-10 21:04:10 +02:00
|
|
|
*
|
|
|
|
* @param \LibDNS\Records\TypeDefinitions\TypeDefinitionManager $typeDefinitionManager
|
|
|
|
* @return JsonDecoder
|
|
|
|
*/
|
|
|
|
public function create(TypeDefinitionManager $typeDefinitionManager = null): JsonDecoder
|
|
|
|
{
|
|
|
|
$typeBuilder = new TypeBuilder(new TypeFactory);
|
|
|
|
|
|
|
|
return new JsonDecoder(
|
|
|
|
new PacketFactory,
|
|
|
|
new MessageFactory(new RecordCollectionFactory),
|
|
|
|
new QuestionFactory,
|
|
|
|
new ResourceBuilder(
|
|
|
|
new ResourceFactory,
|
|
|
|
new RDataBuilder(
|
|
|
|
new RDataFactory,
|
|
|
|
$typeBuilder
|
|
|
|
),
|
|
|
|
$typeDefinitionManager ?: new TypeDefinitionManager(
|
|
|
|
new TypeDefinitionFactory,
|
|
|
|
new FieldDefinitionFactory
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$typeBuilder,
|
|
|
|
new DecodingContextFactory
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|