PHPackages                             toshy/validation-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. toshy/validation-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

toshy/validation-bundle
=======================

Additional Symfony validators.

2.2.0(4mo ago)06.2k↓50%MITPHPPHP ^8.0

Since Dec 23Pushed 4mo agoCompare

[ Source](https://github.com/ToshY/validation-bundle)[ Packagist](https://packagist.org/packages/toshy/validation-bundle)[ Docs](https://secit.pl)[ RSS](/packages/toshy-validation-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (6)Used By (0)

Symfony Validation Bundle
=========================

[](#symfony-validation-bundle)

Additional validators set for Symfony 6/7/8

> This is a fork from [secit-pl/validation-bundle](https://github.com/secit-pl/validation-bundle).

Installation
------------

[](#installation)

From the command line run

```
$ composer require toshy/validation-bundle

```

Validators
----------

[](#validators)

### NotBlankIf

[](#notblankif)

This validator checks if value is not blank like a standard NotBlank Symfony validator, but also allows define the condition when the NotBlank validation should be performed using Symfony Expression Language.

> From Symfony 6.2 you can also use When validator.
>
>
>
>

Example usage

```
use SecIT\ValidationBundle\Validator\Constraints as SecITAssert;

// ...

#[SecITAssert\NotBlankIf("this.isSuperUser")]
private ?string $email = null;

public function isSuperUser(): bool
{
    return true;
}
```

Parameters

ParameterTypeDefaultDescriptionexpressionstringempty arrayThe expression that will be evaluated. If the expression evaluates to a false value (using ==, not ===), not blank validation won't be performed)valuesarrayempty arrayThe values of the custom variables used in the expression. Values can be of any type (numeric, boolean, strings, null, etc.)### FileExtension

[](#fileextension)

This validator checks if file has valid file extension.

> From Symfony 6.2 you can also use the "extensions" option in File validator.
>
>
>
>

Example usage

```
use SecIT\ValidationBundle\Validator\Constraints as SecITAssert;

// ...

#[SecITAssert\FileExtension(["jpg", "jpeg", "png"])]
private $file;
```

```
use SecIT\ValidationBundle\Validator\Constraints as SecITAssert;

// ...

#[SecITAssert\FileExtension(disallowedExtensions: ["jpg", "jpeg", "png"])]
private $file;
```

Parameters

ParameterTypeDefaultDescriptionvalidExtensionsarrayempty arrayAllowed/valid file extensions listdisallowedExtensionsarrayempty arrayDisallowed/invalid file extensions listmatchCaseboolfalseEnable/disable verifying the file extension case**Caution!** It's highly recommended to use this validator together with native Symfony File/Image validator.

```
use SecIT\ValidationBundle\Validator\Constraints as SecITAssert;
use Symfony\Component\Validator\Constraints as Assert;

// ...

#[Assert\Image(maxSize: '2M', mimeTypes: ["image/jpg", "image/jpeg", "image/png"])]
#[SecITAssert\FileExtension(validExtensions: ["jpg", "jpeg", "png"])]
private $file;
```

### CollectionOfUniqueElements

[](#collectionofuniqueelements)

Checks if collection contains only unique elements.

Parameters

ParameterTypeDefaultDescriptionmatchCaseboolfalseEnable/disable verifying the characters casecustomNormalizationFunctionnull or callablenullCustom normalization function```
use SecIT\ValidationBundle\Validator\Constraints as SecITAssert;

// ...

#[SecITAssert\CollectionOfUniqueElements()]
private $collection;
```

This validator can also be used to validate unique files upload.

```
