mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
The `Id`, `Name`, and `Path` value objects are not only message-related concerns, they're part of the core of the library, hence it makes sense to place them at the root namespace.
33 lines
633 B
PHP
33 lines
633 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation;
|
|
|
|
use function lcfirst;
|
|
use function strrchr;
|
|
use function substr;
|
|
use function ucfirst;
|
|
|
|
final readonly class Id
|
|
{
|
|
public function __construct(
|
|
public string $value,
|
|
) {
|
|
}
|
|
|
|
public static function fromRule(Rule $rule): self
|
|
{
|
|
return new self(lcfirst(substr((string) strrchr($rule::class, '\\'), 1)));
|
|
}
|
|
|
|
public function withPrefix(string $prefix): self
|
|
{
|
|
return new self($prefix . ucfirst($this->value));
|
|
}
|
|
}
|