Skip to content

Commit

Permalink
core(project): started
Browse files Browse the repository at this point in the history
  • Loading branch information
Guikingone committed Jun 23, 2020
0 parents commit 8f81911
Show file tree
Hide file tree
Showing 25 changed files with 6,104 additions and 0 deletions.
Empty file added .dockerignore
Empty file.
Empty file added .github/CONTRIBUTING.md
Empty file.
15 changes: 15 additions & 0 deletions .github/workflows/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: SymfonyUidDoctrine - Configuration
on: [ push, pull_request ]
jobs:
project:
name: Configuration
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2

# https://github.com/azohra/shell-linter (community)
- name: Lint check
uses: azohra/[email protected]
with:
path: "docker/php/scripts"
64 changes: 64 additions & 0 deletions .github/workflows/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: SymfonyUidDoctrine
on: [ push, pull_request ]
jobs:
core:
name: PHP ${{ matrix.php-versions }} - ${{ matrix.composer-dependencies }}
# https://hub.docker.com/_/ubuntu/
runs-on: ubuntu-18.04
strategy:
fail-fast: true
matrix:
php-versions: ['7.2', '7.3', '7.4']
composer-dependencies: ['', 'lowest']
steps:
# https://github.com/actions/checkout (official)
- name: Checkout
uses: actions/checkout@v2

# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, extensions and composer with shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: zip, xdebug
coverage: xdebug
env:
update: true

# —— Composer️ —————————————————————————————————————————————————————————
- name: Validate composer.json and composer.lock
run: composer validate

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.composer-dependencies }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.composer-dependencies }}-

- name: Install Composer dependencies
if: matrix.composer-dependencies == ''
run: composer update --no-suggest

- name: Install Composer dependencies - Lowest
if: matrix.composer-dependencies == 'lowest'
run: composer update --no-suggest --prefer-lowest

# —— Style —————————————————————————————————————————————————————————
- name: Launch PHP-CS-FIXER - tests
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --dry-run .

# —— PHPUnit —————————————————————————————————————————————————————————
- name: Launch PHPUnit tests
run: php vendor/bin/phpunit

# —— Infection —————————————————————————————————————————————————————————
- name: Launch Infection analysis
run: php vendor/bin/infection
continue-on-error: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# PHP-CS-FIXER
.php_cs.cache

# PHPUnit
.phpunit.result.cache

# Infection
infection.log
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

- Initial release
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
DOCKER = @docker
DOCKER_COMPOSE = @docker-compose
PHP = $(DOCKER_COMPOSE) run --rm php

.DEFAULT_GOAL := help

help:
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'

##
## Project
##---------------------------------------------------------------------------

.PHONY: boot up down vendor

boot: ## Launch the project
boot: up vendor

up: ## Up the containers
up:
$(DOCKER_COMPOSE) up -d --remove-orphans

down: ## Down the containers
down:
$(DOCKER_COMPOSE) down

vendor: ## Install the dependencies
vendor:
$(PHP) composer install

##
## Tools
##---------------------------------------------------------------------------

.PHONY: php-cs-fixer phpstan

php-cs-fixer: ## Run PHP-CS-FIXER against a specific DIRECTORY (or . by default)
php-cs-fixer:
$(PHP) vendor/bin/php-cs-fixer fix $(or $(DIRECTORY), .)

phpstan: ## Run PHPStan against a specific DIRECTORY (a specific LEVEL can be define)
phpstan:
$(PHP) vendor/bin/phpstan analyse -c phpstan.neon --level $(or $(LEVEL), 8)

##
## Tests
##---------------------------------------------------------------------------

.PHONY: tests infection

tests: ## Launch the PHPUnit tests
tests:
$(PHP) vendor/bin/phpunit tests

infection: ## Launch Infection
infection:
$(PHP) vendor/bin/infection
172 changes: 172 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# guikingone/symfony-uid-doctrine

