/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
src/Illuminate/Container/Attributes/Bind.php
53 строки
1 KB
Richard van Baarsen
[13.x] Allow for passing enums to attributes (#59297)
20 мар 2026, 18:16
Не верифицирован
20 мар 2026, 18:16
8254189
Код
Авторство
О чём код?
<?php namespace Illuminate\Container\Attributes; use Attribute; use InvalidArgumentException; use UnitEnum; use function Illuminate\Support\enum_value; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] class Bind { /** * The concrete class to bind to. * * @var class-string */ public string $concrete; /** * The environments the binding should apply for. * * @var non-empty-array<int, string> */ public array $environments = []; /** * Create a new attribute instance. * * @param class-string $concrete * @param non-empty-array<int, \UnitEnum|non-empty-string>|non-empty-string|\UnitEnum $environments * * @throws \InvalidArgumentException */ public function __construct( string $concrete, string|array|UnitEnum $environments = ['*'], ) { $environments = array_filter(is_array($environments) ? $environments : [$environments]); if ($environments === []) { throw new InvalidArgumentException('The environment property must be set and cannot be empty.'); } $this->concrete = $concrete; $this->environments = array_map( fn ($environment) => enum_value($environment), $environments, ); } }