1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: caoyangmin |
5
|
|
|
* Date: 2018/6/14 |
6
|
|
|
* Time: δΈε2:10 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace PhpBoot\Console; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use DI\FactoryInterface; |
13
|
|
|
use Doctrine\Common\Cache\Cache; |
14
|
|
|
use PhpBoot\Annotation\ContainerBuilder; |
15
|
|
|
use DI\InvokerInterface as DIInvokerInterface; |
16
|
|
|
use PhpBoot\Console\Annotations\ClassAnnotationHandler; |
17
|
|
|
use PhpBoot\Console\Annotations\CommandAnnotationHandler; |
18
|
|
|
use PhpBoot\Console\Annotations\CommandNameAnnotationHandler; |
19
|
|
|
use PhpBoot\Console\Annotations\ParamAnnotationHandler; |
20
|
|
|
use PhpBoot\Console\Annotations\ValidateAnnotationHandler; |
21
|
|
|
|
22
|
|
|
class ConsoleContainerBuilder extends ContainerBuilder |
23
|
|
|
{ |
24
|
|
|
static $DEFAULT_ANNOTATIONS=[ |
|
|
|
|
25
|
|
|
[ClassAnnotationHandler::class, 'class'], |
26
|
|
|
[CommandNameAnnotationHandler::class, "class.children[?name=='command']"], |
27
|
|
|
[CommandAnnotationHandler::class, "methods.*.children[?name=='command'][]"], |
28
|
|
|
[ParamAnnotationHandler::class, "methods.*.children[?name=='param'][]"], |
29
|
|
|
[ValidateAnnotationHandler::class, "methods.*.children[].children[?name=='v'][]"], |
30
|
|
|
]; |
31
|
|
|
/** |
32
|
|
|
* @var FactoryInterface |
33
|
|
|
*/ |
34
|
|
|
private $factory; |
35
|
|
|
/** |
36
|
|
|
* @var DIInvokerInterface |
37
|
|
|
*/ |
38
|
|
|
private $diInvoker; |
39
|
|
|
|
40
|
1 |
View Code Duplication |
public function __construct(FactoryInterface $factory, |
|
|
|
|
41
|
|
|
DIInvokerInterface $diInvoker, |
42
|
|
|
Cache $cache, |
43
|
|
|
array $annotations = null |
44
|
|
|
) |
45
|
|
|
{ |
46
|
1 |
|
if($annotations){ |
47
|
|
|
parent::__construct($annotations, $cache); |
48
|
|
|
}else{ |
49
|
1 |
|
parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache); |
50
|
|
|
} |
51
|
1 |
|
$this->factory = $factory; |
52
|
1 |
|
$this->diInvoker = $diInvoker; |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $className |
57
|
|
|
* @return ConsoleContainer |
58
|
|
|
*/ |
59
|
1 |
|
protected function createContainer($className) |
60
|
|
|
{ |
61
|
1 |
|
return $this->factory->make(ConsoleContainer::class, ['className'=>$className]); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
protected function handleAnnotation($handlerName, $container, $ann) |
65
|
|
|
{ |
66
|
1 |
|
$handler = $this->factory->make($handlerName); |
67
|
1 |
|
return $this->diInvoker->call($handler, [$container, $ann]); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
protected function postCreateContainer($object) |
71
|
|
|
{ |
72
|
1 |
|
parent::postCreateContainer($object); |
73
|
|
|
/**@var ConsoleContainer $object*/ |
74
|
1 |
|
$object->postCreate(); |
75
|
|
|
} |
76
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.