-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
60 lines (54 loc) · 1.57 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Mkusher\PadawanDi;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Complete\Resolver\NodeTypeResolver;
use Complete\Completer\CompleterFactory;
use Parser\UseParser;
use Entity\FQCN;
class Plugin
{
public function __construct(
EventDispatcher $dispatcher,
TypeResolver $resolver,
Completer $completer
) {
$this->dispatcher = $dispatcher;
$this->resolver = $resolver;
$this->completer = $completer;
}
public function init()
{
$this->dispatcher->addListener(
NodeTypeResolver::BLOCK_START,
[$this->resolver, 'handleParentTypeEvent']
);
$this->dispatcher->addListener(
NodeTypeResolver::BLOCK_END,
[$this->resolver, 'handleTypeResolveEvent']
);
$this->dispatcher->addListener(
CompleterFactory::CUSTOM_COMPLETER,
[$this, 'handleCompleteEvent']
);
}
public function handleCompleteEvent($e)
{
$context = $e->context;
if ($context->isMethodCall()) {
list($type, $isThis, $types, $workingNode) = $context->getData();
$fqcn = array_pop($types);
if ($fqcn instanceof FQCN
&& $fqcn->toString() === 'DI\\Container'
&& $workingNode->name === 'get'
) {
$e->completer = $this->completer;
}
}
}
/** @var Completer */
private $completer;
/** @var TypeResolver */
private $resolver;
/** @var EventDispatcher */
private $dispatcher;
}