PHPackages                             secit-pl/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. secit-pl/validation-bundle

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

secit-pl/validation-bundle
==========================

Additional Symfony validators.

3.1.0(2y ago)613.3k↓17.6%2MITPHPPHP &gt;=8.2.0

Since Jun 7Pushed 1y agoCompare

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

READMEChangelogDependencies (8)Versions (16)Used By (0)

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

[](#symfony-validation-bundle)

Additional validators set for Symfony.

Compatibility matrix
--------------------

[](#compatibility-matrix)

Bundle versionMaintainedSymfony versionsMin. PHP version3.xYes7.x8.2.02.xNo6.x8.0.01.8No5.x, 4.x7.1.0Installation
------------

[](#installation)

From the command line run

```
$ composer require secit-pl/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.

> From Symfony 6.0 you can also use the Unique validator.
>
>

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.

```
