Skip to content

Commit 99fa9e9

Browse files
committed
tinker
1 parent 4a7dbc9 commit 99fa9e9

File tree

4 files changed

+19
-29
lines changed

4 files changed

+19
-29
lines changed

src/Loaders/BaseLoader.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class BaseLoader implements LoaderInterface
1111
{
1212
protected Tinker $tinker;
1313

14-
public function init()
14+
public function init(): void
1515
{
1616
$config = new Configuration([
1717
'configFile' => null,
@@ -26,7 +26,9 @@ public function init()
2626
$config->setVerbosity(Configuration::VERBOSITY_QUIET);
2727
$config->setHistoryFile(defined('PHP_WINDOWS_VERSION_BUILD') ? 'null' : '/dev/null');
2828
$config->setRawOutput(false);
29-
$config->setUsePcntl(false);
29+
if (getenv('KUBERNETES_SERVICE_HOST') || defined('PHP_WINDOWS_VERSION_BUILD')) {
30+
$config->setUsePcntl(false);
31+
}
3032

3133
if (class_exists('Illuminate\Support\Collection') && class_exists('Laravel\Tinker\TinkerCaster')) {
3234
$config->getPresenter()->addCasters([
@@ -47,10 +49,10 @@ public function init()
4749
$this->tinker = new Tinker(new CustomOutputModifier, $config);
4850
}
4951

50-
public function execute(string $code)
52+
public function execute(string $code): string
5153
{
5254
$output = $this->tinker->execute($code);
5355

54-
echo trim($output);
56+
return trim($output);
5557
}
5658
}

src/Loaders/LoaderInterface.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ public function name(): string;
1010

1111
public function version(): string;
1212

13-
/**
14-
* @return void
15-
*/
16-
public function init();
13+
public function init(): void;
1714

18-
/**
19-
* @return string
20-
*/
21-
public function execute(string $code);
15+
public function execute(string $code): string;
2216
}

src/Loaders/WordPressLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function name(): string
2626
public function version(): string
2727
{
2828
try {
29-
return get_bloginfo('version');
29+
if (function_exists('get_bloginfo')) {
30+
return get_bloginfo('version');
31+
}
3032
} catch (Throwable $e) {
3133
//
3234
}

src/Tinker.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,15 @@ public function execute(string $phpCode): string
2929
{
3030
$phpCode = $this->removeComments($phpCode);
3131

32-
$phpCode = explode("\n", $phpCode);
33-
34-
$output = '';
35-
36-
foreach ($phpCode as $key => $line) {
37-
$this->shell->addInput($line);
38-
$closure = new ExecutionLoopClosure($this->shell);
39-
$closure->execute();
40-
$result = $this->outputModifier->modify($this->cleanOutput($this->output->fetch()));
41-
if (trim($result) !== '' && trim($result) !== 'null') {
42-
$output .= 'Line '.$key + 1 .' Result:'.PHP_EOL;
43-
$output .= $result;
44-
$output .= PHP_EOL;
45-
}
46-
}
32+
$this->shell->addInput($phpCode);
33+
34+
$closure = new ExecutionLoopClosure($this->shell);
35+
36+
$closure->execute();
37+
38+
$output = $this->cleanOutput($this->output->fetch());
4739

48-
return $output;
40+
return $this->outputModifier->modify($output);
4941
}
5042

5143
protected function createShell(BufferedOutput $output, Configuration $config): Shell

0 commit comments

Comments
 (0)