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