![SymfonyUidDoctrine](https://github.com/Guikingone/SymfonyUidDoctrine/workflows/SymfonyUidDoctrine/badge.svg?branch=master)
![SymfonyUidDoctrine - Configuration](https://github.com/Guikingone/SymfonyUidDoctrine/workflows/SymfonyUidDoctrine%20-%20Configuration/badge.svg?branch=master)

The `guikingone/symfony-uid-doctrine` aim to provide the support of `Symfony/Uid` as a `Doctrine` type.

## Installation

Consider using `Packagist` and `Composer` when installing the following project:

```bash
composer require guikingone/symfony-uid-doctrine
```

## Configuration

### Uuid

```php
Doctrine\DBAL\Types\Type::addType('uuid', Guikingone\SymfonyUid\Doctrine\Uuid\UuidType::class);
```

```yaml
# config/packages/doctrine.yaml
doctrine:
dbal:
types:
uuid: Guikingone\SymfonyUid\Doctrine\Uuid\UuidType
```
### Ulid
```php
Doctrine\DBAL\Types\Type::addType('ulid', Guikingone\SymfonyUid\Doctrine\Ulid\UlidType::class);
```

```yaml
# config/packages/doctrine.yaml
doctrine:
dbal:
types:
ulid: Guikingone\SymfonyUid\Doctrine\Ulid\UlidType
```
## Usage
### Uuid
```php
use Doctrine\ORM\Mapping as ORM;
use Guikingone\SymfonyUid\Doctrine\Uuid\UuidGenerator;

/**
* @ORM\Entity
* @ORM\Table(name="posts")
*/
class Post
{
/**
* @var Symfony\Component\Uid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
protected $id;

public function getId(): Uuid
{
return $this->id;
}
}
```

If you don't want to use the generator, consider using the `__construct()` method:

```php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

/**
* @ORM\Entity
* @ORM\Table(name="posts")
*/
class Post
{
/**
* @var Symfony\Component\Uid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
*/
protected $id;

public function __construct()
{
$this->id = Uuid::v4();
}

public function getId(): Uuid
{
return $this->id;
}
}
```

### Ulid

```php
use Doctrine\ORM\Mapping as ORM;
use Guikingone\SymfonyUid\Doctrine\Ulid\UlidGenerator;

/**
* @ORM\Entity
* @ORM\Table(name="posts")
*/
class Post
{
/**
* @var Symfony\Component\Uid\Ulid
*
* @ORM\Id
* @ORM\Column(type="ulid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UlidGenerator::class)
*/
protected $id;

public function getId(): Ulid
{
return $this->id;
}
}
```

If you don't want to use the generator, consider using the `__construct()` method:

```php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;

/**
* @ORM\Entity
* @ORM\Table(name="posts")
*/
class Post
{
/**
* @var Symfony\Component\Uid\Ulid
*
* @ORM\Id
* @ORM\Column(type="ulid", unique=true)
*/
protected $id;

public function __construct()
{
$this->id = new Ulid();
}

public function getId(): Ulid
{
return $this->id;
}
}
```

## Contributing

Contributions are welcome! Please read [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "guikingone/symfony-uid-doctrine",
"description": "Allow the use of symfony/uid as Doctrine field type",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Guillaume Loulier",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Guikingone\\SymfonyUid\\Doctrine\\": "src/",
"Guikingone\\SymfonyUid\\Doctrine\\Uuid\\": "src/Uuid/",
"Guikingone\\SymfonyUid\\Doctrine\\Ulid\\": "src/Ulid/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Guikingone\\SymfonyUid\\Doctrine\\": "tests/",
"Tests\\Guikingone\\SymfonyUid\\Doctrine\\Uuid\\": "tests/Uuid/",
"Tests\\Guikingone\\SymfonyUid\\Doctrine\\Ulid\\": "tests/Ulid/"
}
},
"require": {
"php": ">=7.2",
"doctrine/orm": "^2.5",
"symfony/uid": "^5.1.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "^0.12.30",
"infection/infection": "^0.15.3",
"friendsofphp/php-cs-fixer": "^2.16"
}
}
Loading

0 comments on commit 8f81911

Please sign in to comment.