You've already forked php-flasher
mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-04-05 12:32:55 +01:00
allow users to set icon for every notification
This commit is contained in:
@@ -11,6 +11,9 @@ final class CliNotification extends Notification
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/** @var string */
|
||||
private $icon;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -27,10 +30,27 @@ final class CliNotification extends Notification
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIcon()
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon
|
||||
*/
|
||||
public function setIcon($icon)
|
||||
{
|
||||
$this->icon = $icon;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return array_merge(parent::toArray(), array(
|
||||
'title' => $this->getTitle(),
|
||||
'icon' => $this->getIcon(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,17 @@ final class CliNotificationBuilder extends NotificationBuilder
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function icon($icon)
|
||||
{
|
||||
$notification = $this->envelope->getNotification();
|
||||
$notification->setIcon($icon);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Flasher\Cli\Prime\Notifier;
|
||||
|
||||
use Flasher\Cli\Prime\CliNotification;
|
||||
use Flasher\Cli\Prime\System\Program;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Notification\NotificationInterface;
|
||||
@@ -76,12 +77,19 @@ abstract class AbstractNotifier implements NotifierInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param Envelope $envelope
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIcon($type)
|
||||
public function getIcon(Envelope $envelope)
|
||||
{
|
||||
$notification = $envelope->getNotification();
|
||||
if ($notification instanceof CliNotification && $notification->getIcon()) {
|
||||
return $notification->getIcon();
|
||||
}
|
||||
|
||||
$type = $envelope->getType();
|
||||
|
||||
if (isset($this->options['icons'][$type]) && file_exists($this->options['icons'][$type])) {
|
||||
return $this->options['icons'][$type];
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ final class GrowlNotifyNotifier extends AbstractNotifier
|
||||
$cmd
|
||||
->addOption('--message', $envelope->getMessage())
|
||||
->addOption('--title', $this->getTitle($envelope))
|
||||
->addOption('--image', $this->getIcon($envelope->getType()))
|
||||
->addOption('--image', $this->getIcon($envelope))
|
||||
;
|
||||
|
||||
$cmd->run();
|
||||
|
||||
@@ -15,7 +15,7 @@ final class NotifuNotifier extends AbstractNotifier
|
||||
$cmd
|
||||
->addOption('/m', $envelope->getMessage())
|
||||
->addOption('/p', $this->getTitle($envelope))
|
||||
->addOption('/i', $this->getIcon($envelope->getType()))
|
||||
->addOption('/i', $this->getIcon($envelope))
|
||||
;
|
||||
|
||||
$cmd->run();
|
||||
@@ -23,7 +23,7 @@ final class NotifuNotifier extends AbstractNotifier
|
||||
|
||||
public function isSupported()
|
||||
{
|
||||
return $this->isEnabled() && OS::isWindows() && $this->getProgram();
|
||||
return $this->isEnabled() && OS::isWindowsSeven() && $this->getProgram();
|
||||
}
|
||||
|
||||
public function configureOptions(array $options)
|
||||
|
||||
@@ -15,7 +15,7 @@ final class NotifySendNotifier extends AbstractNotifier
|
||||
$cmd
|
||||
->addOption('--urgency', 'normal')
|
||||
->addOption('--app-name', 'notify')
|
||||
->addOption('--icon', $this->getIcon($envelope->getType()))
|
||||
->addOption('--icon', $this->getIcon($envelope))
|
||||
->addOption('--expire-time', $this->getExpireTime())
|
||||
->addArgument($this->getTitle($envelope))
|
||||
->addArgument($envelope->getMessage())
|
||||
|
||||
@@ -15,7 +15,7 @@ final class SnoreToastNotifier extends AbstractNotifier
|
||||
$cmd
|
||||
->addOption('-m', $envelope->getMessage())
|
||||
->addOption('-t', $this->getTitle($envelope))
|
||||
->addOption('-p', $this->getIcon($envelope->getType()))
|
||||
->addOption('-p', $this->getIcon($envelope))
|
||||
;
|
||||
|
||||
$cmd->run();
|
||||
@@ -23,7 +23,11 @@ final class SnoreToastNotifier extends AbstractNotifier
|
||||
|
||||
public function isSupported()
|
||||
{
|
||||
return $this->isEnabled() && OS::isWindows() && $this->getProgram();
|
||||
if (!$this->getProgram() || !$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux();
|
||||
}
|
||||
|
||||
public function configureOptions(array $options)
|
||||
|
||||
@@ -15,9 +15,17 @@ final class TerminalNotifierNotifier extends AbstractNotifier
|
||||
$cmd
|
||||
->addOption('-message', $envelope->getMessage())
|
||||
->addOption('-title', $this->getTitle($envelope))
|
||||
->addOption('-appIcon', $this->getIcon($envelope->getType()))
|
||||
;
|
||||
|
||||
if (version_compare(OS::getMacOSVersion(), '10.9.0', '>=')) {
|
||||
$cmd->addOption('-appIcon', $this->getIcon($envelope));
|
||||
}
|
||||
|
||||
$url = $envelope->getOption('url');
|
||||
if ($url) {
|
||||
$cmd->addOption('-open', $url);
|
||||
}
|
||||
|
||||
$cmd->run();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ final class ToasterNotifier extends AbstractNotifier
|
||||
$cmd
|
||||
->addOption('-m', $envelope->getMessage())
|
||||
->addOption('-t', $this->getTitle($envelope))
|
||||
->addOption('-p', $this->getIcon($envelope->getType()))
|
||||
->addOption('-p', $this->getIcon($envelope))
|
||||
;
|
||||
|
||||
$cmd->run();
|
||||
@@ -23,7 +23,11 @@ final class ToasterNotifier extends AbstractNotifier
|
||||
|
||||
public function isSupported()
|
||||
{
|
||||
return $this->isEnabled() && OS::isWindows() && $this->getProgram();
|
||||
if (!$this->getProgram() || !$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux();
|
||||
}
|
||||
|
||||
public function configureOptions(array $options)
|
||||
|
||||
@@ -50,4 +50,13 @@ class OS
|
||||
{
|
||||
return false !== strpos(self::getName(), 'Darwin');
|
||||
}
|
||||
|
||||
public static function getMacOSVersion()
|
||||
{
|
||||
$cmd = new Command('sw_vers');
|
||||
$cmd->addArgument('-productVersion');
|
||||
$cmd->run();
|
||||
|
||||
return trim($cmd->getOutput());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user