Skip to content

Checks if there is at least one row with the required field in the database, for example, a row with the same identifier

License

Notifications You must be signed in to change notification settings

k2gl/entity-exist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assert entity exist or not using Symfony constraints and Doctrine.

GitHub Actions

Installation

You can add this library as a local, per-project dependency to your project using Composer:

composer require k2gl/entity-exist

Configuration

Makes classes in src/ available to be used as services in services.yaml

services:
    K2gl\Component\Validator\Constraint\EntityExist\:
        resource: '../vendor/k2gl/entity-exist/src/'
        arguments: ['@doctrine.orm.entity_manager']
        tags:
            - { name: validator.constraint_validator }

Usage

AssertEntityNotExist

use K2gl\Component\Validator\Constraint\EntityExist\AssertEntityNotExist;

readonly class RegisterUserOrder
{
    public function __construct(
        #[Assert\NotBlank]
        #[Assert\Email]
        #[AssertEntityNotExist(
            entity: User::class,
            property: 'email',
            message: 'User with email "%value%" already registered.'
        )]
        public string $email,
    ) {
    }
}

AssertEntityExist

use K2gl\Component\Validator\Constraint\EntityExist\AssertEntityExist;

readonly class TransferUserToOtherUnitOrder
{
    public function __construct(
        #[Assert\NotBlank]
        #[AssertEntityExist(
            entity: User::class,
            property: 'uuid',
        )]
        public string $user,
        #[Assert\NotBlank]
        #[AssertEntityExist(
            entity: Unit::class,
            property: 'uuid',
        )]
        public string $unit,        
    ) {
    }
}

Pull requests are always welcome

Collaborate with pull requests

About

Checks if there is at least one row with the required field in the database, for example, a row with the same identifier

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages