Permalink
Browse files

added HoustonNotifier

  • Loading branch information...
1 parent 7f3eb67 commit 9990bc1fd9e93d295c7f75fd02eeba37a110d5d3 Andreas Hucks committed Mar 20, 2012
Showing with 56 additions and 0 deletions.
  1. BIN data/houston.wav
  2. +56 −0 src/Duochrome/Sismo/HoustonNotifier.php
View
Binary file not shown.
@@ -0,0 +1,56 @@
+<?php
+
+namespace Duochrome\Sismo;
+
+use Symfony\Component\Process\Process;
+use Sismo\Notifier;
+use Sismo\Commit;
+
+class HoustonNotifier extends Notifier
+{
+ const SOUND_DEFAULT = 'houston.wav';
+
+ private $soundFail;
+ private $soundSuccess;
+ private $volume;
+
+ public function __construct($soundFail = 'houston.wav', $soundSuccess = null, $volume = 1)
+ {
+ $this->soundFail = (string) $soundFail;
+ $this->soundSuccess = (string) $soundSuccess;
+ $this->volume = (float) $volume;
+
+ if (self::SOUND_DEFAULT === $this->soundFail) {
+ $this->soundFail = __DIR__ . '/../../../data/houston.wav';
+ }
+
+ if ($this->volume > 1) {
+ $this->volume = 1;
+ }
+
+ if ($this->volume < 0) {
+ $this->volume = 0;
+ }
+ }
+
+ public function notify(Commit $commit)
+ {
+ if (!$commit->isSuccessful() && null !== $this->soundFail) {
+ $this->play($this->soundFail);
+ } elseif ($commit->isSuccessful() && null !== $this->soundSuccess) {
+ $this->play($this->soundSuccess);
+ }
+ }
+
+ protected function play($file)
+ {
+ if (!file_exists($file)) {
+ throw new \InvalidArgumentException(sprintf('Soundfile %s could not be found.'), $file);
+ }
+
+ $p = new Process(sprintf('afplay "%s" --volume %s', $file, $this->volume));
+ $p->setTimeout(30);
+
+ $p->run();
+ }
+}

0 comments on commit 9990bc1

Please sign in to comment.