generated from JetBrains/intellij-platform-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtinker_run.php
78 lines (64 loc) · 2.82 KB
/
tinker_run.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
69
70
71
72
73
74
75
76
77
78
/*<?php /**/
define('LARAVEL_START', microtime(true));
echo "%%START-OUTPUT%%";
$projectSettings = json_decode($argv[2]) ?? new stdClass();
require ($projectSettings->vendorRoot ?: __DIR__) . '/vendor/autoload.php';
$app = require_once ($projectSettings->laravelRoot ?: __DIR__) . '/bootstrap/app.php';
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
$config = new \Psy\Configuration([
'updateCheck' => 'never',
'usePcntl' => false,
'useReadline' => false,
'prompt' => '',
'theme' => 'compact',
]);
$config->setRawOutput(true);
$config->setColorMode(\Psy\Configuration::COLOR_MODE_FORCED);
$config->setInteractiveMode(\Psy\Configuration::INTERACTIVE_MODE_DISABLED);
$casters = [
'Illuminate\Support\Collection' => 'Laravel\Tinker\TinkerCaster::castCollection',
'Illuminate\Support\HtmlString' => 'Laravel\Tinker\TinkerCaster::castHtmlString',
'Illuminate\Support\Stringable' => 'Laravel\Tinker\TinkerCaster::castStringable',
'Illuminate\Database\Eloquent\Model' => 'Laravel\Tinker\TinkerCaster::castModel',
'Illuminate\Foundation\Application' => 'Laravel\Tinker\TinkerCaster::castApplication',
'Illuminate\Process\ProcessResult' => 'Laravel\Tinker\TinkerCaster::castProcessResult',
];
$existingCasters = [];
foreach($casters as $castableClass => $casterMethod) {
list($casterClass, $casterClassMethod) = explode('::', $casterMethod);
if(class_exists($castableClass) && method_exists($casterClass, $casterClassMethod)) {
$existingCasters[$castableClass] = $casterMethod;
}
}
$config->getPresenter()->addCasters($existingCasters);
$config->setHistoryFile(defined('PHP_WINDOWS_VERSION_BUILD') ? 'nul' : '/dev/null');
$shell = new \Psy\Shell($config);
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$shell->setOutput($output);
$closure = new \Psy\ExecutionLoopClosure($shell);
$autoloadClassMap = ($projectSettings->vendorRoot ?: __DIR__) . '/vendor/composer/autoload_classmap.php';
if(class_exists('\Laravel\Tinker\ClassAliasAutoloader')) {
$loader = \Laravel\Tinker\ClassAliasAutoloader::register($shell, $autoloadClassMap);
}
$unsanitizedRunCode = token_get_all($argv[1]);
$sanitizedRunCode = '';
foreach($unsanitizedRunCode as $token) {
if (!is_string($token)) {
[$id, $token] = $token;
if (in_array($id, [T_COMMENT, T_DOC_COMMENT, T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG], true)) {
continue;
}
}
$sanitizedRunCode .= $token;
}
$shell->addInput($sanitizedRunCode, true);
if($projectSettings->terminateApp) {
$shell->addInput('echo "%%END-OUTPUT%%";', true);
$shell->addInput('app()->terminate();', true);
}
$shell->addInput('usleep(250000); throw new \Psy\Exception\BreakException("%%END-OUTPUT%%");', true);
$closure->execute();
if(isset($loader)) {
$loader->unregister();
}