PHPackages                             vrok/symfony-addons - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. vrok/symfony-addons

ActiveSymfony-bundle[Testing &amp; Quality](/categories/testing)

vrok/symfony-addons
===================

Symfony helper classes

3.4.0(1mo ago)14.8k11MITPHPPHP ^8.4CI passing

Since Aug 1Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/j-schumann/symfony-addons)[ Packagist](https://packagist.org/packages/vrok/symfony-addons)[ Docs](https://vrok.de)[ RSS](/packages/vrok-symfony-addons/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (48)Versions (56)Used By (1)

vrok/symfony-addons
===================

[](#vroksymfony-addons)

This is a library with additional classes for usage in combination with the Symfony framework.

[![CI Status](https://github.com/j-schumann/symfony-addons/actions/workflows/ci.yaml/badge.svg)](https://github.com/j-schumann/symfony-addons/actions)[![Coverage Status](https://camo.githubusercontent.com/ad3388875aa02cd28c00112e398839c1c44da15176ba34a90c638bf46fe9b1c5/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a2d736368756d616e6e2f73796d666f6e792d6164646f6e732f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/j-schumann/symfony-addons?branch=main)

Mailer helpers
--------------

[](#mailer-helpers)

### Automatically set a sender address

[](#automatically-set-a-sender-address)

We want to replace setting the sender via mailer.yaml as envelope (@see ) as this would still require each mail to have a FROM address set and also doesn't allow us to set a sender name.

config/services.yaml:

```
    Vrok\SymfonyAddons\EventSubscriber\AutoSenderSubscriber:
        arguments:
            $sender: "%env(MAILER_SENDER)%"
```

.env\[.local\]:

```
MAILER_SENDER="Change Me "
```

Messenger helpers
-----------------

[](#messenger-helpers)

### Resetting the logger before/after a message

[](#resetting-the-logger-beforeafter-a-message)

We want to group all log entries belonging to a single message to be grouped with a distinct UID and to flush a buffer logger after a message was processed (successfully or failed), to immediately see the entries in the log:

config/services.yaml:

```
    # add a UID to the context, same UID for each HTTP request or console command
    # and with the event subscriber also for each message
    Monolog\Processor\UidProcessor:
        tags:
            - { name: monolog.processor, handler: logstash }

    # resets the UID when a message is received, flushed a buffer after a
    # message was handled. Add this multiple times if you want to flush more
    # channels, e.g. messenger
    app.event.reset_app_logger:
        class: Vrok\SymfonyAddons\EventSubscriber\ResetLoggerSubscriber
        tags:
            - { name: monolog.logger, channel: app }
```

Validators
----------

[](#validators)

### AtLeastOneOf

[](#atleastoneof)

Works like Symfony's own AtLeastOneOf constraint, but instead of returning a message like `This value should satisfy at least ...` it returns the message of the last failed validation. Can be used for obviously optional form fields where only simple messages should be displayed when `AtLeastOne` is used with `Blank` as first constraint.
See `AtLeastOneOfValidatorTest` for examples.

### NoHtml

[](#nohtml)

This validator tries to detect if a string contains HTML, to allow only plain text.
See `NoHtmlValidatorTest` for examples of allowed / forbidden values.

### NoLineBreak

[](#nolinebreak)

This validator raises a violation if it detects one or more linebreak characters in the validated string.
Detects unicode linebreaks, see `NoLineBreaksValidatorTest` for details.

### NoSurroundingWhitespace

[](#nosurroundingwhitespace)

This validator raises a violation if it detects trailing or leading whitespace or newline characters in the validated string. Linebreaks and spaces are valid within the string.
Uses a regex looking for `\s` and `\R`, see `NoSurroundingWhitespaceValidatorTest`for details on detected characters.

### PasswordStrength

[](#passwordstrength)

This validator evaluates the strength of a given password string by determining its entropy instead of requireing something like "must contain at least one uppercase &amp; one digit &amp; one special char".
Allows to set a `minStrength` to vary the requirements. See `Vrok\SymfonyAddons\Helper\PasswordStrength` for details on the calculation.

PHPUnit helpers
---------------

[](#phpunit-helpers)

### Using the ApiPlatformTestCase

[](#using-the-apiplatformtestcase)

This class is used to test ApiPlatform endpoints by specifying input data and verifying the response data. It combines the traits documented below to refresh the database before each test, optionally create authenticated requests and check for created logs / sent emails / dispatched messages. It allows to easily check for expected response content, allowed or forbidden keys in the data or to verify against a given schema.

Requires "symfony/browser-kit" &amp; "symfony/http-client" to be installed (and of cause ApiPlatform).

```
