Class to support Flow annotations
- Primitive types relevant to PHP
nullundefinednumbernumericstringintfloatboolbooleanarrayobject- * (exists)
- Literal types for
string,intandfloat - Maybe types marked with
?sign, e.g.?bool - Object types, e.g.
{ hello: 'world' } - Exact object type, e.g.
{| hello: 'world' |} - Array types, e.g.
string[] - Tuple types, e.g.
[number, string, 'three'] - Union types, e.g.
int | float | string - Intersection types, e.g.
{ a: int } & {b : float } - Grouping with parentheses, e.g.
(int | string)[]
Type aliases are supported by using Registry::set() method that can registers any alias of compiled validator or any \Closure validator.
Duck\Types\AnnotationInterface
| Name | Description |
|---|---|
| Annotation::UNION_ANNOTATION = ":union-annotation:" | |
| Annotation::INTERSECTION_ANNOTATION = ":intersection-annotation:" | |
| Annotation::SHAPE_ANNOTATION = ":shape-annotation:" | |
| Annotation::ARRAY_ANNOTATION = ":array-annotation:" | |
| Annotation::TUPLE_ANNOTATION = ":tuple-annotation:" |
| Name | Description |
|---|---|
| Annotation::compile() | Compiles AST-like tree into validator \Closure |
| Annotation::parse() | Parses Flow annotation into AST-like tree |
Description
public static compile (array $tree): \ClosureCompiles AST-like tree into validator \Closure
Parameters
(array) $tree: AST-like tree genereated with {@see \Annotation::parse()}
Return Values
\Closure
Description
public static parse (string $annotation): arrayParses Flow annotation into AST-like tree
Parameters
(string) $annotation: Flow annotation
Return Values
array
AST-like tree