mirror of
https://github.com/Respect/Validation.git
synced 2024-06-06 15:52:15 +02:00
02b70bf1cb
That way, everything related to messages would stay in the same namespace. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
34 lines
777 B
PHP
34 lines
777 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Message;
|
|
|
|
use ReflectionClass;
|
|
|
|
final class TemplateCollector
|
|
{
|
|
/** @var array<string, array<Template>> */
|
|
private array $templates = [];
|
|
|
|
/**
|
|
* @return array<Template>
|
|
*/
|
|
public function extract(object $object): array
|
|
{
|
|
if (!isset($this->templates[$object::class])) {
|
|
$reflection = new ReflectionClass($object);
|
|
foreach ($reflection->getAttributes(Template::class) as $attribute) {
|
|
$this->templates[$object::class][] = $attribute->newInstance();
|
|
}
|
|
}
|
|
|
|
return $this->templates[$object::class] ?? [];
|
|
}
|
|
}
|