forked from sofascore/purgatory-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressionValues.php
More file actions
45 lines (35 loc) · 1.18 KB
/
ExpressionValues.php
File metadata and controls
45 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Sofascore\PurgatoryBundle\Attribute\RouteParamValue;
use Sofascore\PurgatoryBundle\Exception\LogicException;
use Symfony\Component\ExpressionLanguage\Expression;
final class ExpressionValues extends AbstractValues
{
public readonly Expression $expression;
public function __construct(
string|Expression $expression,
) {
$this->expression = self::normalizeExpression($expression);
}
/**
* @return non-empty-list<string>
*/
protected function getValues(): array
{
return [(string) $this->expression];
}
public static function type(): string
{
return 'expression';
}
private static function normalizeExpression(string|Expression $expression): Expression
{
if ($expression instanceof Expression) {
return $expression;
}
if (!class_exists(Expression::class)) {
throw new LogicException(\sprintf('You cannot use "%s" because the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".', self::class));
}
return new Expression($expression);
}
}