1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Atreyu; |
4
|
|
|
|
5
|
|
|
class InjectionException extends InjectorException |
6
|
|
|
{ |
7
|
|
|
public $dependencyChain; |
8
|
|
|
|
9
|
|
|
public function __construct(array $inProgressMakes, $message = "", $code = 0, \Exception $previous = null) |
10
|
|
|
{ |
11
|
|
|
$this->dependencyChain = array_flip($inProgressMakes); |
12
|
|
|
ksort($this->dependencyChain); |
13
|
|
|
|
14
|
|
|
parent::__construct($message, $code, $previous); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Add a human readable version of the invalid callable to the standard 'invalid invokable' message. |
19
|
|
|
*/ |
20
|
|
|
public static function fromInvalidCallable( |
21
|
|
|
array $inProgressMakes, |
22
|
|
|
$callableOrMethodStr, |
23
|
|
|
\Exception $previous = null |
24
|
|
|
) { |
25
|
|
|
$callableString = null; |
26
|
|
|
|
27
|
|
|
if (is_string($callableOrMethodStr)) { |
28
|
|
|
$callableString .= $callableOrMethodStr; |
29
|
|
|
} else if (is_array($callableOrMethodStr) && |
30
|
|
|
array_key_exists(0, $callableOrMethodStr) && |
31
|
|
|
array_key_exists(0, $callableOrMethodStr)) { |
32
|
|
|
if (is_string($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) { |
33
|
|
|
$callableString .= $callableOrMethodStr[0].'::'.$callableOrMethodStr[1]; |
34
|
|
|
} else if (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) { |
35
|
|
|
$callableString .= sprintf( |
36
|
|
|
"[object(%s), '%s']", |
37
|
|
|
get_class($callableOrMethodStr[0]), |
38
|
|
|
$callableOrMethodStr[1] |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($callableString) { |
|
|
|
|
44
|
|
|
// Prevent accidental usage of long strings from filling logs. |
45
|
|
|
$callableString = substr($callableString, 0, 250); |
46
|
|
|
$message = sprintf( |
47
|
|
|
"%s. Invalid callable was '%s'", |
48
|
|
|
Injector::M_INVOKABLE, |
49
|
|
|
$callableString |
50
|
|
|
); |
51
|
|
|
} else { |
52
|
|
|
$message = \Atreyu\Injector::M_INVOKABLE; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return new self($inProgressMakes, $message, Injector::E_INVOKABLE, $previous); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns the hierarchy of dependencies that were being created when |
60
|
|
|
* the exception occurred. |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getDependencyChain() |
64
|
|
|
{ |
65
|
|
|
return $this->dependencyChain; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: