skrepr / id-type
Symfony bundle for generating and validating ID types
Installs: 417
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2.0
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.10 || ^3.0
- symfony/framework-bundle: ^6.0 || ^7.0
- symfony/uid: ^6.2 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.2
- roave/security-advisories: dev-latest
- skrepr/dto-tester: ^0.2
- symfony/maker-bundle: ^1.48
- symfony/phpunit-bridge: ^6.1 || ^7.0
- symfony/var-dumper: ^6.2 || ^7.0
This package is not auto-updated.
Last update: 2024-04-23 11:38:04 UTC
README
Skrepr ID Types
Symfony bundle for generating and validating ID types
Prerequisites
This version of the project requires:
- PHP 8.2+
- Symfony 6.0+
Installation
You can install the library through composer:
$ composer require skrepr/id-type
The bundle should be enabled by syfmony/flex but if not:
// config/bundles.php <?php return [ Skrepr\IdType\SkreprIdTypeBundle::class => ['all' => true], ];
Usage
To generate an UuidType:
bin/console make:id-type <id_name>
Where id_name
is something like "user_id".
With this maker command, two files are generated (src/ValueObject/UserId.php
and src/Persistence/Doctrine/UserIdType.php
)
and also the new type is added to config/packages/doctrine.yaml
.
To use this new id in your entity:
<?php declare(strict_types=1); namespace App\Entity; use App\ValueObject\UserId; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class User { #[ORM\Id] #[ORM\Column(type: 'user_id')] public readonly UserId $id; #[ORM\Column(type: 'string')] public string $name; public function __construct(string $name) { $this->id = UserId::generate(); $this->name = $name; } }