From c8ae91502022f8dc27296d9a68373f1c6fd64a75 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 23 Oct 2023 14:24:33 +0200 Subject: [PATCH 1/7] feat(create-records): add support to pass ResourceRecord class this will make for a "cleaner" and more error-prone solution. Remembering the parameters for the array can be hard --- src/Resources/ResourceRecord.php | 13 +++++- src/Zone.php | 78 ++++++++++++++------------------ 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/Resources/ResourceRecord.php b/src/Resources/ResourceRecord.php index 1573455..1d467b4 100644 --- a/src/Resources/ResourceRecord.php +++ b/src/Resources/ResourceRecord.php @@ -271,6 +271,15 @@ public function getShortName(): string */ public function setName(string $name): self { + if ($this->getZone() !== null) { + $name = str_replace('@', $this->getZone()->getCanonicalName(), $name); + + // If the name of the record doesn't end in the zone name, append the zone name to it. + if (substr($name, -strlen($this->getZone()->getCanonicalName())) !== $this->getZone()->getCanonicalName()) { + $name = sprintf('%s.%s', $name, $this->getZone()->getCanonicalName()); + } + } + $this->name = $name; return $this; @@ -398,9 +407,9 @@ public function setType(string $type): self /** * Get the zone object for this ResourceRecord. * - * @return Zone The zone for this ResourceRecord. + * @return Zone|null The zone for this ResourceRecord. */ - public function getZone(): Zone + public function getZone(): ?Zone { return $this->zone; } diff --git a/src/Zone.php b/src/Zone.php index cb2c4ac..4c2c12c 100644 --- a/src/Zone.php +++ b/src/Zone.php @@ -3,7 +3,6 @@ namespace Exonet\Powerdns; use Exonet\Powerdns\Exceptions\InvalidNsec3Param; -use Exonet\Powerdns\Resources\Record; use Exonet\Powerdns\Resources\ResourceRecord; use Exonet\Powerdns\Resources\ResourceSet; use Exonet\Powerdns\Transformers\DnssecTransformer; @@ -14,14 +13,13 @@ use Exonet\Powerdns\Transformers\SoaEditTransformer; use Exonet\Powerdns\Transformers\Transformer; -class Zone extends AbstractZone -{ +class Zone extends AbstractZone { /** * Create one or more new resource records in the current zone. If $name is passed as multidimensional array those * resource records will be created in a single call to the PowerDNS server. If $name is a string, a single resource * record is created. * - * @param mixed[]|string $name The resource record name. + * @param mixed[]|ResourceRecord|ResourceRecord[]|string $name The resource record name. * @param string $type The type of the resource record. * @param mixed[]|string $content The content of the resource record. When passing a multidimensional array, * multiple records are created for this resource record. @@ -32,15 +30,22 @@ class Zone extends AbstractZone * * @return bool True when created. */ - public function create($name, string $type = '', $content = '', int $ttl = 3600, array $comments = []): bool - { + public function create($name, string $type = '', $content = '', int $ttl = 3600, array $comments = []): bool { if (is_array($name)) { $resourceRecords = []; foreach ($name as $item) { - $resourceRecords[] = $this->make($item['name'], $item['type'], $item['content'], $item['ttl'] ?? $ttl, $item['comments'] ?? []); + if ($item instanceof ResourceRecord) { + $resourceRecords[] = $item; + } else { + $resourceRecords[] = $this->make($item['name'], $item['type'], $item['content'], $item['ttl'] ?? $ttl, $item['comments'] ?? []); + } } } else { - $resourceRecords = [$this->make($name, $type, $content, $ttl, $comments)]; + if ($name instanceof ResourceRecord) { + $resourceRecords = [$name]; + } else { + $resourceRecords = [$this->make($name, $type, $content, $ttl, $comments)]; + } } return $this->patch($resourceRecords); @@ -53,8 +58,7 @@ public function create($name, string $type = '', $content = '', int $ttl = 3600, * * @return bool True when successful. */ - public function patch(array $resourceRecords): bool - { + public function patch(array $resourceRecords): bool { $result = $this->connector->patch($this->getZonePath(), new RRSetTransformer($resourceRecords)); // Invalidate the resource. $this->zoneResource = null; @@ -73,8 +77,7 @@ public function patch(array $resourceRecords): bool * * @return bool True when successful. */ - public function put(Transformer $transformer): bool - { + public function put(Transformer $transformer): bool { $result = $this->connector->put($this->getZonePath(), $transformer); // Invalidate the resource. $this->zoneResource = null; @@ -94,8 +97,7 @@ public function put(Transformer $transformer): bool * * @return ResourceSet A ResourceSet containing all the resource records. */ - public function get(?string $recordType = null): ResourceSet - { + public function get(?string $recordType = null): ResourceSet { $resourceSet = new ResourceSet($this); foreach ($this->resource()->getResourceRecords() as $rrset) { @@ -116,17 +118,16 @@ public function get(?string $recordType = null): ResourceSet * * @return ResourceSet A ResourceSet containing all the resource records. */ - public function find(string $resourceRecordName, ?string $recordType = null): ResourceSet - { + public function find(string $resourceRecordName, ?string $recordType = null): ResourceSet { $resourceRecordName = $resourceRecordName === '@' ? $this->zone : $resourceRecordName; - $records = $this->get($recordType); + $records = $this->get($recordType); $foundResources = new ResourceSet($this); foreach ($records as $record) { if ( $record->getName() === $resourceRecordName - || $record->getName() === $resourceRecordName.'.' + || $record->getName() === $resourceRecordName . '.' || $record->getName() === sprintf('%s.%s', $resourceRecordName, $this->zone) ) { $foundResources->addResource($record); @@ -149,8 +150,7 @@ public function find(string $resourceRecordName, ?string $recordType = null): Re * * @return ResourceRecord The constructed ResourceRecord. */ - public function make(string $name, string $type, $content, int $ttl, array $comments): ResourceRecord - { + public function make(string $name, string $type, $content, int $ttl, array $comments): ResourceRecord { return Helper::createResourceRecord($this->zone, compact('name', 'type', 'content', 'ttl', 'comments')); } @@ -159,8 +159,7 @@ public function make(string $name, string $type, $content, int $ttl, array $comm * * @return string The zone in AXFR format. */ - public function export(): string - { + public function export(): string { $result = $this->connector->get($this->getZonePath('/export')); return $result['zone']; @@ -178,9 +177,8 @@ public function export(): string * * @return bool True when updated. */ - public function setNsec3param(?string $nsec3param): bool - { - $zone = $this->resource()->setNsec3param($nsec3param); + public function setNsec3param(?string $nsec3param): bool { + $zone = $this->resource()->setNsec3param($nsec3param); $transformer = new Nsec3paramTransformer($zone); return $this->put($transformer); @@ -193,8 +191,7 @@ public function setNsec3param(?string $nsec3param): bool * * @return bool True when updated. */ - public function unsetNsec3param(): bool - { + public function unsetNsec3param(): bool { return $this->setNsec3param(null); } @@ -203,8 +200,7 @@ public function unsetNsec3param(): bool * * @return bool True when the DNS notify was successfully sent */ - public function notify(): bool - { + public function notify(): bool { $result = $this->connector->put($this->getZonePath('/notify')); /* @@ -219,8 +215,7 @@ public function notify(): bool * * @return bool True when enabled. */ - public function enableDnssec(): bool - { + public function enableDnssec(): bool { return $this->setDnssec(true); } @@ -229,8 +224,7 @@ public function enableDnssec(): bool * * @return bool True when disabled. */ - public function disableDnssec(): bool - { + public function disableDnssec(): bool { return $this->setDnssec(false); } @@ -241,8 +235,7 @@ public function disableDnssec(): bool * * @return bool True when the request succeeded. */ - public function setDnssec(bool $state): bool - { + public function setDnssec(bool $state): bool { return $this->put(new DnssecTransformer(['dnssec' => $state])); } @@ -251,8 +244,7 @@ public function setDnssec(bool $state): bool * * @return Cryptokey The DNSSEC instance. */ - public function dnssec(): Cryptokey - { + public function dnssec(): Cryptokey { return new Cryptokey($this->connector, $this->zone); } @@ -261,8 +253,7 @@ public function dnssec(): Cryptokey * * @return Meta The meta data. */ - public function meta(): Meta - { + public function meta(): Meta { return new Meta($this->connector, $this->zone); } @@ -273,8 +264,7 @@ public function meta(): Meta * * @return bool True when the request succeeded. */ - public function setSoaEdit(string $value): bool - { + public function setSoaEdit(string $value): bool { return $this->put(new SoaEditTransformer(['soa_edit' => $value])); } @@ -285,8 +275,7 @@ public function setSoaEdit(string $value): bool * * @return bool True when the request succeeded. */ - public function setSoaEditApi(string $value): bool - { + public function setSoaEditApi(string $value): bool { return $this->put(new SoaEditApiTransformer(['soa_edit_api' => $value])); } @@ -298,8 +287,7 @@ public function setSoaEditApi(string $value): bool * * @return bool True when the request succeeded. */ - public function setKind(string $kind, array $masters = []): bool - { + public function setKind(string $kind, array $masters = []): bool { $this->resource()->setKind($kind); $this->resource()->setMasters($masters); From 15c2345bb95c70c9fb7d1556298786d896724fef Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Wed, 18 Oct 2023 20:31:19 +0200 Subject: [PATCH 2/7] chore(tests): added tests for new object-based creation --- tests/ZoneTest.php | 106 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/ZoneTest.php b/tests/ZoneTest.php index 045c5e6..e454568 100644 --- a/tests/ZoneTest.php +++ b/tests/ZoneTest.php @@ -3,6 +3,10 @@ namespace Exonet\Powerdns\tests; use Exonet\Powerdns\Connector; +use Exonet\Powerdns\RecordType; +use Exonet\Powerdns\Resources\Comment; +use Exonet\Powerdns\Resources\Record; +use Exonet\Powerdns\Resources\ResourceRecord; use Exonet\Powerdns\Resources\Zone as ZoneResource; use Exonet\Powerdns\Transformers\RRSetTransformer; use Exonet\Powerdns\Zone; @@ -61,6 +65,34 @@ public function testCreateSingleResourceRecord(): void $zone->create('test', 'A', '127.0.0.1', 10); } + public function testCreateSingleResourceRecordFromClass(): void + { + $connector = Mockery::mock(Connector::class); + $connector->shouldReceive('patch')->withArgs(['zones/test.nl.', Mockery::on(function (RRSetTransformer $transformer) { + $data = $transformer->transform(); + + $this->assertSame('test.test.nl.', $data->rrsets[0]->name); + $this->assertSame('A', $data->rrsets[0]->type); + $this->assertSame(10, $data->rrsets[0]->ttl); + $this->assertSame('127.0.0.1', $data->rrsets[0]->records[0]->content); + + return true; + })]); + + $zone = new Zone($connector, 'test.nl'); + $rr = (new ResourceRecord()) + ->setName('test.test.nl.') + ->setType(RecordType::A) + ->setRecord('127.0.0.1') + ->setTtl(10) + ->setComments([ + (new Comment())->setContent('Hello')->setAccount('root')->setModifiedAt(1), + (new Comment())->setContent('Power')->setAccount('admin')->setModifiedAt(2), + (new Comment())->setContent('DNS')->setAccount('superuser')->setModifiedAt(3), + ]); + $zone->create($rr); + } + public function testCreateMultipleResourceRecords(): void { $connector = Mockery::mock(Connector::class); @@ -106,6 +138,80 @@ public function testCreateMultipleResourceRecords(): void ]); } + public function testCreateMultipleResourceRecordsFromClass(): void + { + $connector = Mockery::mock(Connector::class); + $connector->shouldReceive('patch')->withArgs(['zones/test.nl.', Mockery::on(function (RRSetTransformer $transformer) { + $data = $transformer->transform(); + + $this->assertSame('test.test.nl.', $data->rrsets[0]->name); + $this->assertSame('A', $data->rrsets[0]->type); + $this->assertSame(10, $data->rrsets[0]->ttl); + $this->assertSame('127.0.0.1', $data->rrsets[0]->records[0]->content); + + $this->assertSame('test.nl.', $data->rrsets[1]->name); + $this->assertSame('A', $data->rrsets[1]->type); + $this->assertSame(20, $data->rrsets[1]->ttl); + $this->assertSame('127.0.0.1', $data->rrsets[1]->records[0]->content); + + $this->assertSame('test.nl.', $data->rrsets[2]->name); + $this->assertSame('MX', $data->rrsets[2]->type); + $this->assertSame(30, $data->rrsets[2]->ttl); + $this->assertSame('10 mail01.test.nl.', $data->rrsets[2]->records[0]->content); + $this->assertSame('20 mail02.test.nl.', $data->rrsets[2]->records[1]->content); + + $this->assertSame('test02.test.nl.', $data->rrsets[3]->name); + $this->assertSame('A', $data->rrsets[3]->type); + $this->assertSame(40, $data->rrsets[3]->ttl); + $this->assertSame('127.0.0.1', $data->rrsets[3]->records[0]->content); + + $this->assertSame('test03.test.nl.', $data->rrsets[4]->name); + $this->assertSame('TXT', $data->rrsets[4]->type); + $this->assertSame(40, $data->rrsets[4]->ttl); + $this->assertSame('"v=DMARC1; p=none; rua=mailto:info@test.nl; ruf=mailto:info@test.nl"', $data->rrsets[4]->records[0]->content); + + return true; + })]); + + $zone = new Zone($connector, 'test.nl'); + $zone->create([ + (new ResourceRecord()) + ->setZone($zone) + ->setName('test') + ->setType(RecordType::A) + ->setRecord((new Record()) + ->setContent('127.0.0.1')) + ->setTtl(10), + (new ResourceRecord()) + ->setZone($zone) + ->setName('@') + ->setType(RecordType::A) + ->setRecord((new Record())->setContent('127.0.0.1')) + ->setTtl(20), + (new ResourceRecord()) + ->setZone($zone) + ->setName('@') + ->setType(RecordType::MX) + ->setRecords([ + (new Record())->setContent('10 mail01.test.nl.'), + (new Record())->setContent('20 mail02.test.nl.'), + ]) + ->setTtl(30), + (new ResourceRecord()) + ->setZone($zone) + ->setName('test02') + ->setType(RecordType::A) + ->setRecord((new Record())->setContent('127.0.0.1')) + ->setTtl(40), + + (new ResourceRecord()) + ->setZone($zone) + ->setName('test03') + ->setType(RecordType::TXT)->setRecord((new Record())->setContent('"v=DMARC1; p=none; rua=mailto:info@test.nl; ruf=mailto:info@test.nl"')) + ->setTtl(40), + ]); + } + public function testCreateNoResourceRecords(): void { $connector = Mockery::mock(Connector::class); From e8a7cf884a28595016d899a9016212a6add0399c Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Wed, 18 Oct 2023 20:31:30 +0200 Subject: [PATCH 3/7] chore(README): updated readme to reflect the possibility to pass objects --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 0644efc..5300d3f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Basic example how to create a new DNS zone and insert a few DNS records. ```php use Exonet\Powerdns\Powerdns; use Exonet\Powerdns\RecordType; +use Exonet\Powerdns\Resources\ResourceRecord; +use Exonet\Powerdns\Resources\Record; // Initialize the Powerdns client. $powerdns = new Powerdns('127.0.0.1', 'powerdns_secret_string'); @@ -33,6 +35,12 @@ $zone->create([ ['type' => RecordType::A, 'content' => '127.0.0.1', 'ttl' => 60, 'name' => '@'], ['type' => RecordType::A, 'content' => '127.0.0.1', 'ttl' => 60, 'name' => 'www'], ]); + +// OR use the Object-based way +$zone->create([ + (new ResourceRecord())->setType(RecordType::A)->setRecord('127.0.0.1')->setName('@')->setTtl(60), + (new ResourceRecord())->setType(RecordType::A)->setRecord((new Record())->setContent('127.0.0.1'))->setName('@')->setTtl(60), +]); ``` See the [examples](examples) directory for more. From b0aead666ffc3d6d1633eb3454bb735967c3abdb Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 23 Oct 2023 14:25:24 +0200 Subject: [PATCH 4/7] chore(README): update with correct syntax --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5300d3f..2711514 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ $zone->create([ // OR use the Object-based way $zone->create([ - (new ResourceRecord())->setType(RecordType::A)->setRecord('127.0.0.1')->setName('@')->setTtl(60), - (new ResourceRecord())->setType(RecordType::A)->setRecord((new Record())->setContent('127.0.0.1'))->setName('@')->setTtl(60), + (new ResourceRecord())->setZone($zone)->setType(RecordType::A)->setRecord('127.0.0.1')->setName('@')->setTtl(60), + (new ResourceRecord())->setZone($zone)->setType(RecordType::A)->setRecord((new Record())->setContent('127.0.0.1'))->setName('@')->setTtl(60), ]); ``` From 60312bda9d107c1793e8ee8eed36e6742ca0a183 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 27 Oct 2023 10:04:52 +0200 Subject: [PATCH 5/7] feat: remove the need to set the zone explicitly --- src/Zone.php | 12 +++++++----- tests/ZoneTest.php | 5 ----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Zone.php b/src/Zone.php index 4c2c12c..ac9817e 100644 --- a/src/Zone.php +++ b/src/Zone.php @@ -20,11 +20,11 @@ class Zone extends AbstractZone { * record is created. * * @param mixed[]|ResourceRecord|ResourceRecord[]|string $name The resource record name. - * @param string $type The type of the resource record. - * @param mixed[]|string $content The content of the resource record. When passing a multidimensional array, - * multiple records are created for this resource record. - * @param int $ttl The TTL. - * @param array|mixed[] $comments The comment to assign to the record. + * @param string $type The type of the resource record. + * @param mixed[]|string $content The content of the resource record. When passing a multidimensional array, + * multiple records are created for this resource record. + * @param int $ttl The TTL. + * @param array|mixed[] $comments The comment to assign to the record. * * @throws Exceptions\InvalidRecordType If the given type is invalid. * @@ -35,6 +35,7 @@ public function create($name, string $type = '', $content = '', int $ttl = 3600, $resourceRecords = []; foreach ($name as $item) { if ($item instanceof ResourceRecord) { + $item->setZone($this)->setName($item->getName()); $resourceRecords[] = $item; } else { $resourceRecords[] = $this->make($item['name'], $item['type'], $item['content'], $item['ttl'] ?? $ttl, $item['comments'] ?? []); @@ -42,6 +43,7 @@ public function create($name, string $type = '', $content = '', int $ttl = 3600, } } else { if ($name instanceof ResourceRecord) { + $name->setZone($this)->setName($name->getName()); $resourceRecords = [$name]; } else { $resourceRecords = [$this->make($name, $type, $content, $ttl, $comments)]; diff --git a/tests/ZoneTest.php b/tests/ZoneTest.php index e454568..1956791 100644 --- a/tests/ZoneTest.php +++ b/tests/ZoneTest.php @@ -176,20 +176,17 @@ public function testCreateMultipleResourceRecordsFromClass(): void $zone = new Zone($connector, 'test.nl'); $zone->create([ (new ResourceRecord()) - ->setZone($zone) ->setName('test') ->setType(RecordType::A) ->setRecord((new Record()) ->setContent('127.0.0.1')) ->setTtl(10), (new ResourceRecord()) - ->setZone($zone) ->setName('@') ->setType(RecordType::A) ->setRecord((new Record())->setContent('127.0.0.1')) ->setTtl(20), (new ResourceRecord()) - ->setZone($zone) ->setName('@') ->setType(RecordType::MX) ->setRecords([ @@ -198,14 +195,12 @@ public function testCreateMultipleResourceRecordsFromClass(): void ]) ->setTtl(30), (new ResourceRecord()) - ->setZone($zone) ->setName('test02') ->setType(RecordType::A) ->setRecord((new Record())->setContent('127.0.0.1')) ->setTtl(40), (new ResourceRecord()) - ->setZone($zone) ->setName('test03') ->setType(RecordType::TXT)->setRecord((new Record())->setContent('"v=DMARC1; p=none; rua=mailto:info@test.nl; ruf=mailto:info@test.nl"')) ->setTtl(40), From 59601808066dc2170ec7f8ab0283c3d489232723 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 27 Oct 2023 10:05:12 +0200 Subject: [PATCH 6/7] chore: update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2711514..5300d3f 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ $zone->create([ // OR use the Object-based way $zone->create([ - (new ResourceRecord())->setZone($zone)->setType(RecordType::A)->setRecord('127.0.0.1')->setName('@')->setTtl(60), - (new ResourceRecord())->setZone($zone)->setType(RecordType::A)->setRecord((new Record())->setContent('127.0.0.1'))->setName('@')->setTtl(60), + (new ResourceRecord())->setType(RecordType::A)->setRecord('127.0.0.1')->setName('@')->setTtl(60), + (new ResourceRecord())->setType(RecordType::A)->setRecord((new Record())->setContent('127.0.0.1'))->setName('@')->setTtl(60), ]); ``` From 8ca41c94a03def8d10b93bb5c8dfb79e86049a69 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Fri, 27 Oct 2023 10:24:59 +0200 Subject: [PATCH 7/7] chore: update formatting --- src/Zone.php | 63 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/src/Zone.php b/src/Zone.php index ac9817e..0ee0d15 100644 --- a/src/Zone.php +++ b/src/Zone.php @@ -13,7 +13,8 @@ use Exonet\Powerdns\Transformers\SoaEditTransformer; use Exonet\Powerdns\Transformers\Transformer; -class Zone extends AbstractZone { +class Zone extends AbstractZone +{ /** * Create one or more new resource records in the current zone. If $name is passed as multidimensional array those * resource records will be created in a single call to the PowerDNS server. If $name is a string, a single resource @@ -30,7 +31,8 @@ class Zone extends AbstractZone { * * @return bool True when created. */ - public function create($name, string $type = '', $content = '', int $ttl = 3600, array $comments = []): bool { + public function create($name, string $type = '', $content = '', int $ttl = 3600, array $comments = []): bool + { if (is_array($name)) { $resourceRecords = []; foreach ($name as $item) { @@ -60,7 +62,8 @@ public function create($name, string $type = '', $content = '', int $ttl = 3600, * * @return bool True when successful. */ - public function patch(array $resourceRecords): bool { + public function patch(array $resourceRecords): bool + { $result = $this->connector->patch($this->getZonePath(), new RRSetTransformer($resourceRecords)); // Invalidate the resource. $this->zoneResource = null; @@ -79,7 +82,8 @@ public function patch(array $resourceRecords): bool { * * @return bool True when successful. */ - public function put(Transformer $transformer): bool { + public function put(Transformer $transformer): bool + { $result = $this->connector->put($this->getZonePath(), $transformer); // Invalidate the resource. $this->zoneResource = null; @@ -99,7 +103,8 @@ public function put(Transformer $transformer): bool { * * @return ResourceSet A ResourceSet containing all the resource records. */ - public function get(?string $recordType = null): ResourceSet { + public function get(?string $recordType = null): ResourceSet + { $resourceSet = new ResourceSet($this); foreach ($this->resource()->getResourceRecords() as $rrset) { @@ -120,16 +125,17 @@ public function get(?string $recordType = null): ResourceSet { * * @return ResourceSet A ResourceSet containing all the resource records. */ - public function find(string $resourceRecordName, ?string $recordType = null): ResourceSet { + public function find(string $resourceRecordName, ?string $recordType = null): ResourceSet + { $resourceRecordName = $resourceRecordName === '@' ? $this->zone : $resourceRecordName; - $records = $this->get($recordType); + $records = $this->get($recordType); $foundResources = new ResourceSet($this); foreach ($records as $record) { if ( $record->getName() === $resourceRecordName - || $record->getName() === $resourceRecordName . '.' + || $record->getName() === $resourceRecordName.'.' || $record->getName() === sprintf('%s.%s', $resourceRecordName, $this->zone) ) { $foundResources->addResource($record); @@ -152,7 +158,8 @@ public function find(string $resourceRecordName, ?string $recordType = null): Re * * @return ResourceRecord The constructed ResourceRecord. */ - public function make(string $name, string $type, $content, int $ttl, array $comments): ResourceRecord { + public function make(string $name, string $type, $content, int $ttl, array $comments): ResourceRecord + { return Helper::createResourceRecord($this->zone, compact('name', 'type', 'content', 'ttl', 'comments')); } @@ -161,7 +168,8 @@ public function make(string $name, string $type, $content, int $ttl, array $comm * * @return string The zone in AXFR format. */ - public function export(): string { + public function export(): string + { $result = $this->connector->get($this->getZonePath('/export')); return $result['zone']; @@ -179,8 +187,9 @@ public function export(): string { * * @return bool True when updated. */ - public function setNsec3param(?string $nsec3param): bool { - $zone = $this->resource()->setNsec3param($nsec3param); + public function setNsec3param(?string $nsec3param): bool + { + $zone = $this->resource()->setNsec3param($nsec3param); $transformer = new Nsec3paramTransformer($zone); return $this->put($transformer); @@ -193,7 +202,8 @@ public function setNsec3param(?string $nsec3param): bool { * * @return bool True when updated. */ - public function unsetNsec3param(): bool { + public function unsetNsec3param(): bool + { return $this->setNsec3param(null); } @@ -202,7 +212,8 @@ public function unsetNsec3param(): bool { * * @return bool True when the DNS notify was successfully sent */ - public function notify(): bool { + public function notify(): bool + { $result = $this->connector->put($this->getZonePath('/notify')); /* @@ -217,7 +228,8 @@ public function notify(): bool { * * @return bool True when enabled. */ - public function enableDnssec(): bool { + public function enableDnssec(): bool + { return $this->setDnssec(true); } @@ -226,7 +238,8 @@ public function enableDnssec(): bool { * * @return bool True when disabled. */ - public function disableDnssec(): bool { + public function disableDnssec(): bool + { return $this->setDnssec(false); } @@ -237,7 +250,8 @@ public function disableDnssec(): bool { * * @return bool True when the request succeeded. */ - public function setDnssec(bool $state): bool { + public function setDnssec(bool $state): bool + { return $this->put(new DnssecTransformer(['dnssec' => $state])); } @@ -246,7 +260,8 @@ public function setDnssec(bool $state): bool { * * @return Cryptokey The DNSSEC instance. */ - public function dnssec(): Cryptokey { + public function dnssec(): Cryptokey + { return new Cryptokey($this->connector, $this->zone); } @@ -255,7 +270,8 @@ public function dnssec(): Cryptokey { * * @return Meta The meta data. */ - public function meta(): Meta { + public function meta(): Meta + { return new Meta($this->connector, $this->zone); } @@ -266,7 +282,8 @@ public function meta(): Meta { * * @return bool True when the request succeeded. */ - public function setSoaEdit(string $value): bool { + public function setSoaEdit(string $value): bool + { return $this->put(new SoaEditTransformer(['soa_edit' => $value])); } @@ -277,7 +294,8 @@ public function setSoaEdit(string $value): bool { * * @return bool True when the request succeeded. */ - public function setSoaEditApi(string $value): bool { + public function setSoaEditApi(string $value): bool + { return $this->put(new SoaEditApiTransformer(['soa_edit_api' => $value])); } @@ -289,7 +307,8 @@ public function setSoaEditApi(string $value): bool { * * @return bool True when the request succeeded. */ - public function setKind(string $kind, array $masters = []): bool { + public function setKind(string $kind, array $masters = []): bool + { $this->resource()->setKind($kind); $this->resource()->setMasters($masters);