Skip to content
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

Add AbstractCliBasedDriver::launchProcess() #112

Merged
merged 3 commits into from
Sep 30, 2024
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
2 changes: 1 addition & 1 deletion example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@

$driver = $notifier->getDriver();

echo 'Notification ', $result ? 'successfully sent' : 'failed', ' with ', str_replace('Joli\\JoliNotif\\Driver\\', '', $driver::class), \PHP_EOL;
echo 'Notification ', $result ? 'successfully sent' : 'failed', ' with ', str_replace('Joli\JoliNotif\Driver\\', '', $driver::class), \PHP_EOL;
2 changes: 1 addition & 1 deletion src/DefaultNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
?LoggerInterface $logger = null,
/** @var list<DriverInterface> $additionalDrivers */
private readonly array $additionalDrivers = [],
private readonly bool $useOnlyAdditionalDrivers = false
private readonly bool $useOnlyAdditionalDrivers = false,
) {
$this->logger = $logger ?? new NullLogger();
}
Expand Down
7 changes: 6 additions & 1 deletion src/Driver/AbstractCliBasedDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function send(Notification $notification): bool
}

$process = new Process(array_merge([$binary], $arguments));
$process->run();
$this->launchProcess($process);

return $this->handleExitCode($process);
}
Expand Down Expand Up @@ -125,6 +125,11 @@ protected function isBinaryAvailable(): bool
return $process->isSuccessful();
}

protected function launchProcess(Process $process): void
{
$process->run();
}

/**
* Return whether the process executed successfully.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Driver/AppleScriptDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public function getPriority(): int

protected function getCommandLineArguments(Notification $notification): array
{
$script = 'display notification "' . str_replace('"', '\\"', $notification->getBody() ?? '') . '"';
$script = 'display notification "' . str_replace('"', '\"', $notification->getBody() ?? '') . '"';

if ($notification->getTitle()) {
$script .= ' with title "' . str_replace('"', '\\"', $notification->getTitle()) . '"';
$script .= ' with title "' . str_replace('"', '\"', $notification->getTitle()) . '"';
}

if ($notification->getOption('subtitle')) {
$script .= ' subtitle "' . str_replace('"', '\\"', (string) $notification->getOption('subtitle')) . '"';
$script .= ' subtitle "' . str_replace('"', '\"', (string) $notification->getOption('subtitle')) . '"';
}

if ($notification->getOption('sound')) {
$script .= ' sound name "' . str_replace('"', '\\"', (string) $notification->getOption('sound')) . '"';
$script .= ' sound name "' . str_replace('"', '\"', (string) $notification->getOption('sound')) . '"';
}

return [
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/NotifuDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Joli\JoliNotif\Notification;
use JoliCode\PhpOsHelper\OsHelper;
use Symfony\Component\Process\Process;

/**
* This driver can be used on Windows Seven and provides its own binaries if
Expand Down Expand Up @@ -71,4 +72,14 @@ protected function getCommandLineArguments(Notification $notification): array

return $arguments;
}

protected function launchProcess(Process $process): void
{
$process->start();
}

protected function handleExitCode(Process $process): bool
{
return true;
}
}
7 changes: 6 additions & 1 deletion src/Driver/SnoreToastDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ protected function getCommandLineArguments(Notification $notification): array
return $arguments;
}

protected function launchProcess(Process $process): void
{
$process->start();
}

protected function handleExitCode(Process $process): bool
{
return 0 < $process->getExitCode();
return true;
}
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidNotificationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
Notification $notification,
string $message = '',
int $code = 0,
?\Throwable $previous = null
?\Throwable $previous = null,
) {
$this->notification = $notification;

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/NoSupportedNotifierException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NoSupportedNotifierException extends \RuntimeException implements Exceptio
public function __construct(
string $message = 'No supported notifier',
int $code = 0,
?\Throwable $previous = null
?\Throwable $previous = null,
) {
parent::__construct($message, $code, $previous);
}
Expand Down
Loading