Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Feb 24, 2021
1 parent 4cb6125 commit 9808503
Show file tree
Hide file tree
Showing 24 changed files with 728 additions and 25 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/composer-normalize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: normalize composer.json

on:
push:
paths:
- 'composer.json'

jobs:
normalize:
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v2

- name: Validate Composer configuration
run: composer validate --strict

- name: Normalize composer.json
run: |
composer global require ergebnis/composer-normalize
composer normalize --indent-style=space --indent-size=4 --no-check-lock --no-update-lock --no-interaction --ansi
- uses: stefanzweifel/[email protected]
with:
commit_message: normalize composer.json
19 changes: 19 additions & 0 deletions .github/workflows/markdown-normalize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: normalize markdown

on:
push:
paths:
- '*.md'

jobs:
normalize:
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v2

- name: Prettify markdown
uses: creyD/[email protected]
with:
prettier_options: --write **/*.md
52 changes: 52 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: run-tests

on:
push:
schedule:
- cron: '0 0 * * *'

jobs:
test:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [8.0]
laravel: [8.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
keys: |
dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-
dependencies-laravel-${{ matrix.laravel }}-php-
dependencies-laravel-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
57 changes: 57 additions & 0 deletions .github/workflows/stale-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Close stale issues"
on:
schedule:
- cron: "0 0 * * *"

jobs:
default:
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days'
stale-issue-label: 'stale'
exempt-issue-labels: 'bug,enhancement,documentation,help wanted,next release,next major release'
days-before-stale: 21
days-before-close: 7

invalid:
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been labeled as invalid.'
stale-issue-label: 'stale'
only-labels: 'invalid'
days-before-stale: 1
days-before-close: 2

duplicate:
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been labeled as duplicate.'
stale-issue-label: 'stale'
only-labels: 'duplicate'
days-before-stale: 1
days-before-close: 2

wontfix:
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been labeled as wontfix.'
stale-issue-label: 'stale'
only-labels: 'wontfix'
days-before-stale: 1
days-before-close: 2
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# Laravel vCard

## Usage

```php
Vcard::make()
->fullName('John Adam Smith')
->name('Smith', 'John', 'Adam')
->email('[email protected]')
->email('[email protected]', [Email::WORK, Email::INTERNET])
->tel('+1234567890', [Tel::HOME, Tel::VOICE])
->tel('+0987654321', [Tel::WORK, Tel::VOICE])
->tel('+0123456789', [Tel::CELL, Tel::VOICE])
->url('https://johnsmith.com')
->url('https://company.com')
->bday(Carbon::parse('1990-06-24'));
```

```vcard
BEGIN:VCARD
VERSION:4.0
FN;CHARSET=UTF-8:John Adam Smith
N;CHARSET=UTF-8:Smith;John;Adam;;
EMAIL;TYPE=INTERNET:[email protected]
EMAIL;TYPE=WORK;TYPE=INTERNET:[email protected]
TEL;TYPE=HOME;TYPE=VOICE:+1234567890
TEL;TYPE=WORK;TYPE=VOICE:+0987654321
TEL;TYPE=CELL;TYPE=VOICE:+0123456789
URL:https://johnsmith.com
URL:https://company.com
BDAY:1990-06-24
REV:2021-02-25T10:30:45.000000Z
END:VCARD
```
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
],
"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"
"illuminate/contracts": "^8.0",
"illuminate/http": "^8.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3",
"spatie/phpunit-snapshot-assertions": "^4.2"
},
"config": {
"sort-packages": true
Expand Down
27 changes: 27 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php" backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing" force="true"/>
</php>
</phpunit>
20 changes: 20 additions & 0 deletions src/Properties/Bday.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Astrotomic\Vcard\Properties;

use DateTimeInterface;

class Bday extends Property
{
protected DateTimeInterface $bday;

public function __construct(DateTimeInterface $bday)
{
$this->bday = $bday;
}

public function __toString(): string
{
return "BDAY:{$this->bday->format('Y-m-d')}";
}
}
30 changes: 30 additions & 0 deletions src/Properties/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Astrotomic\Vcard\Properties;

class Email extends Property
{
public const INTERNET = 'INTERNET';
public const WORK = 'WORK';

protected string $email;

/** @var string[] */
protected array $types;

public function __construct(string $email, array $types)
{
$this->email = $email;
$this->types = $types;
}

public function __toString(): string
{
$types = implode(';', array_map(
fn(string $type): string => "TYPE={$type}",
$this->types
));

return "EMAIL;{$types}:{$this->email}";
}
}
21 changes: 21 additions & 0 deletions src/Properties/Gender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Astrotomic\Vcard\Properties;

class Gender extends Property
{
public const FEMALE = 'F';
public const MALE = 'M';

protected string $gender;

public function __construct(string $gender)
{
$this->gender = $gender;
}

public function __toString(): string
{
return "GENDER:{$this->gender}";
}
}
22 changes: 22 additions & 0 deletions src/Properties/Kind.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Astrotomic\Vcard\Properties;

class Kind extends Property
{
public const INDIVIDUAL = 'individual';
public const ORGANIZATION = 'organization';
public const GROUP = 'group';

protected string $kind;

public function __construct(string $kind)
{
$this->kind = $kind;
}

public function __toString(): string
{
return "KIND:{$this->kind}";
}
}
25 changes: 25 additions & 0 deletions src/Properties/Photo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Astrotomic\Vcard\Properties;

use Illuminate\Support\Str;
use InvalidArgumentException;

class Photo extends Property
{
protected string $photo;

public function __construct(string $photo)
{
if(!Str::startsWith($photo, 'data:image/jpeg;base64,')) {
throw new InvalidArgumentException('Photo property has to be a jpeg base64 data-uri.');
}

$this->photo = $photo;
}

public function __toString(): string
{
return "PHOTO:{$this->photo}";
}
}
8 changes: 8 additions & 0 deletions src/Properties/Property.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Astrotomic\Vcard\Properties;

abstract class Property
{
abstract public function __toString(): string;
}
Loading

0 comments on commit 9808503

Please sign in to comment.