diff --git a/bootstrap/repl.php b/bootstrap/repl.php index 7426efd..6b1f515 100644 --- a/bootstrap/repl.php +++ b/bootstrap/repl.php @@ -24,6 +24,6 @@ class_alias(DNSRecordCollection::class, 'DNSRecordCollection'); $cloudFlareResolver = new \RemotelyLiving\PHPDNS\Resolvers\CloudFlare(); $cloudFlareResolver->addSubscriber($IOSubscriber); -$chainResolver = new \RemotelyLiving\PHPDNS\Resolvers\Chain([$cloudFlareResolver, $googleDNSResolver, $localSystemResolver]); +$chainResolver = new \RemotelyLiving\PHPDNS\Resolvers\Chain($cloudFlareResolver, $googleDNSResolver, $localSystemResolver); $cachedResolver = new \RemotelyLiving\PHPDNS\Resolvers\Cached(new \Symfony\Component\Cache\Adapter\FilesystemAdapter(), $chainResolver); $cachedResolver->addSubscriber($IOSubscriber); \ No newline at end of file diff --git a/src/Resolvers/Cached.php b/src/Resolvers/Cached.php index d81698b..ae5092c 100644 --- a/src/Resolvers/Cached.php +++ b/src/Resolvers/Cached.php @@ -39,6 +39,11 @@ public function __construct(CacheItemPoolInterface $cache, Resolver $resolver, i $this->ttlSeconds = $ttlSeconds; } + public function flush(): void + { + $this->cache->clear(); + } + protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRecordCollection { $cachedResult = $this->cache->getItem($this->buildCacheKey($hostname, $recordType)); diff --git a/src/Resolvers/Chain.php b/src/Resolvers/Chain.php index caff493..81b9411 100644 --- a/src/Resolvers/Chain.php +++ b/src/Resolvers/Chain.php @@ -29,7 +29,7 @@ class Chain extends ResolverAbstract implements Interfaces\Chain */ private $callThroughStrategy = self::STRATEGY_FIRST_TO_FIND; - public function __construct(array $resolvers = []) + public function __construct(Resolver...$resolvers) { foreach ($resolvers as $resolver) { $this->pushResolver($resolver); @@ -45,7 +45,7 @@ public function pushResolver(Resolver...$resolvers): void public function withAllResults(): Interfaces\Chain { - $all = new self($this->resolvers); + $all = new self(...$this->resolvers); $all->callThroughStrategy = self::STRATEGY_ALL_RESULTS; return $all; @@ -53,7 +53,7 @@ public function withAllResults(): Interfaces\Chain public function withFirstResults(): Interfaces\Chain { - $first = new self($this->resolvers); + $first = new self(...$this->resolvers); $first->callThroughStrategy = self::STRATEGY_FIRST_TO_FIND; return $first; @@ -61,7 +61,7 @@ public function withFirstResults(): Interfaces\Chain public function withConsensusResults(): Interfaces\Chain { - $consensus = new self($this->resolvers); + $consensus = new self(...$this->resolvers); $consensus->callThroughStrategy = self::STRATEGY_CONSENSUS; return $consensus; diff --git a/tests/Integration/BaseTestAbstract.php b/tests/Integration/BaseTestAbstract.php index 54ee372..ee3448b 100644 --- a/tests/Integration/BaseTestAbstract.php +++ b/tests/Integration/BaseTestAbstract.php @@ -39,7 +39,7 @@ protected function createLocalSystemDNS(): LocalSystemDNS protected function createChainResolver(Resolver...$resolvers): Chain { - return new Chain($resolvers); + return new Chain(...$resolvers); } protected function createCachePool(): CacheItemPoolInterface diff --git a/tests/Unit/Resolvers/ChainTest.php b/tests/Unit/Resolvers/ChainTest.php index e83d471..b2a3e68 100644 --- a/tests/Unit/Resolvers/ChainTest.php +++ b/tests/Unit/Resolvers/ChainTest.php @@ -35,7 +35,7 @@ protected function setUp() $this->resolver1 = $this->createMock(ObservableResolver::class); $this->resolver2 = $this->createMock(ObservableResolver::class); - $this->chainResolver = new Chain([$this->resolver1, $this->resolver2]); + $this->chainResolver = new Chain($this->resolver1, $this->resolver2); $this->assertInstanceOf(ResolverAbstract::class, $this->chainResolver); }