Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Validator Bundle Laravel Package

assoconnect/validator-bundle

View on GitHub
Deep Wiki
Context7

AssoConnectDoctrineValidatorBundle

Installation with Symfony Flex

a) First download the bundle

composer require assoconnect/validator-bundle

b) Accept the contrib recipes installation from Symfony Flex

-  WARNING  assoconnect/validator-bundle (0.1): From gitlab.com/assoconnect/validator-bundle
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): 

Usage

You can use them as any other Symfony validation:

<?php
namespace App\Entity;


use AssoConnect\ValidatorBundle\Validator\Constraint as AssoConnectAssert

Class User
{
	/**
	 * [@AssoConnectAssert](https://github.com/AssoConnectAssert)\Email()
	 */
	public $email;
}

The EntityValidator sets up default validators for your entity properties based on their Doctrine types. For example,

<?php
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use AssoConnect\DoctrineValidatorBundle\Validator\Constraint as AssoConnectAssert;

/**
 * [@AssoConnectAssert](https://github.com/AssoConnectAssert)\Entity()
 */
Class BankAccount
{
	/**
	 * [@ORM](https://github.com/ORM)\Column(type="iban")
	 */
	public $iban;
}

is equivalent to this code:

<?php
namespace App\Entity;

use Symfony\Compotent\Validator\Constraint as Assert;
use Doctrine\ORM\Mapping as ORM;

Class BankAccount
{
	/**
	 * [@Assert](https://github.com/Assert)\Iban()
	 * [@Assert](https://github.com/Assert)\Length(27)
	 * [@Assert](https://github.com/Assert)\NotNull()
	 * [@ORM](https://github.com/ORM)\Column(type="string", length="27")
	 */
	public $iban;
}

Custom constraints

You can use different constraints for a given type. For instance, if you want to use Symfony default email constraint, you have to create your own constraint and validator:

<?php
namespace App\Validator\Constraints;

use AssoConnect\ValidatorBundle\Validator\Constraints\Entity;

Class CustomEntity extends Entity
{}
 
<?php
namespace App\Validator\Constraints;

use AssoConnect\ValidatorBundle\Validator\Constraints\EntityValidator;
use Symfony\Component\Validator\Constraints\Email;

Class CustomEntityValidator extends EntityValidator
{

    protected function getConstraintsForType(string $type) :array
    {
        if ($type === 'email') {
            return [new Email()];
        } else {
            return parent::getConstraintsForType($type);
        }
    }

}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views