Skip to content

Commit 60bcca4

Browse files
committed
introduce HasArchive trait for entities
- the handling of archived-flags can be added to entities by this trait - add trait to database, page and block
1 parent 3df9d7b commit 60bcca4

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

src/Entities/Blocks/Block.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use FiveamCode\LaravelNotionApi\Entities\Entity;
66
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
7+
use FiveamCode\LaravelNotionApi\Traits\HasArchive;
78
use FiveamCode\LaravelNotionApi\Traits\HasParent;
89
use FiveamCode\LaravelNotionApi\Traits\HasTimestamps;
910
use Illuminate\Support\Arr;
@@ -13,7 +14,7 @@
1314
*/
1415
class Block extends Entity
1516
{
16-
use HasTimestamps, HasParent;
17+
use HasTimestamps, HasArchive, HasParent;
1718

1819
/**
1920
* @var string
@@ -63,6 +64,7 @@ protected function fillFromRaw(): void
6364
$this->fillRawContent();
6465
$this->fillHasChildren();
6566
$this->fillParentProperties();
67+
$this->fillArchivedProperties();
6668
$this->fillTimestampableProperties();
6769
}
6870

src/Entities/Database.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use FiveamCode\LaravelNotionApi\Entities\Properties\Property;
66
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText;
77
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8+
use FiveamCode\LaravelNotionApi\Traits\HasArchive;
89
use FiveamCode\LaravelNotionApi\Traits\HasParent;
910
use FiveamCode\LaravelNotionApi\Traits\HasTimestamps;
1011
use Illuminate\Support\Arr;
@@ -15,7 +16,7 @@
1516
*/
1617
class Database extends Entity
1718
{
18-
use HasTimestamps, HasParent;
19+
use HasTimestamps, HasArchive, HasParent;
1920

2021
/**
2122
* @var string
@@ -113,6 +114,7 @@ private function fillFromRaw()
113114
$this->fillProperties();
114115
$this->fillDatabaseUrl();
115116
$this->fillParentProperties();
117+
$this->fillArchivedProperties();
116118
$this->fillTimestampableProperties();
117119
}
118120

@@ -226,7 +228,7 @@ public function getTitle(): string
226228
/**
227229
* @return bool
228230
*/
229-
public function getIsInline(): bool
231+
public function isInline(): bool
230232
{
231233
return $this->isInline;
232234
}

src/Entities/Page.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FiveamCode\LaravelNotionApi\Entities\Properties\Title;
1818
use FiveamCode\LaravelNotionApi\Entities\Properties\Url;
1919
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
20+
use FiveamCode\LaravelNotionApi\Traits\HasArchive;
2021
use FiveamCode\LaravelNotionApi\Traits\HasParent;
2122
use FiveamCode\LaravelNotionApi\Traits\HasTimestamps;
2223
use Illuminate\Support\Arr;
@@ -27,7 +28,7 @@
2728
*/
2829
class Page extends Entity
2930
{
30-
use HasTimestamps, HasParent;
31+
use HasTimestamps, HasArchive, HasParent;
3132

3233
/**
3334
* @var string
@@ -123,6 +124,7 @@ private function fillFromRaw(): void
123124
$this->fillIcon();
124125
$this->fillCover();
125126
$this->fillParentProperties();
127+
$this->fillArchivedProperties();
126128
$this->fillTimestampableProperties();
127129
}
128130

src/Traits/HasArchive.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Traits;
4+
5+
use Illuminate\Support\Arr;
6+
7+
/**
8+
* Trait HasArchive
9+
*/
10+
trait HasArchive
11+
{
12+
/**
13+
* @var array
14+
*/
15+
protected array $responseData = [];
16+
17+
/**
18+
* @var bool
19+
*/
20+
private bool $archived = false;
21+
22+
23+
protected function fillArchivedProperties(): void
24+
{
25+
$this->fillArchived();
26+
}
27+
28+
private function fillArchived(): void
29+
{
30+
if (Arr::exists($this->responseData, 'archived')) {
31+
$this->archived = $this->responseData['archived'];
32+
}
33+
}
34+
35+
/**
36+
* @return bool
37+
*/
38+
public function isArchived(): bool
39+
{
40+
return $this->archived;
41+
}
42+
}

0 commit comments

Comments
 (0)