diff --git a/composer.json b/composer.json index aacfee2..7a3fd1c 100644 --- a/composer.json +++ b/composer.json @@ -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" }, "autoload": { "files": [ diff --git a/src/helper.php b/src/helper.php index 6bb01a7..586fc2e 100644 --- a/src/helper.php +++ b/src/helper.php @@ -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) { @@ -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. + // 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()); + } } }