Skip to content

Commit 9ec7309

Browse files
committed
Buxfixes and examples
1 parent 658a6f4 commit 9ec7309

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Vcard generator
22
===============
33
[![Latest Version](https://img.shields.io/github/release/rutgerkirkels/vcard-generator.svg?style=flat-square)](https://github.com/rutgerkirkels/vcard-generator/releases)
44
[![Total Downloads](https://img.shields.io/packagist/dt/rutgerkirkels/vcard-generator.svg?style=flat-square)](https://packagist.org/packages/rutgerkirkels/vcard-generator)
5-
![License](https://img.shields.io/github/license/mashape/apistatus.svg)
5+
![License](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)
66

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

examples/basic.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
// Don't forget to include the composer autoloader
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
5+
use \rutgerkirkels\vcard_generator\Generator;
6+
use \rutgerkirkels\vcard_generator\Models\Name;
7+
use \rutgerkirkels\vcard_generator\Models\Organization;
8+
use \rutgerkirkels\vcard_generator\Models\Email;
9+
use \rutgerkirkels\vcard_generator\Models\Telephone;
10+
use \rutgerkirkels\vcard_generator\Models\Url;
11+
use \rutgerkirkels\vcard_generator\Models\Birthday;
12+
use \rutgerkirkels\vcard_generator\Models\Note;
13+
use \rutgerkirkels\vcard_generator\Models\Photo;
14+
15+
$generator = new Generator();
16+
$generator
17+
// Set the first and last name
18+
->setName(new Name('Marco', 'Woodberry'))
19+
// Set the name of the organization and the department (optional)
20+
->setOrganization(new Organization('ACME', 'Engineering'))
21+
// Add a business landline (optional)
22+
->addTelephone(new Telephone('+31206255455', 'WORK'))
23+
// Add a cellphone (optional)
24+
->addTelephone(new Telephone('+31693382817', 'CELL'))
25+
// Add a business e-mail address (optional)
26+
->addEmailAddress(new Email('[email protected]','work'))
27+
// Add a personal e-mail address (optional)
28+
->addEmailAddress(new Email('[email protected]','home'))
29+
// Set the person's birth date (optional)
30+
->setBirthday(new Birthday(new DateTime('1963-03-11')))
31+
// Add a note (optional)
32+
->setNote(new Note('First line of the note' . PHP_EOL . 'Second line of the note'))
33+
// Add a business website (optional)
34+
->addUrl(new Url('https://www.acme.com','work'))
35+
// Store the VCF file. (default location is the current directory)
36+
->store();

src/Models/Note.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public function setNote($note) : Note
4848
*/
4949
public function toString() : string
5050
{
51-
return 'NOTE:' . $this->getNote();
51+
return 'NOTE:' . str_replace(PHP_EOL, '\\n', $this->getNote());
5252
}
5353
}

src/Models/Vcard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getVersion(): float
9797
/**
9898
* @return Name
9999
*/
100-
public function getName(): Name
100+
public function getName(): ?Name
101101
{
102102
return $this->name;
103103
}
@@ -270,7 +270,7 @@ public function getUrls() : array
270270
/**
271271
* @return Photo
272272
*/
273-
public function getPhoto(): Photo
273+
public function getPhoto(): ?Photo
274274
{
275275
return $this->photo;
276276
}

0 commit comments

Comments
 (0)