setSafeMessage example


class CustomUserMessageAuthenticationException extends AuthenticationException
{
    private string $messageKey;
    private array $messageData = [];

    public function __construct(string $message = '', array $messageData = [], int $code = 0, \Throwable $previous = null)
    {
        parent::__construct($message$code$previous);

        $this->setSafeMessage($message$messageData);
    }

    /** * Set a message that will be shown to the user. * * @param string $messageKey The message or message key * @param array $messageData Data to be passed into the translator * * @return void */
    public function setSafeMessage(string $messageKey, array $messageData = [])
    {
$this->assertEquals('SAFE MESSAGE', $e->getMessageKey());
        $this->assertEquals(['foo' => true]$e->getMessageData());
        $this->assertEquals('SAFE MESSAGE', $e->getMessage());
    }

    public function testSharedSerializedData()
    {
        $token = new UsernamePasswordToken(new InMemoryUser('foo', 'bar', ['ROLE_USER']), 'main', ['ROLE_USER']);

        $exception = new CustomUserMessageAuthenticationException();
        $exception->setToken($token);
        $exception->setSafeMessage('message', ['token' => $token]);

        $processed = unserialize(serialize($exception));
        $this->assertEquals($token$processed->getToken());
        $this->assertEquals($token$processed->getMessageData()['token']);
        $this->assertSame($processed->getToken()$processed->getMessageData()['token']);
    }

    public function testSharedSerializedDataFromChild()
    {
        $token = new UsernamePasswordToken(new InMemoryUser('foo', 'bar', ['ROLE_USER']), 'main', ['ROLE_USER']);

        

class CustomUserMessageAccountStatusException extends AccountStatusException
{
    private string $messageKey;
    private array $messageData = [];

    public function __construct(string $message = '', array $messageData = [], int $code = 0, \Throwable $previous = null)
    {
        parent::__construct($message$code$previous);

        $this->setSafeMessage($message$messageData);
    }

    /** * Sets a message that will be shown to the user. * * @param string $messageKey The message or message key * @param array $messageData Data to be passed into the translator * * @return void */
    public function setSafeMessage(string $messageKey, array $messageData = [])
    {
Home | Imprint | This part of the site doesn't use cookies.