|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Railt package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Railt\SDL\Compiler; |
|
11
|
|
|
|
|
12
|
|
|
use Psr\Log\LoggerAwareInterface; |
|
13
|
|
|
use Psr\Log\LoggerAwareTrait; |
|
14
|
|
|
use Railt\Io\Readable; |
|
15
|
|
|
use Railt\Reflection\Contracts\Definition; |
|
16
|
|
|
use Railt\Reflection\Dictionary\CallbackDictionary; |
|
17
|
|
|
use Railt\SDL\Compiler; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Dictionary |
|
21
|
|
|
*/ |
|
22
|
|
|
class Dictionary extends CallbackDictionary implements LoggerAwareInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use LoggerAwareTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Compiler |
|
28
|
|
|
*/ |
|
29
|
|
|
private $compiler; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Dictionary constructor. |
|
33
|
|
|
* @param Compiler $compiler |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(Compiler $compiler) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->compiler = $compiler; |
|
38
|
|
|
|
|
39
|
|
|
$this->addLoggerListener(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
private function addLoggerListener(): void |
|
46
|
|
|
{ |
|
47
|
|
|
parent::onTypeNotFound(function (string $type, ?Definition $from): void { |
|
|
|
|
|
|
48
|
|
|
if ($this->logger) { |
|
49
|
|
|
$direct = 'Try to load type %s from direct method executing'; |
|
50
|
|
|
$context = 'Try to load type %s from %s (%s:%d)'; |
|
51
|
|
|
|
|
52
|
|
|
$message = $from === null ? \sprintf($direct, $type) : \sprintf($context, $type, $from, |
|
53
|
|
|
$from->getFile(), $from->getLine()); |
|
54
|
|
|
|
|
55
|
|
|
$this->logger->debug($message); |
|
56
|
|
|
} |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param \Closure $then |
|
62
|
|
|
*/ |
|
63
|
|
|
public function onTypeNotFound(\Closure $then): void |
|
64
|
|
|
{ |
|
65
|
|
|
parent::onTypeNotFound(function (string $type, ?Definition $from) use ($then): void { |
|
66
|
|
|
if (($file = $then($type, $from)) instanceof Readable) { |
|
67
|
|
|
$this->compiler->compile($file); |
|
68
|
|
|
} |
|
69
|
|
|
}); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.