1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
<?php
/**
* Utilise notify-send from within Phing.
*
* PHP Version 5
*
* @category Tasks
* @package phing.tasks.ext
* @author Ken Guest <ken@linux.ie>
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html)
* @link https://github.com/kenguest/Phing-NotifySendTask
*/
require_once 'phing/Task.php';
/**
* NotifySendTask
*
* @category Tasks
* @package phing.tasks.ext
* @author Ken Guest <ken@linux.ie>
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html)
* @link NotifySendTask.php
*/
class NotifySendTask extends Task
{
protected $msg = null;
protected $title = null;
protected $icon = 'info';
protected $silent = false;
/**
* Set icon attribute
*
* @param string $icon name/location of icon
*
* @return void
*/
public function setIcon($icon)
{
switch ($icon)
{
case 'info':
case 'error':
case 'warning':
$this->icon = $icon;
break;
default:
if (file_exists($icon) && is_file($icon)) {
$this->icon = $icon;
} else {
if (isset($this->log)) {
$this->log(
sprintf(
"%s is not a file. Using default icon instead.",
$icon
),
Project::MSG_WARN
);
}
}
}
}
/**
* Get icon to be used (filename or generic name)
*
* @return string
*/
public function getIcon()
{
return $this->icon;
}
/**
* Set to a true value to not execute notifysend command.
*
* @param bool $silent Don't execute notifysend? True not to.
*
* @return void
*/
public function setSilent($silent)
{
$this->silent = (bool) $silent;
}
/**
* Set title attribute
*
* @param string $title Title to display
*
* @return void
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get Title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set msg attribute
*
* @param string $msg Message
*
* @return void
*/
public function setMsg($msg)
{
$this->msg = $msg;
}
/**
* Get message.
*
* @return string
*/
public function getMsg()
{
return $this->msg;
}
/**
* The main entry point method.
*
* @throws BuildException
* @return void
*/
public function main()
{
$msg = '';
$title = 'Phing';
if ($this->title != '') {
$title = "'" . $this->title . "'";
}
if ($this->msg != '') {
$msg = "'" . $this->msg . "'";
}
$cmd = 'notify-send -i ' . $this->icon . ' ' . $title . ' ' . $msg;
$this->log(sprintf("cmd: %s", $cmd), Project::MSG_DEBUG);
if (!$this->silent) {
exec(escapeshellcmd($cmd), $output, $return);
if ($return !== 0) {
throw new BuildException("Notify task failed.");
}
}
$this->log(sprintf("Title: '%s'", $title), Project::MSG_DEBUG);
$this->log(sprintf("Message: '%s'", $msg), Project::MSG_DEBUG);
$this->log($msg, Project::MSG_INFO);
}
}
// vim:set et ts=4 sw=4:
|