1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpBoot\Console\Annotations; |
4
|
|
|
|
5
|
|
|
use DI\InvokerInterface; |
6
|
|
|
use FastRoute\RouteParser\Std; |
7
|
|
|
use PhpBoot\Console\Command; |
8
|
|
|
use PhpBoot\Console\ConsoleContainer; |
9
|
|
|
use PhpBoot\Entity\ContainerFactory; |
10
|
|
|
use PhpBoot\Entity\EntityContainerBuilder; |
11
|
|
|
use PhpBoot\Metas\ReturnMeta; |
12
|
|
|
use PhpBoot\Annotation\AnnotationBlock; |
13
|
|
|
use PhpBoot\Annotation\AnnotationTag; |
14
|
|
|
use PhpBoot\Entity\MixedTypeContainer; |
15
|
|
|
use PhpBoot\Exceptions\AnnotationSyntaxException; |
16
|
|
|
use PhpBoot\Metas\ParamMeta; |
17
|
|
|
use PhpBoot\Utils\AnnotationParams; |
18
|
|
|
|
19
|
|
|
class CommandAnnotationHandler |
20
|
|
|
{ |
21
|
1 |
|
public function __invoke(ConsoleContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
22
|
|
|
{ |
23
|
1 |
|
$params = new AnnotationParams($ann->description, 2); |
24
|
1 |
|
$target = $ann->parent->name; |
25
|
1 |
|
$name = $params->getParam(0, $target); |
26
|
|
|
|
27
|
|
|
//获取方法参数信息 |
28
|
1 |
|
$rfl = new \ReflectionClass($container->getClassName()); |
29
|
1 |
|
$method = $rfl->getMethod($target); |
30
|
1 |
|
$methodParams = $method->getParameters(); |
31
|
|
|
|
32
|
1 |
|
$command = new Command($target, $name); |
33
|
1 |
|
$command->setDescription($container->getSummary().' : '.$ann->parent->summary); |
34
|
1 |
|
$command->setHelp($ann->parent->description); |
35
|
|
|
|
36
|
|
|
//设置参数列表 |
37
|
1 |
|
$paramsMeta = []; |
38
|
1 |
|
foreach ($methodParams as $param){ |
39
|
1 |
|
$paramName = $param->getName(); |
|
|
|
|
40
|
1 |
|
$source = "argv.$paramName"; |
41
|
1 |
|
$paramClass = $param->getClass(); |
42
|
1 |
|
if($paramClass){ |
43
|
|
|
$paramClass = $paramClass->getName(); |
|
|
|
|
44
|
|
|
} |
45
|
1 |
|
$entityContainer = ContainerFactory::create($entityBuilder, $paramClass); |
46
|
1 |
|
$meta = new ParamMeta($paramName, |
47
|
1 |
|
$source, |
48
|
1 |
|
$paramClass?:'mixed', |
49
|
1 |
|
$param->isOptional(), |
50
|
1 |
|
$param->isOptional()?$param->getDefaultValue():null, |
51
|
1 |
|
$param->isPassedByReference(), |
52
|
1 |
|
null, |
53
|
1 |
|
'', |
54
|
|
|
$entityContainer |
55
|
1 |
|
); |
56
|
1 |
|
$paramsMeta[] = $meta; |
57
|
1 |
|
} |
58
|
1 |
|
$command->setParamMetas($paramsMeta); |
59
|
1 |
|
$container->addCommand($target, $command); |
60
|
|
|
} |
61
|
|
|
} |