Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"require": {
"php": "^7.2",
"illuminate/support": "5.6.*|5.7.*|5.8.*|^6.0"
"illuminate/support": "5.6.*|5.7.*|5.8.*|^6.0",
"symfony/process": "^5.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "symfony/process": "^4.0|^5.0"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

},
"autoload": {
"files": [
Expand Down
29 changes: 28 additions & 1 deletion src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use Illuminate\Support\Str;
use Illuminate\Support\Collection;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

if (! function_exists('tinker')) {
function tinker(...$args)
{
Expand Down Expand Up @@ -33,6 +36,30 @@ function tinker(...$args)
->combine($args)
->all();

exec('open "tinkerwell://?cwd='.base64_encode(base_path()).'&scope='.base64_encode(serialize($namedParameters)).'"');
//exec('open "tinkerwell://?cwd='.base64_encode(base_path()).'&scope='.base64_encode(serialize($namedParameters)).'"');

// For MacOS
$command = 'open "tinkerwell://?cwd='.base64_encode(base_path()).'&scope='.base64_encode(serialize($namedParameters)).'"';

if (windows_os()) {
$logPath = base_path() . '\\storage\\logs\\tinkerwell-' . date("Y-m-d") . '.log';

// For Windows || ATTENTION ... I added a ^ before the & to escape it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comment! This is an annoying quirk of Windows that I only discovered the other day. 👍

// If base64 encoded string of $namedParameters lenght is too long (I don't know what the limit is) the execution will fail
$command ='start tinkerwell://?cwd='.base64_encode(base_path()) .'^&scope='.base64_encode(serialize($namedParameters)) . ' >> ' . $logPath . ' 2>&1';
}

$process = new Process($command);

try {
$process->run();

if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

} catch (ProcessFailedException $exception) {
Log::error($exception->getMessage());
}
}
}