jaredhowland/contacts
Composer 安装命令:
composer require jaredhowland/contacts
包简介
📇 PHP library for address book contacts (make vCards for contacts)
关键字:
README 文档
README
Contacts
Contacts is a small PHP library to create files containing address book information for people or organizations. Currently, vCard 3.0 is the only supported export format.
Features
- vCard 3.0 Compatibility:
- Generates vCards that should be compatible with all applications that use vCards
- Includes fields that are unique to the iOS and macOS contacts application (
Supervisor,Anniversary,Spouse,Child)
- Flexible: future implementations will include other formats commonly used to store contact information—other vCard formats, microformats, Google contacts format,
.csvformat, etc. - Method chaining for constructing contact information in a fluid interface
- The method argument order typically comes directly from the standard itself
Installation
Contacts is available as a Composer package:
- If needed, install Composer
- Add the following to your
composer.jsonfile
"require": { "jaredhowland/contacts": "~6.0" }
Usage
Input
This is an extensive example. The code is well documented and you should get all the hints needed for using it in an IDE. Most of the time, you will only need a fraction of these fields to create a vCard:
<?php require 'vendor/autoload.php'; use \Contacts\Options; // Only needed if you must override the default settings use \Contacts\Vcard; // Set desired options $options = new Options(); $options->setDataDirectory('./'); // Tell app where to save `.vcf` file $vcard = new Vcard($options); $vcard->addFullName('Jane Doe'); $vcard->addName('Doe', 'Jane'); $vcard->addNickname('Janie, Jan'); $vcard->addPhoto('https://raw.githubusercontent.com/jaredhowland/contacts/master/tests/files/photo.jpg'); $vcard->addBirthday(10, 2, null); $vcard->addAddress(null, null, '123 Main', 'Provo', 'UT', '84602', 'United States', ['dom', 'postal', 'parcel', 'work']); $vcard->addAddress(null, null, '123 Main', 'Provo', 'UT', '84602', 'United States', ['dom', 'postal', 'parcel', 'home']); $vcard->addLabel('Jane Doe\n123 Main St\nProvo, UT 84602', ['dom', 'parcel']); $vcard->addTelephone('555-555-5555', ['cell', 'iphone']); $vcard->addEmail('jane_doe@domain.com'); $vcard->addTimeZone('-7'); $vcard->addLatLong(40.3333331, -111.7777775); $vcard->addTitle('System Administrator'); $vcard->addRole('Programmer'); // $vcard->addAgent($agent); NOT SUPPORTED $vcard->addOrganizations(['Awesome Company']); $vcard->addCategories(['School', 'Work']); $vcard->addNote('Not much is known about Jane Doe.'); $vcard->addSortString('Doe'); // $vcard->addSound($sound); NOT SUPPORTED $vcard->addUrl('https://www.example.com'); // $vcard->addKey($key); NOT SUPPORTED $vcard->addAnniversary('2010-10-10'); $vcard->addSupervisor('Jane Smith'); $vcard->addSpouse('John Doe'); $vcard->addChild('Jeff Doe'); $vcard->addChild('Lisa Doe'); $vcard->addExtendedType('TWITTER', '@jared_howland'); $vcard->addUniqueIdentifier(); $vcard->addRevision('2023-09-05'); // Added automatically if you don't call this method $directory->buildVcard(true, 'example'); ?>
Or you can chain methods together to build the vCard:
<?php require '../vendor/autoload.php'; use \Contacts\Options; use \Contacts\Vcard; // Set desired options $options = new Options(); $options->setDataDirectory('./'); // Tell app where to save `.vcf` file $vcard = new Vcard($options); $vcard->addFullName('Jane Doe') ->addName('Doe', 'Jane') ->addNickname('Janie, Jan') ->addPhoto('https://raw.githubusercontent.com/jaredhowland/contacts/master/tests/files/photo.jpg') ->addBirthday(10, 2, null) ->addAddress(null, null, '123 Main', 'Provo', 'UT', '84602', 'United States', ['dom', 'postal', 'parcel', 'work']) ->addAddress(null, null, '123 Main', 'Provo', 'UT', '84602', 'United States', ['dom', 'postal', 'parcel', 'home']) ->addLabel('Jane Doe\n123 Main St\nProvo, UT 84602', ['dom', 'parcel']) ->addTelephone('555-555-5555', ['cell', 'iphone']) ->addEmail('jane_doe@domain.com') ->addTimeZone('-7') ->addLatLong(40.3333331, -111.7777775) ->addTitle('System Administrator') ->addRole('Programmer') ->addOrganizations(['Awesome Company']) ->addCategories(['School', 'Work']) ->addNote('Not much is known about Jane Doe.') ->addSortString('Doe') ->addUrl('http://www.example.com') ->addAnniversary('2010-10-10') ->addSupervisor('Jane Smith') ->addSpouse('John Doe') ->addChild('Jeff Doe') ->addChild('Lisa Doe') ->addExtendedType('TWITTER', '@jared_howland') ->addUniqueIdentifier() ->addRevision('2023-09-05') /* Added automatically with the current date and time if you don't call this method */ ->buildVcard(true, 'example'); // $vcard->addAgent($agent); NOT SUPPORTED // $vcard->addSound($sound); NOT SUPPORTED // $vcard->addKey($key); NOT SUPPORTED ?>
Output
BEGIN:VCARD VERSION:3.0 FN:Jane Doe N:Doe;Jane;;; NICKNAME:Janie,Jan PHOTO;ENCODING=b;TYPE=JPEG:/9j/4QBwRXhpZgAASUkqAAgAAAABAJiCAgBLAAAAGgAAAA AAAABDb3B5cmlnaHQgQllVIFB …rest of binary-encoded photo BDAY;X-APPLE-OMIT-YEAR=1604:1604-02-10 ADR;TYPE=dom,postal,parcel,work:;;123 Main;Provo;UT;84602;United States ADR;TYPE=dom,postal,parcel,home:;;123 Main;Provo;UT;84602;United States LABEL;TYPE=dom,parcel:Jane Doe\n123 Main St\nProvo\, UT 84602 TEL;TYPE=cell,iphone:(555) 555-5555 EMAIL;TYPE=internet:jane_doe@domain.com TZ:-07:00 GEO:40.333333;-111.777778 TITLE:System Administrator ROLE:Programmer ORG:Awesome Company CATEGORIES:School,Work NOTE:Not much is known about Jane Doe. SORT-STRING:Doe URL:https://www.example.com item1.X-ABDATE;type=pref:2010-10-10 item1.X-ABLabel:_$!<Anniversary>!$_ item2.X-ABRELATEDNAMES:Jane Smith item2.X-ABLabel:_$!<Manager>!$_ item3.X-ABRELATEDNAMES:John Doe item3.X-ABLabel:_$!<Spouse>!$_ item4.X-ABRELATEDNAMES:Jeff Doe item4.X-ABLabel:_$!<Child>!$_ item5.X-ABRELATEDNAMES:Lisa Doe item5.X-ABLabel:_$!<Child>!$_ X-TWITTER:@jared_howland UID:5a32a74023b097.12918287 REV:2023-09-05T00:00:00Z END:VCARD
Options
Available options and defaults in the Options class:
setDataDirectory:./data/setDefaultAreaCode:nullsetFormatUsTelephone:true
With appropriate getters:
getDataDirectory()getDefaultAreaCode()isFormatUsTelephone()
Contribute
- Issue Tracker: https://github.com/jaredhowland/contacts/issues
- Source Code: https://github.com/jaredhowland/contacts
- Code of conduct: https://github.com/jaredhowland/contacts/blob/master/CODE_OF_CONDUCT.md
Known Issues
- Date-time values not supported for
BDAYfield (only date values). No plans to implement. - Text values not supported for
TZfield (only UTC-offset values). No plans to implement. - The following vCard elements are not currently supported (no plans to implement):
AGENTSOUNDKEY
Inspired by https://github.com/jeroendesloovere/vcard
jaredhowland/contacts 适用场景与选型建议
jaredhowland/contacts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.95k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「contacts」 「vCard」 「address book」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jaredhowland/contacts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jaredhowland/contacts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jaredhowland/contacts 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
A clean, modern, and easy-to-use QR code generator for Laravel
Module adding custom shipping attribute for what3words address
This VCard PHP class can generate a vCard with some data. When using an iOS device it will export as a .ics file because iOS devices don't support the default .vcf files.
contacts
统计信息
- 总下载量: 3.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-19