1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This is a partial modification of Illuminate\Framework |
5
|
|
|
* and that is licenced by MIT License (MIT) |
6
|
|
|
* Copyright (c) <Taylor Otwell> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Vluzrmos\Tinker; |
10
|
|
|
|
11
|
|
|
use Illuminate\Contracts\Console\Kernel as Console; |
12
|
|
|
use Illuminate\Database\Eloquent\Model; |
13
|
|
|
use Illuminate\Support\Collection; |
14
|
|
|
use Laravel\Lumen\Application; |
15
|
|
|
use Psy\Configuration; |
16
|
|
|
use Psy\Shell; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class TinkerShell. |
20
|
|
|
*/ |
21
|
|
|
class TinkerShell |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Lumen Console Kernel. |
25
|
|
|
* @var \Laravel\Lumen\Console\Kernel |
26
|
|
|
*/ |
27
|
|
|
protected $console; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* PsySH Shell. |
31
|
|
|
* @var Shell |
32
|
|
|
*/ |
33
|
|
|
protected $shell; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* artisan commands to include in the tinker shell. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $commandWhiteList = [ |
41
|
|
|
'migrate', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Console $console |
46
|
|
|
*/ |
47
|
|
|
public function __construct(Console $console) |
48
|
|
|
{ |
49
|
|
|
$this->console = $console; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set files that should be included on shell. |
54
|
|
|
* |
55
|
|
|
* @param $include |
56
|
|
|
* @return $this |
57
|
|
|
*/ |
58
|
|
|
public function setIncludes($include) |
59
|
|
|
{ |
60
|
|
|
$this->getShell()->setIncludes($include); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get instance of the Shell. |
67
|
|
|
* @return \Psy\Shell |
68
|
|
|
*/ |
69
|
|
|
public function getShell() |
70
|
|
|
{ |
71
|
|
|
if (! $this->shell) { |
72
|
|
|
$config = new Configuration(); |
73
|
|
|
|
74
|
|
|
$config->getPresenter()->addCasters( |
75
|
|
|
$this->getCasters() |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->shell = new Shell($config); |
79
|
|
|
|
80
|
|
|
$this->shell->addCommands($this->getCommands()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $this->shell; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get an array of Laravel tailored casters. |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
protected function getCasters() |
92
|
|
|
{ |
93
|
|
|
return [ |
94
|
|
|
Application::class => 'Vluzrmos\Tinker\TinkerCaster::castApplication', |
95
|
|
|
Collection::class => 'Vluzrmos\Tinker\TinkerCaster::castCollection', |
96
|
|
|
Model::class => 'Vluzrmos\Tinker\TinkerCaster::castModel', |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get artisan commands to pass through to PsySH. |
102
|
|
|
* |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
protected function getCommands() |
106
|
|
|
{ |
107
|
|
|
$commands = []; |
108
|
|
|
|
109
|
|
|
foreach ($this->console->all() as $name => $command) { |
110
|
|
|
if (in_array($name, $this->commandWhiteList)) { |
111
|
|
|
$commands[] = $command; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $commands; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Run the shell. |
120
|
|
|
*/ |
121
|
|
|
public function run() |
122
|
|
|
{ |
123
|
|
|
$this->getShell()->run(); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.