Fix windows path

This commit is contained in:
Khoubza Younes
2021-10-12 20:23:44 +01:00
parent 92069fe278
commit 23c4e5677b
18 changed files with 126 additions and 129 deletions
+2 -1
View File
@@ -13,7 +13,8 @@
], ],
"require": { "require": {
"php": ">=5.3", "php": ">=5.3",
"ext-json": "*" "ext-json": "*",
"ext-mbstring": "*"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
+18 -15
View File
@@ -3,6 +3,7 @@
namespace Flasher\Cli\Prime\Notifier; namespace Flasher\Cli\Prime\Notifier;
use Flasher\Cli\Prime\CliNotification; use Flasher\Cli\Prime\CliNotification;
use Flasher\Cli\Prime\System\Path;
use Flasher\Cli\Prime\System\Program; use Flasher\Cli\Prime\System\Program;
use Flasher\Prime\Envelope; use Flasher\Prime\Envelope;
use Flasher\Prime\Notification\NotificationInterface; use Flasher\Prime\Notification\NotificationInterface;
@@ -51,7 +52,9 @@ abstract class AbstractNotifier implements NotifierInterface
return $this->getBinary(); return $this->getBinary();
} }
foreach ((array) $this->getBinaryPaths() as $path) { foreach ((array)$this->getBinaryPaths() as $path) {
$path = Path::realpath($path);
if (file_exists($path)) { if (file_exists($path)) {
return $path; return $path;
} }
@@ -85,16 +88,16 @@ abstract class AbstractNotifier implements NotifierInterface
{ {
$notification = $envelope->getNotification(); $notification = $envelope->getNotification();
if ($notification instanceof CliNotification && $notification->getIcon()) { if ($notification instanceof CliNotification && $notification->getIcon()) {
return $notification->getIcon(); return Path::realpath($notification->getIcon());
} }
$type = $envelope->getType(); $type = $envelope->getType();
if (isset($this->options['icons'][$type]) && file_exists($this->options['icons'][$type])) { if (isset($this->options['icons'][$type]) && file_exists($this->options['icons'][$type])) {
return $this->options['icons'][$type]; return Path::realpath($this->options['icons'][$type]);
} }
return __DIR__ . '/../Resources/icons/info.png'; return Path::realpath(__DIR__.'/../Resources/icons/info.png');
} }
public function playSound($type = null) public function playSound($type = null)
@@ -103,16 +106,16 @@ abstract class AbstractNotifier implements NotifierInterface
return; return;
} }
\exec('paplay ' . $this->getSound($type)); \exec('paplay '.$this->getSound($type));
} }
public function getSound($type) public function getSound($type)
{ {
if (isset($this->options['sounds'][$type]) && file_exists($this->options['sounds'][$type])) { if (isset($this->options['sounds'][$type]) && file_exists($this->options['sounds'][$type])) {
return $this->options['sounds'][$type]; return Path::realpath($this->options['sounds'][$type]);
} }
return __DIR__ . '/../Resources/sounds/info.wav'; return Path::realpath(__DIR__.'/../Resources/sounds/info.wav');
} }
public function configureOptions(array $options) public function configureOptions(array $options)
@@ -124,17 +127,17 @@ abstract class AbstractNotifier implements NotifierInterface
'binary_paths' => array(), 'binary_paths' => array(),
'title' => 'PHPFlasher', 'title' => 'PHPFlasher',
'icons' => array( 'icons' => array(
NotificationInterface::TYPE_SUCCESS => __DIR__ . '/../Resources/icons/success.png', NotificationInterface::TYPE_SUCCESS => Path::realpath(__DIR__.'/../Resources/icons/success.png'),
NotificationInterface::TYPE_ERROR => __DIR__ . '/../Resources/icons/error.png', NotificationInterface::TYPE_ERROR => Path::realpath(__DIR__.'/../Resources/icons/error.png'),
NotificationInterface::TYPE_INFO => __DIR__ . '/../Resources/icons/info.png', NotificationInterface::TYPE_INFO => Path::realpath(__DIR__.'/../Resources/icons/info.png'),
NotificationInterface::TYPE_WARNING => __DIR__ . '/../Resources/icons/warning.png', NotificationInterface::TYPE_WARNING => Path::realpath(__DIR__.'/../Resources/icons/warning.png'),
), ),
'mute' => false, 'mute' => false,
'sounds' => array( 'sounds' => array(
NotificationInterface::TYPE_SUCCESS => __DIR__ . '/../Resources/sounds/success.wav', NotificationInterface::TYPE_SUCCESS => Path::realpath(__DIR__.'/../Resources/sounds/success.wav'),
NotificationInterface::TYPE_ERROR => __DIR__ . '/../Resources/sounds/error.wav', NotificationInterface::TYPE_ERROR => Path::realpath(__DIR__.'/../Resources/sounds/error.wav'),
NotificationInterface::TYPE_INFO => __DIR__ . '/../Resources/sounds/info.wav', NotificationInterface::TYPE_INFO => Path::realpath(__DIR__.'/../Resources/sounds/info.wav'),
NotificationInterface::TYPE_WARNING => __DIR__ . '/../Resources/sounds/warning.wav', NotificationInterface::TYPE_WARNING => Path::realpath(__DIR__.'/../Resources/sounds/warning.wav'),
), ),
); );
@@ -15,8 +15,7 @@ final class GrowlNotifyNotifier extends AbstractNotifier
$cmd $cmd
->addOption('--message', $envelope->getMessage()) ->addOption('--message', $envelope->getMessage())
->addOption('--title', $this->getTitle($envelope)) ->addOption('--title', $this->getTitle($envelope))
->addOption('--image', $this->getIcon($envelope)) ->addOption('--image', $this->getIcon($envelope));
;
$cmd->run(); $cmd->run();
} }
+1 -2
View File
@@ -15,8 +15,7 @@ final class KDialogNotifier extends AbstractNotifier
$cmd $cmd
->addOption('--passivepopup', $envelope->getMessage()) ->addOption('--passivepopup', $envelope->getMessage())
->addOption('--title', $this->getTitle($envelope)) ->addOption('--title', $this->getTitle($envelope))
->addArgument(5) ->addArgument(5);
;
$cmd->run(); $cmd->run();
} }
+28 -28
View File
@@ -1,28 +1,28 @@
<?php <?php
namespace Flasher\Cli\Prime\Notifier; namespace Flasher\Cli\Prime\Notifier;
use Flasher\Prime\Envelope; use Flasher\Prime\Envelope;
interface NotifierInterface interface NotifierInterface
{ {
/** /**
* @param Envelope[] $envelopes * @param Envelope[] $envelopes
*/ */
public function render(array $envelopes); public function render(array $envelopes);
/** /**
* @return bool * @return bool
*/ */
public function isSupported(); public function isSupported();
/** /**
* @return int * @return int
*/ */
public function getPriority(); public function getPriority();
/** /**
* @return string * @return string
*/ */
public function getBinary(); public function getBinary();
} }
+3 -3
View File
@@ -4,6 +4,7 @@ namespace Flasher\Cli\Prime\Notifier;
use Flasher\Cli\Prime\System\Command; use Flasher\Cli\Prime\System\Command;
use Flasher\Cli\Prime\System\OS; use Flasher\Cli\Prime\System\OS;
use Flasher\Cli\Prime\System\Path;
use Flasher\Prime\Envelope; use Flasher\Prime\Envelope;
final class NotifuNotifier extends AbstractNotifier final class NotifuNotifier extends AbstractNotifier
@@ -15,8 +16,7 @@ final class NotifuNotifier extends AbstractNotifier
$cmd $cmd
->addOption('/m', $envelope->getMessage()) ->addOption('/m', $envelope->getMessage())
->addOption('/p', $this->getTitle($envelope)) ->addOption('/p', $this->getTitle($envelope))
->addOption('/i', $this->getIcon($envelope)) ->addOption('/i', $this->getIcon($envelope));
;
$cmd->run(); $cmd->run();
} }
@@ -31,7 +31,7 @@ final class NotifuNotifier extends AbstractNotifier
$default = array( $default = array(
'binary' => 'notifu', 'binary' => 'notifu',
'binary_paths' => array( 'binary_paths' => array(
__DIR__ . '/../Resources/bin/notifu/notifu.exe', Path::realpath(__DIR__.'/../Resources/bin/notifu/notifu.exe'),
), ),
); );
@@ -18,8 +18,7 @@ final class NotifySendNotifier extends AbstractNotifier
->addOption('--icon', $this->getIcon($envelope)) ->addOption('--icon', $this->getIcon($envelope))
->addOption('--expire-time', $this->getExpireTime()) ->addOption('--expire-time', $this->getExpireTime())
->addArgument($this->getTitle($envelope)) ->addArgument($this->getTitle($envelope))
->addArgument($envelope->getMessage()) ->addArgument($envelope->getMessage());
;
$cmd->run(); $cmd->run();
} }
@@ -31,14 +30,14 @@ final class NotifySendNotifier extends AbstractNotifier
public function getExpireTime() public function getExpireTime()
{ {
return (int) $this->options['expire_time']; return (int)$this->options['expire_time'];
} }
public function configureOptions(array $options) public function configureOptions(array $options)
{ {
$default = array( $default = array(
'binary' => 'notify-send', 'binary' => 'notify-send',
'expire_time' => 0, 'expire_time' => 1,
'priority' => 2, 'priority' => 2,
); );
+17 -17
View File
@@ -1,17 +1,17 @@
<?php <?php
namespace Flasher\Cli\Prime\Notifier; namespace Flasher\Cli\Prime\Notifier;
use Flasher\Prime\Envelope; use Flasher\Prime\Envelope;
final class NullNotifier extends AbstractNotifier final class NullNotifier extends AbstractNotifier
{ {
public function renderEnvelope(Envelope $envelope) public function renderEnvelope(Envelope $envelope)
{ {
} }
public function isSupported() public function isSupported()
{ {
return false; return false;
} }
} }
@@ -4,6 +4,7 @@ namespace Flasher\Cli\Prime\Notifier;
use Flasher\Cli\Prime\System\Command; use Flasher\Cli\Prime\System\Command;
use Flasher\Cli\Prime\System\OS; use Flasher\Cli\Prime\System\OS;
use Flasher\Cli\Prime\System\Path;
use Flasher\Prime\Envelope; use Flasher\Prime\Envelope;
final class SnoreToastNotifier extends AbstractNotifier final class SnoreToastNotifier extends AbstractNotifier
@@ -15,8 +16,7 @@ final class SnoreToastNotifier extends AbstractNotifier
$cmd $cmd
->addOption('-m', $envelope->getMessage()) ->addOption('-m', $envelope->getMessage())
->addOption('-t', $this->getTitle($envelope)) ->addOption('-t', $this->getTitle($envelope))
->addOption('-p', $this->getIcon($envelope)) ->addOption('-p', $this->getIcon($envelope));
;
$cmd->run(); $cmd->run();
} }
@@ -35,7 +35,7 @@ final class SnoreToastNotifier extends AbstractNotifier
$default = array( $default = array(
'binary' => 'snoretoast', 'binary' => 'snoretoast',
'binary_paths' => array( 'binary_paths' => array(
__DIR__ . '/../Resources/bin/snoreToast/snoretoast-x86.exe', Path::realpath(__DIR__.'/../Resources/bin/snoreToast/snoretoast-x86.exe'),
), ),
); );
@@ -14,8 +14,7 @@ final class TerminalNotifierNotifier extends AbstractNotifier
$cmd $cmd
->addOption('-message', $envelope->getMessage()) ->addOption('-message', $envelope->getMessage())
->addOption('-title', $this->getTitle($envelope)) ->addOption('-title', $this->getTitle($envelope));
;
if (version_compare(OS::getMacOSVersion(), '10.9.0', '>=')) { if (version_compare(OS::getMacOSVersion(), '10.9.0', '>=')) {
$cmd->addOption('-appIcon', $this->getIcon($envelope)); $cmd->addOption('-appIcon', $this->getIcon($envelope));
+4 -3
View File
@@ -4,6 +4,7 @@ namespace Flasher\Cli\Prime\Notifier;
use Flasher\Cli\Prime\System\Command; use Flasher\Cli\Prime\System\Command;
use Flasher\Cli\Prime\System\OS; use Flasher\Cli\Prime\System\OS;
use Flasher\Cli\Prime\System\Path;
use Flasher\Prime\Envelope; use Flasher\Prime\Envelope;
final class ToasterNotifier extends AbstractNotifier final class ToasterNotifier extends AbstractNotifier
@@ -13,10 +14,10 @@ final class ToasterNotifier extends AbstractNotifier
$cmd = new Command($this->getProgram()); $cmd = new Command($this->getProgram());
$cmd $cmd
->addOption('-m', $envelope->getMessage())
->addOption('-t', $this->getTitle($envelope)) ->addOption('-t', $this->getTitle($envelope))
->addOption('-m', $envelope->getMessage())
->addOption('-p', $this->getIcon($envelope)) ->addOption('-p', $this->getIcon($envelope))
; ->addArgument('-w');;
$cmd->run(); $cmd->run();
} }
@@ -35,7 +36,7 @@ final class ToasterNotifier extends AbstractNotifier
$default = array( $default = array(
'binary' => 'toast', 'binary' => 'toast',
'binary_paths' => array( 'binary_paths' => array(
__DIR__ . '/../Resources/bin/toaster/toast.exe', Path::realpath(__DIR__.'/../Resources/bin/toaster/toast.exe'),
), ),
); );
+2 -3
View File
@@ -14,9 +14,8 @@ final class ZenityNotifier extends AbstractNotifier
$cmd $cmd
->addArgument('--notification') ->addArgument('--notification')
->addOption('--text', $this->getTitle($envelope) . '\n\n' . $envelope->getMessage()) ->addOption('--text', $this->getTitle($envelope).'\n\n'.$envelope->getMessage())
->addOption('--window-icon', $this->getIcon($envelope)) ->addOption('--window-icon', $this->getIcon($envelope));
;
$cmd->run(); $cmd->run();
} }
+7 -20
View File
@@ -7,8 +7,6 @@ class Command
private $command; private $command;
private $options = array(); private $options = array();
private $arguments = array(); private $arguments = array();
private $output;
private $exitCode;
public function __construct($command) public function __construct($command)
{ {
@@ -31,11 +29,15 @@ class Command
public function run() public function run()
{ {
$command = $this->command . ' ' . $this->formatOptions() . ' ' . $this->formatArguments(); $command = $this->command.' '.$this->formatOptions().' '.$this->formatArguments();
// dd($command); if (OS::isWindows()) {
pclose(popen("start /B ".$command, "r"));
exec($command, $this->output, $this->exitCode); return;
}
exec($command);
} }
private function formatArguments() private function formatArguments()
@@ -56,19 +58,4 @@ class Command
return $line; return $line;
} }
public function getOutput()
{
return $this->output;
}
public function getExitCode()
{
return $this->exitCode;
}
public function isSuccessful()
{
return 0 === $this->getExitCode();
}
} }
+2 -4
View File
@@ -53,10 +53,8 @@ class OS
public static function getMacOSVersion() public static function getMacOSVersion()
{ {
$cmd = new Command('sw_vers'); exec('sw_vers -productVersion', $output);
$cmd->addArgument('-productVersion');
$cmd->run();
return trim($cmd->getOutput()); return trim($output);
} }
} }
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace Flasher\Cli\Prime\System;
class Path
{
public static function realpath($path)
{
return realpath(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path));
}
}
+19 -19
View File
@@ -1,19 +1,19 @@
<?php <?php
namespace Flasher\Cli\Prime\System; namespace Flasher\Cli\Prime\System;
class Program class Program
{ {
public static function exist($program) public static function exist($program)
{ {
if (OS::isWindows()) { if (OS::isWindows()) {
$output = shell_exec("where $program"); $output = shell_exec("where $program 2>null");
return !empty($output); return !empty($output);
} }
$output = shell_exec("command -v $program"); $output = shell_exec("command -v $program");
return !empty($output); return !empty($output);
} }
} }
+1
View File
@@ -28,6 +28,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=5.3", "php": ">=5.3",
"ext-mbstring": "*",
"php-flasher/flasher": "^0.6.3" "php-flasher/flasher": "^0.6.3"
}, },
"autoload": { "autoload": {
@@ -39,13 +39,13 @@ JAVASCRIPT;
tag.setAttribute('src', '${rootScript}'); tag.setAttribute('src', '${rootScript}');
tag.setAttribute('type', 'text/javascript'); tag.setAttribute('type', 'text/javascript');
tag.onload = flasherRender tag.onload = flasherRender;
document.body.appendChild(tag); document.body.appendChild(tag);
} else { } else {
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
flasherRender() flasherRender();
}) });
} }
</script> </script>
JAVASCRIPT; JAVASCRIPT;