respect-validation/library/Message/Stringifier/KeepOriginalStringName.php
Henrique Moody 3093d79155
Allow to customize parameter stringifier
We have seen users that want to change the default behavior of parameter
stringifier:

* Change the depth level shown from an array.

* Change the number of elements shown from an array.

* Not add quotes to some parameters.

Because of that, this commit will allow users to customize the parameter
stringifier.

This commit will also update the documentation to instruct how to
customize it.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-12 13:49:54 +02:00

33 lines
758 B
PHP

<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Message\Stringifier;
use Respect\Validation\Message\ParameterStringifier;
use function is_string;
use function Respect\Stringifier\stringify;
final class KeepOriginalStringName implements ParameterStringifier
{
/**
* {@inheritDoc}
*/
public function stringify(string $name, $value): string
{
if ($name === 'name' && is_string($value)) {
return $value;
}
return stringify($value);
}
}