Skip to content

Commit

Permalink
change Chain constructor to variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
chthomas committed Dec 5, 2018
1 parent b5f45d6 commit daaee08
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bootstrap/repl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 5 additions & 0 deletions src/Resolvers/Cached.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions src/Resolvers/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -45,23 +45,23 @@ 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;
}

public function withFirstResults(): Interfaces\Chain
{
$first = new self($this->resolvers);
$first = new self(...$this->resolvers);
$first->callThroughStrategy = self::STRATEGY_FIRST_TO_FIND;

return $first;
}

public function withConsensusResults(): Interfaces\Chain
{
$consensus = new self($this->resolvers);
$consensus = new self(...$this->resolvers);
$consensus->callThroughStrategy = self::STRATEGY_CONSENSUS;

return $consensus;
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/BaseTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Resolvers/ChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit daaee08

Please sign in to comment.