Skip to content

Commit

Permalink
Buxfixes and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rutgerkirkels committed Dec 8, 2018
1 parent 658a6f4 commit 9ec7309
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Vcard generator
===============
[![Latest Version](https://img.shields.io/github/release/rutgerkirkels/vcard-generator.svg?style=flat-square)](https://github.com/rutgerkirkels/vcard-generator/releases)
[![Total Downloads](https://img.shields.io/packagist/dt/rutgerkirkels/vcard-generator.svg?style=flat-square)](https://packagist.org/packages/rutgerkirkels/vcard-generator)
![License](https://img.shields.io/github/license/mashape/apistatus.svg)
![License](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)

This PHP-library enables you to generate a Vcard from external data like a database, CSV file or any other data source.

Expand Down
36 changes: 36 additions & 0 deletions examples/basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
// Don't forget to include the composer autoloader
require_once __DIR__ . '/vendor/autoload.php';

use \rutgerkirkels\vcard_generator\Generator;
use \rutgerkirkels\vcard_generator\Models\Name;
use \rutgerkirkels\vcard_generator\Models\Organization;
use \rutgerkirkels\vcard_generator\Models\Email;
use \rutgerkirkels\vcard_generator\Models\Telephone;
use \rutgerkirkels\vcard_generator\Models\Url;
use \rutgerkirkels\vcard_generator\Models\Birthday;
use \rutgerkirkels\vcard_generator\Models\Note;
use \rutgerkirkels\vcard_generator\Models\Photo;

$generator = new Generator();
$generator
// Set the first and last name
->setName(new Name('Marco', 'Woodberry'))
// Set the name of the organization and the department (optional)
->setOrganization(new Organization('ACME', 'Engineering'))
// Add a business landline (optional)
->addTelephone(new Telephone('+31206255455', 'WORK'))
// Add a cellphone (optional)
->addTelephone(new Telephone('+31693382817', 'CELL'))
// Add a business e-mail address (optional)
->addEmailAddress(new Email('[email protected]','work'))
// Add a personal e-mail address (optional)
->addEmailAddress(new Email('[email protected]','home'))
// Set the person's birth date (optional)
->setBirthday(new Birthday(new DateTime('1963-03-11')))
// Add a note (optional)
->setNote(new Note('First line of the note' . PHP_EOL . 'Second line of the note'))
// Add a business website (optional)
->addUrl(new Url('https://www.acme.com','work'))
// Store the VCF file. (default location is the current directory)
->store();
2 changes: 1 addition & 1 deletion src/Models/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function setNote($note) : Note
*/
public function toString() : string
{
return 'NOTE:' . $this->getNote();
return 'NOTE:' . str_replace(PHP_EOL, '\\n', $this->getNote());
}
}
4 changes: 2 additions & 2 deletions src/Models/Vcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getVersion(): float
/**
* @return Name
*/
public function getName(): Name
public function getName(): ?Name
{
return $this->name;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public function getUrls() : array
/**
* @return Photo
*/
public function getPhoto(): Photo
public function getPhoto(): ?Photo
{
return $this->photo;
}
Expand Down

0 comments on commit 9ec7309

Please sign in to comment.