bright / vcard
Generate vCard files for quick contact import.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bright/vcard
Requires
- php: ^8.1
Requires (Dev)
- pestphp/pest: 4.x-dev
README
A lightweight PHP package for generating .vcf (vCard) files — compatible with most contact applications.
Includes convenient helpers for building vCards from models or plain data arrays.
⚙️ Requirements
- PHP 8.1+
Installation
Install via Composer:
composer require bright/vcard
Quick Usage
Create a simple vCard
use Bright\VCard\VCard; $vcard = VCard::make() ->addName('Doe', 'John') ->addEmail('john@example.com', 'WORK') ->addPhoneNumber('+1 555-1234', 'WORK') ->addCompany('Bright') ->addJobtitle('Developer') ->addAddress('', '', '123 Main St', 'New York', '', '10001', 'United States') ->addURL('https://linkedin.com/in/johndoe', 'LinkedIn') ->addNote('Software Developer at Bright') ->addFilename('John Doe'); $file = $vcard->getFilename() . '.vcf'; $vcard->save(); // Saves to disk
Build from a model (object or DTO)
$info = (object) [ 'name' => 'Jane Doe', 'first_name' => 'Jane', 'last_name' => 'Doe', 'email' => 'jane@example.com', 'phone' => '555-6789', 'job_title' => 'Designer', 'big_group' => 'Creative', 'city' => 'Berlin', 'company' => 'Bright', 'linkedin' => 'https://linkedin.com/in/janedoe', 'expertise' => 'UX/UI', 'interests' => 'Art, Photography', 'picture' => null, ]; $vcard = VCard::model($info); $vcard->save();
File Output
By default, .vcf files are saved in the current working directory.
You can change the save directory:
$vcard->setSavePath(__DIR__ . '/exports/'); $vcard->save();
Output response
use Bright\VCard\VCard; $vcard = VCard::make() ->addName('Doe', 'John') ->addEmail('john@example.com', 'WORK') ->addPhoneNumber('+1 555-1234', 'WORK') ->addCompany('Bright') ->addFilename('John Doe'); // Build the VCard $output = $vcard->buildVCard(); // Set appropriate headers $headers = $vcard->getHeaders(true); // Output headers manually (instead of Laravel's response helper) foreach ($headers as $key => $value) { header("$key: $value"); } // Send the VCard data as the response http_response_code(200); echo $output; exit;
Testing
To run the test suite (powered by Pest):
composer install ./vendor/bin/pest
📝 License
MIT License © Bright