Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Allow to set filename for template (FIXED) #21

Merged
merged 6 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static function dateTime(\DateTimeImmutable $dateTime, string $format = '
return new Component\DateTime($dateTime, $format);
}

public static function document(string $link): Component\Document
public static function document(string $link, string $filename = null): Component\Document
{
return new Component\Document($link);
return new Component\Document($link, $filename);
}

public static function image(string $link): Component\Image
Expand Down
9 changes: 8 additions & 1 deletion src/Component/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ class Document extends Component
*/
protected string $link;

public function __construct(string $link)
/**
* File name to be used for file
*/
protected string $filename;

public function __construct(string $link, ?string $filename = null)
{
if (filter_var($link, FILTER_VALIDATE_URL) === false) {
throw new UnsupportedMediaValue($link, 'document', 'Link is not a valid URL');
Expand All @@ -27,6 +32,7 @@ public function __construct(string $link)
}

$this->link = $link;
$this->filename = empty($filename) ? 'document' : $filename;
}

public function toArray(): array
Expand All @@ -35,6 +41,7 @@ public function toArray(): array
'type' => 'document',
'document' => [
'link' => $this->link,
'filename' => $this->filename
],
];
}
Expand Down
1 change: 1 addition & 0 deletions tests/Component/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function the_document_link_is_a_supported_document()
'type' => 'document',
'document' => [
'link' => 'https://www.netflie.es/document.pdf',
'filename' => 'document',
],
];

Expand Down
2 changes: 1 addition & 1 deletion tests/WhatsAppTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function the_notification_component_header_can_be_set()
],
[
'type' => 'document',
'document' => ['link' => 'https://netflie.es/document.pdf'],
'document' => ['link' => 'https://netflie.es/document.pdf', 'filename' => 'document'],
],
[
'type' => 'video',
Expand Down
Loading