-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.editorconfig export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.styleci.yml export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore | ||
/.github export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
/composer.lock | ||
/phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
preset: laravel | ||
|
||
risky: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# laravel-vcard | ||
# Laravel vCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "astrotomic/laravel-vcard", | ||
"type": "library", | ||
"description": "", | ||
"keywords": [], | ||
"homepage": "https://github.com/Astrotomic/laravel-vcard", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Tom Witkowski", | ||
"email": "[email protected]", | ||
"homepage": "https://gummibeer.de", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"illuminate/contracts": "^7.0 || ^8.0", | ||
"illuminate/http": "^7.0 || ^8.0", | ||
"illuminate/support": "^7.0 || ^8.0", | ||
"illuminate/database": "^7.0 || ^8.0" | ||
}, | ||
"require-dev": { | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Astrotomic\\CachableAttributes\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Astrotomic\\CachableAttributes\\Tests\\": "tests/" | ||
} | ||
}, | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Utils; | ||
|
||
use Illuminate\Contracts\Support\Responsable; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Str; | ||
use Stringable; | ||
use Symfony\Component\HttpFoundation\HeaderUtils; | ||
|
||
class Vcard implements Stringable, Responsable | ||
{ | ||
protected string $name; | ||
protected ?string $email = null; | ||
protected ?string $phone = null; | ||
|
||
public static function make(string $name): self | ||
{ | ||
return new static($name); | ||
} | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function email(?string $email): self | ||
{ | ||
$this->email = $email; | ||
|
||
return $this; | ||
} | ||
|
||
public function phone(?string $phone): self | ||
{ | ||
$this->phone = $phone; | ||
|
||
return $this; | ||
} | ||
|
||
public function toResponse($request) | ||
{ | ||
$content = strval($this); | ||
|
||
$filename = Str::of($this->name)->slug('_')->append('.vcf'); | ||
|
||
return new Response($content, 200, [ | ||
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', | ||
'Content-Type' => 'text/vcard', | ||
'Content-Length' => Str::length($content), | ||
'Content-Disposition' => HeaderUtils::makeDisposition( | ||
HeaderUtils::DISPOSITION_ATTACHMENT, | ||
$filename, | ||
$filename->ascii()->replace('%', '') | ||
), | ||
]); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return collect([ | ||
'BEGIN:VCARD', | ||
'VERSION:4.0', | ||
sprintf('FN:%s', $this->name), | ||
$this->email ? sprintf('EMAIL:%s', $this->email) : null, | ||
$this->phone ? sprintf('TEL;TYPE=VOICE:%s', $this->phone) : null, | ||
'END:VCARD', | ||
])->filter()->implode(PHP_EOL); | ||
} | ||
} |