Skip to content

Environment Helper #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2025
Merged
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
14 changes: 7 additions & 7 deletions src/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

namespace Native\Laravel;

use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use Native\Laravel\Client\Client;
use Native\Laravel\Facades\Window;

class Alert
{
protected ?string $type;

protected ?string $title;

protected ?string $detail;

protected ?array $buttons;

protected ?int $defaultId;

protected ?int $cancelId;

final public function __construct(protected Client $client)
{
}
final public function __construct(protected Client $client) {}

public static function new()
{
Expand Down Expand Up @@ -76,7 +76,7 @@ public function show(string $message): int
'detail' => $this->detail,
'buttons' => $this->buttons,
'defaultId' => $this->defaultId,
'cancelId' => $this->cancelId
'cancelId' => $this->cancelId,
]);

return (int) $response->json('result');
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use Native\Laravel\Support\Environment;

use function Laravel\Prompts\error;
use function Laravel\Prompts\info;
Expand Down Expand Up @@ -53,7 +54,7 @@ private function processEnvironment(): static
{
$locationCommand = 'which';

if (PHP_OS_FAMILY === 'Windows') {
if (Environment::isWindows()) {
$locationCommand = 'where';
}

Expand Down Expand Up @@ -154,9 +155,9 @@ private function outputToClipboard(): void
$json = json_encode($this->debugInfo->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

// Copy json to clipboard
if (PHP_OS_FAMILY === 'Windows') {
if (Environment::isWindows()) {
Process::run('echo '.escapeshellarg($json).' | clip');
} elseif (PHP_OS_FAMILY === 'Linux') {
} elseif (Environment::isLinux()) {
Process::run('echo '.escapeshellarg($json).' | xclip -selection clipboard');
} else {
Process::run('echo '.escapeshellarg($json).' | pbcopy');
Expand Down
2 changes: 1 addition & 1 deletion src/Events/EventWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function register(): void
Event::listen('*', function (string $eventName, array $data) {
$event = $data[0] ?? (object) null;

if(! is_object($event)) {
if (! is_object($event)) {
return;
}

Expand Down
31 changes: 31 additions & 0 deletions src/Support/Environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Native\Laravel\Support;

class Environment
{
public static function isWindows(): bool
{
return PHP_OS_FAMILY === 'Windows';
}

public static function isLinux(): bool
{
return PHP_OS_FAMILY === 'Linux';
}

public static function isMac(): bool
{
return PHP_OS_FAMILY === 'Darwin';
}

public static function isUnknown(): bool
{
return PHP_OS_FAMILY === 'Unknown';
}

public static function isUnixLike(): bool
{
return static::isLinux() || static::isMac();
}
}
3 changes: 2 additions & 1 deletion src/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Native\Laravel\Client\Client;
use Native\Laravel\DataObjects\Printer;
use Native\Laravel\Support\Environment;
use Native\Laravel\Support\Timezones;

class System
Expand Down Expand Up @@ -79,7 +80,7 @@ public function timezone(): string
{
$timezones = new Timezones;

if (PHP_OS_FAMILY === 'Windows') {
if (Environment::isWindows()) {
$timezone = $timezones->translateFromWindowsString(exec('tzutil /g'));
} else {
$timezone = $timezones->translateFromAbbreviatedString(exec('date +%Z'));
Expand Down