|
1
|
|
|
<?php |
|
2
|
|
|
namespace Wandu\DI\Exception; |
|
3
|
|
|
|
|
4
|
|
|
use Interop\Container\Exception\NotFoundException; |
|
5
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
|
6
|
|
|
use RuntimeException; |
|
7
|
|
|
use ReflectionClass; |
|
8
|
|
|
use Wandu\Reflection\ReflectionCallable; |
|
9
|
|
|
|
|
10
|
|
|
class CannotResolveException extends RuntimeException implements NotFoundExceptionInterface, NotFoundException |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
protected $class; |
|
14
|
|
|
|
|
15
|
|
|
/** @var callable */ |
|
16
|
|
|
protected $callee; |
|
17
|
|
|
|
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
protected $parameter; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $classOrCallee |
|
23
|
|
|
* @param string $parameter |
|
24
|
|
|
*/ |
|
25
|
9 |
|
public function __construct($classOrCallee, $parameter) |
|
26
|
|
|
{ |
|
27
|
9 |
|
if (is_string($classOrCallee) && class_exists($classOrCallee)) { |
|
28
|
6 |
|
$this->class = $classOrCallee; |
|
29
|
6 |
|
$refl = new ReflectionClass($classOrCallee); |
|
30
|
6 |
|
$this->file = $refl->getFileName(); |
|
31
|
6 |
|
if ($propRefl = $refl->getConstructor()) { |
|
32
|
6 |
|
$this->line = $propRefl->getStartLine(); |
|
33
|
|
|
} else { |
|
34
|
|
|
$this->line = $refl->getStartLine(); |
|
35
|
|
|
} |
|
36
|
6 |
|
$this->message = "cannot resolve the \"{$parameter}\" parameter in the \"{$classOrCallee}\" class."; |
|
37
|
4 |
|
} elseif (is_callable($classOrCallee)) { |
|
38
|
4 |
|
$this->callee = $classOrCallee; |
|
39
|
4 |
|
$refl = new ReflectionCallable($classOrCallee); |
|
40
|
4 |
|
$this->line = $refl->getStartLine(); |
|
41
|
4 |
|
$this->file = $refl->getFileName(); |
|
42
|
4 |
|
$this->message = "cannot resolve the \"{$parameter}\" parameter in the {$refl->getCallableName()}."; |
|
43
|
|
|
} |
|
44
|
9 |
|
$this->parameter = $parameter; |
|
45
|
9 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
7 |
|
public function getClass() |
|
51
|
|
|
{ |
|
52
|
7 |
|
return $this->class; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return callable |
|
57
|
|
|
*/ |
|
58
|
3 |
|
public function getCallee() |
|
59
|
|
|
{ |
|
60
|
3 |
|
return $this->callee; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
7 |
|
public function getParameter() |
|
67
|
|
|
{ |
|
68
|
7 |
|
return $this->parameter; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|