respect-validation/library/Message/Parameter/Raw.php
Henrique Moody d25557cd72
Extract parameter processor into multiple classes
By extracting them into different processors, the code in the rendered
becomes much more straightforward, and the design makes it possible to
create processors easily. This change will allow users to customize that
behavior if they want to.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-02-22 01:56:22 +01:00

30 lines
690 B
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Message\Parameter;
use function is_bool;
use function is_scalar;
final class Raw implements Processor
{
public function __construct(
private readonly Processor $nextProcessor,
) {
}
public function process(string $name, mixed $value, ?string $modifier = null): string
{
if ($modifier === 'raw' && is_scalar($value)) {
return is_bool($value) ? (string) (int) $value : (string) $value;
}
return $this->nextProcessor->process($name, $value, $modifier);
}
}