|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpBoot\Entity\Annotations; |
|
4
|
|
|
|
|
5
|
|
|
use PhpBoot\Annotation\AnnotationBlock; |
|
6
|
|
|
use PhpBoot\Annotation\AnnotationTag; |
|
7
|
|
|
use PhpBoot\Entity\ContainerFactory; |
|
8
|
|
|
use PhpBoot\Entity\EntityContainer; |
|
9
|
|
|
use PhpBoot\Entity\EntityContainerBuilder; |
|
10
|
|
|
use PhpBoot\Entity\MixedTypeContainer; |
|
11
|
|
|
use PhpBoot\Exceptions\AnnotationSyntaxException; |
|
12
|
|
|
use PhpBoot\Utils\AnnotationParams; |
|
13
|
|
|
use PhpBoot\Utils\TypeHint; |
|
14
|
|
|
|
|
15
|
|
|
class VarAnnotationHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param EntityContainer $container |
|
19
|
|
|
* @param AnnotationBlock|AnnotationTag $ann |
|
20
|
|
|
* @param EntityContainerBuilder $builder |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
7 |
|
public function __invoke(EntityContainer $container, $ann, EntityContainerBuilder $builder) |
|
24
|
|
|
{ |
|
25
|
7 |
|
$params = new AnnotationParams($ann->description, 3); |
|
26
|
7 |
|
if($params->count()){ |
|
27
|
7 |
|
$type = $params->getParam(0); |
|
28
|
|
|
//TODO 校验type类型 |
|
29
|
7 |
|
$target = $ann->parent->name; |
|
30
|
7 |
|
$property = $container->getProperty($target); |
|
31
|
7 |
|
$property or \PhpBoot\abort($container->getClassName()." property $target not exist "); |
|
32
|
7 |
|
if($type == null || $type == 'mixed'){ |
|
33
|
|
|
$property->container = new MixedTypeContainer(); |
|
34
|
|
|
} else{ |
|
35
|
|
|
// TODO 判断$type是否匹配 |
|
36
|
7 |
|
$property->type = TypeHint::normalize($type, $container->getClassName()); |
|
37
|
|
|
// TODO 防止递归死循环 |
|
38
|
7 |
|
$property->container = ContainerFactory::create($builder, $property->type); |
|
39
|
|
|
} |
|
40
|
7 |
|
}else{ |
|
41
|
|
|
\PhpBoot\abort(new AnnotationSyntaxException( |
|
42
|
|
|
"The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::{$ann->parent->name} require 1 param, 0 given" |
|
43
|
|
|
)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
} |