Exception
1 day ago
SpecificationFactory
1 day ago
AggregateSpecification.php
1 day ago
AndSpecification.php
1 day ago
CollectionOperators.php
1 day ago
CollectionSpecification.php
1 day ago
ComparisonOperators.php
1 day ago
ComparisonSpecification.php
1 day ago
CompositeSpecification.php
1 day ago
ContainsSpecification.php
1 day ago
Context.php
1 day ago
ContextAwareSpecification.php
1 day ago
DateComparisonSpecification.php
1 day ago
DateOperators.php
1 day ago
DateRangeSpecification.php
1 day ago
DateRelativeDaysSpecification.php
1 day ago
DateRelativeDeductedSpecification.php
1 day ago
DateSpecification.php
1 day ago
DateTimeFactory.php
1 day ago
DateTrait.php
1 day ago
EndsWithSpecification.php
1 day ago
FactSpecification.php
1 day ago
FactTrait.php
1 day ago
FloatComparisonSpecification.php
1 day ago
FloatRangeSpecification.php
1 day ago
IntegerComparisonSpecification.php
1 day ago
IntegerRangeSpecification.php
1 day ago
NotSpecification.php
1 day ago
NullSpecification.php
1 day ago
OperatorExpression.php
1 day ago
OrSpecification.php
1 day ago
RangeOperators.php
1 day ago
RangeSpecification.php
1 day ago
Specification.php
1 day ago
SpecificationFactory.php
1 day ago
StartsWithSpecification.php
1 day ago
StringComparisonSpecification.php
1 day ago
StringMatchSpecification.php
1 day ago
StringOperators.php
1 day ago
Type.php
1 day ago
TypeSpecification.php
1 day ago
TypeTrait.php
1 day ago
Types.php
1 day ago
Type.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Expression; |
| 6 | |
| 7 | use DomainException; |
| 8 | |
| 9 | final class Type |
| 10 | { |
| 11 | private string $type; |
| 12 | |
| 13 | private function __construct(string $type) |
| 14 | { |
| 15 | $this->type = $type; |
| 16 | |
| 17 | $this->validate(); |
| 18 | } |
| 19 | |
| 20 | private function validate(): void |
| 21 | { |
| 22 | $valid = [ |
| 23 | Types::STRING, |
| 24 | Types::INTEGER, |
| 25 | Types::FLOAT, |
| 26 | Types::DATE, |
| 27 | ]; |
| 28 | |
| 29 | if (! in_array($this->type, $valid, true)) { |
| 30 | throw new DomainException('Invalid type.'); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public static function string(): self |
| 35 | { |
| 36 | return new self(Types::STRING); |
| 37 | } |
| 38 | |
| 39 | public static function integer(): self |
| 40 | { |
| 41 | return new self(Types::INTEGER); |
| 42 | } |
| 43 | |
| 44 | public static function float(): self |
| 45 | { |
| 46 | return new self(Types::FLOAT); |
| 47 | } |
| 48 | |
| 49 | public static function date(): self |
| 50 | { |
| 51 | return new self(Types::DATE); |
| 52 | } |
| 53 | |
| 54 | public function __toString(): string |
| 55 | { |
| 56 | return $this->type; |
| 57 | } |
| 58 | |
| 59 | } |
| 60 |