-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathShellController.php
68 lines (61 loc) · 1.44 KB
/
ShellController.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
61
62
63
64
65
66
67
68
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yii\shell;
use yii\console\Controller;
use Psy\Shell;
use Psy\Configuration;
/**
* Runs interactive shell. That is especially useful when developing an application and you want to try
* some method of your code.
*
* @author Daniel Gomez Pan <[email protected]>
* @since 2.0
*/
class ShellController extends Controller
{
/**
* @var array include file(s) before starting tinker shell
*/
public $include = [];
/**
* @var array PsySH shell configuration array
* @since 2.0.6
*/
public $shellConfig = [];
/**
* @inheritdoc
*/
public function options($actionID)
{
return array_merge(parent::options($actionID), [
'include'
]);
}
/**
* Runs interactive shell
*/
public function actionIndex()
{
$config = new Configuration;
$config->loadConfig($this->shellConfig);
$config->getPresenter()->addCasters(
$this->getCasters()
);
$shell = new Shell($config);
$shell->setIncludes($this->include);
$shell->run();
}
/**
* @return array casters for psysh
*/
protected function getCasters()
{
return [
'yii\db\ActiveRecord' => 'yii\shell\YiiCaster::castModel',
];
}
}