k2gl/entity-exist

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

Installs: 1 324

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.12.0 2024-04-21 16:27 UTC

This package is auto-updated.

Last update: 2024-04-21 16:29:38 UTC


README

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