Skip to content

Commit 8f81911

Browse files
committed
core(project): started
0 parents  commit 8f81911

25 files changed

+6104
-0
lines changed

.dockerignore

Whitespace-only changes.

.github/CONTRIBUTING.md

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: SymfonyUidDoctrine - Configuration
2+
on: [ push, pull_request ]
3+
jobs:
4+
project:
5+
name: Configuration
6+
runs-on: ubuntu-18.04
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v2
10+
11+
# https://github.com/azohra/shell-linter (community)
12+
- name: Lint check
13+
uses: azohra/[email protected]
14+
with:
15+
path: "docker/php/scripts"

.github/workflows/project.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: SymfonyUidDoctrine
2+
on: [ push, pull_request ]
3+
jobs:
4+
core:
5+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.composer-dependencies }}
6+
# https://hub.docker.com/_/ubuntu/
7+
runs-on: ubuntu-18.04
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
php-versions: ['7.2', '7.3', '7.4']
12+
composer-dependencies: ['', 'lowest']
13+
steps:
14+
# https://github.com/actions/checkout (official)
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
# https://github.com/shivammathur/setup-php (community)
19+
- name: Setup PHP, extensions and composer with shivammathur/setup-php
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-versions }}
23+
extensions: zip, xdebug
24+
coverage: xdebug
25+
env:
26+
update: true
27+
28+
# —— Composer️ —————————————————————————————————————————————————————————
29+
- name: Validate composer.json and composer.lock
30+
run: composer validate
31+
32+
- name: Get composer cache directory
33+
id: composer-cache
34+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
35+
36+
- name: Cache composer dependencies
37+
uses: actions/cache@v1
38+
with:
39+
path: ${{ steps.composer-cache.outputs.dir }}
40+
key: ${{ runner.os }}-composer-${{ matrix.composer-dependencies }}-${{ hashFiles('**/composer.lock') }}
41+
restore-keys: ${{ runner.os }}-composer-${{ matrix.composer-dependencies }}-
42+
43+
- name: Install Composer dependencies
44+
if: matrix.composer-dependencies == ''
45+
run: composer update --no-suggest
46+
47+
- name: Install Composer dependencies - Lowest
48+
if: matrix.composer-dependencies == 'lowest'
49+
run: composer update --no-suggest --prefer-lowest
50+
51+
# —— Style —————————————————————————————————————————————————————————
52+
- name: Launch PHP-CS-FIXER - tests
53+
uses: docker://oskarstark/php-cs-fixer-ga
54+
with:
55+
args: --dry-run .
56+
57+
# —— PHPUnit —————————————————————————————————————————————————————————
58+
- name: Launch PHPUnit tests
59+
run: php vendor/bin/phpunit
60+
61+
# —— Infection —————————————————————————————————————————————————————————
62+
- name: Launch Infection analysis
63+
run: php vendor/bin/infection
64+
continue-on-error: true

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# PHP-CS-FIXER
2+
.php_cs.cache
3+
4+
# PHPUnit
5+
.phpunit.result.cache
6+
7+
# Infection
8+
infection.log

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.1.0
2+
3+
- Initial release

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
DOCKER = @docker
2+
DOCKER_COMPOSE = @docker-compose
3+
PHP = $(DOCKER_COMPOSE) run --rm php
4+
5+
.DEFAULT_GOAL := help
6+
7+
help:
8+
@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/'
9+
10+
##
11+
## Project
12+
##---------------------------------------------------------------------------
13+
14+
.PHONY: boot up down vendor
15+
16+
boot: ## Launch the project
17+
boot: up vendor
18+
19+
up: ## Up the containers
20+
up:
21+
$(DOCKER_COMPOSE) up -d --remove-orphans
22+
23+
down: ## Down the containers
24+
down:
25+
$(DOCKER_COMPOSE) down
26+
27+
vendor: ## Install the dependencies
28+
vendor:
29+
$(PHP) composer install
30+
31+
##
32+
## Tools
33+
##---------------------------------------------------------------------------
34+
35+
.PHONY: php-cs-fixer phpstan
36+
37+
php-cs-fixer: ## Run PHP-CS-FIXER against a specific DIRECTORY (or . by default)
38+
php-cs-fixer:
39+
$(PHP) vendor/bin/php-cs-fixer fix $(or $(DIRECTORY), .)
40+
41+
phpstan: ## Run PHPStan against a specific DIRECTORY (a specific LEVEL can be define)
42+
phpstan:
43+
$(PHP) vendor/bin/phpstan analyse -c phpstan.neon --level $(or $(LEVEL), 8)
44+
45+
##
46+
## Tests
47+
##---------------------------------------------------------------------------
48+
49+
.PHONY: tests infection
50+
51+
tests: ## Launch the PHPUnit tests
52+
tests:
53+
$(PHP) vendor/bin/phpunit tests
54+
55+
infection: ## Launch Infection
56+
infection:
57+
$(PHP) vendor/bin/infection

README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# guikingone/symfony-uid-doctrine
2+
3+
![SymfonyUidDoctrine](https://github.com/Guikingone/SymfonyUidDoctrine/workflows/SymfonyUidDoctrine/badge.svg?branch=master)
4+
![SymfonyUidDoctrine - Configuration](https://github.com/Guikingone/SymfonyUidDoctrine/workflows/SymfonyUidDoctrine%20-%20Configuration/badge.svg?branch=master)
5+
6+
The `guikingone/symfony-uid-doctrine` aim to provide the support of `Symfony/Uid` as a `Doctrine` type.
7+
8+
## Installation
9+
10+
Consider using `Packagist` and `Composer` when installing the following project:
11+
12+
```bash
13+
composer require guikingone/symfony-uid-doctrine
14+
```
15+
16+
## Configuration
17+
18+
### Uuid
19+
20+
```php
21+
Doctrine\DBAL\Types\Type::addType('uuid', Guikingone\SymfonyUid\Doctrine\Uuid\UuidType::class);
22+
```
23+
24+
```yaml
25+
# config/packages/doctrine.yaml
26+
doctrine:
27+
dbal:
28+
types:
29+
uuid: Guikingone\SymfonyUid\Doctrine\Uuid\UuidType
30+
```
31+
32+
### Ulid
33+
34+
```php
35+
Doctrine\DBAL\Types\Type::addType('ulid', Guikingone\SymfonyUid\Doctrine\Ulid\UlidType::class);
36+
```
37+
38+
```yaml
39+
# config/packages/doctrine.yaml
40+
doctrine:
41+
dbal:
42+
types:
43+
ulid: Guikingone\SymfonyUid\Doctrine\Ulid\UlidType
44+
```
45+
46+
## Usage
47+
48+
### Uuid
49+
50+
```php
51+
use Doctrine\ORM\Mapping as ORM;
52+
use Guikingone\SymfonyUid\Doctrine\Uuid\UuidGenerator;
53+
54+
/**
55+
* @ORM\Entity
56+
* @ORM\Table(name="posts")
57+
*/
58+
class Post
59+
{
60+
/**
61+
* @var Symfony\Component\Uid\Uuid
62+
*
63+
* @ORM\Id
64+
* @ORM\Column(type="uuid", unique=true)
65+
* @ORM\GeneratedValue(strategy="CUSTOM")
66+
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
67+
*/
68+
protected $id;
69+
70+
public function getId(): Uuid
71+
{
72+
return $this->id;
73+
}
74+
}
75+
```
76+
77+
If you don't want to use the generator, consider using the `__construct()` method:
78+
79+
```php
80+
use Doctrine\ORM\Mapping as ORM;
81+
use Symfony\Component\Uid\Uuid;
82+
83+
/**
84+
* @ORM\Entity
85+
* @ORM\Table(name="posts")
86+
*/
87+
class Post
88+
{
89+
/**
90+
* @var Symfony\Component\Uid\Uuid
91+
*
92+
* @ORM\Id
93+
* @ORM\Column(type="uuid", unique=true)
94+
*/
95+
protected $id;
96+
97+
public function __construct()
98+
{
99+
$this->id = Uuid::v4();
100+
}
101+
102+
public function getId(): Uuid
103+
{
104+
return $this->id;
105+
}
106+
}
107+
```
108+
109+
### Ulid
110+
111+
```php
112+
use Doctrine\ORM\Mapping as ORM;
113+
use Guikingone\SymfonyUid\Doctrine\Ulid\UlidGenerator;
114+
115+
/**
116+
* @ORM\Entity
117+
* @ORM\Table(name="posts")
118+
*/
119+
class Post
120+
{
121+
/**
122+
* @var Symfony\Component\Uid\Ulid
123+
*
124+
* @ORM\Id
125+
* @ORM\Column(type="ulid", unique=true)
126+
* @ORM\GeneratedValue(strategy="CUSTOM")
127+
* @ORM\CustomIdGenerator(class=UlidGenerator::class)
128+
*/
129+
protected $id;
130+
131+
public function getId(): Ulid
132+
{
133+
return $this->id;
134+
}
135+
}
136+
```
137+
138+
If you don't want to use the generator, consider using the `__construct()` method:
139+
140+
```php
141+
use Doctrine\ORM\Mapping as ORM;
142+
use Symfony\Component\Uid\Ulid;
143+
144+
/**
145+
* @ORM\Entity
146+
* @ORM\Table(name="posts")
147+
*/
148+
class Post
149+
{
150+
/**
151+
* @var Symfony\Component\Uid\Ulid
152+
*
153+
* @ORM\Id
154+
* @ORM\Column(type="ulid", unique=true)
155+
*/
156+
protected $id;
157+
158+
public function __construct()
159+
{
160+
$this->id = new Ulid();
161+
}
162+
163+
public function getId(): Ulid
164+
{
165+
return $this->id;
166+
}
167+
}
168+
```
169+
170+
## Contributing
171+
172+
Contributions are welcome! Please read [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "guikingone/symfony-uid-doctrine",
3+
"description": "Allow the use of symfony/uid as Doctrine field type",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Guillaume Loulier",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"Guikingone\\SymfonyUid\\Doctrine\\": "src/",
15+
"Guikingone\\SymfonyUid\\Doctrine\\Uuid\\": "src/Uuid/",
16+
"Guikingone\\SymfonyUid\\Doctrine\\Ulid\\": "src/Ulid/"
17+
}
18+
},
19+
"autoload-dev": {
20+
"psr-4": {
21+
"Tests\\Guikingone\\SymfonyUid\\Doctrine\\": "tests/",
22+
"Tests\\Guikingone\\SymfonyUid\\Doctrine\\Uuid\\": "tests/Uuid/",
23+
"Tests\\Guikingone\\SymfonyUid\\Doctrine\\Ulid\\": "tests/Ulid/"
24+
}
25+
},
26+
"require": {
27+
"php": ">=7.2",
28+
"doctrine/orm": "^2.5",
29+
"symfony/uid": "^5.1.0"
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "^8.5",
33+
"phpstan/phpstan": "^0.12.30",
34+
"infection/infection": "^0.15.3",
35+
"friendsofphp/php-cs-fixer": "^2.16"
36+
}
37+
}

0 commit comments

Comments
 (0)