[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: JobHook: add new helper methods, accept Definition

git at icinga.org git at icinga.org
Tue Jun 7 15:59:13 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: f32d5a646b633644a2f3cc38a8e3e0c43b5d102f
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=f32d5a646b633644a2f3cc38a8e3e0c43b5d102f

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed May 25 11:48:45 2016 +0200

JobHook: add new helper methods, accept Definition

---

 library/Director/Hook/JobHook.php |   51 +++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/library/Director/Hook/JobHook.php b/library/Director/Hook/JobHook.php
index fbed18a..b4ccf14 100644
--- a/library/Director/Hook/JobHook.php
+++ b/library/Director/Hook/JobHook.php
@@ -2,13 +2,23 @@
 
 namespace Icinga\Module\Director\Hook;
 
+use Icinga\Application\Icinga;
 use Icinga\Module\Director\Db;
+use Icinga\Module\Director\Objects\DirectorJob;
 use Icinga\Module\Director\Web\Form\QuickForm;
 
 abstract class JobHook
 {
     private $db;
 
+    private $output   = array();
+
+    private $warnings = array();
+
+    private $errors   = array();
+
+    private $jobDefinition;
+
     public static function getDescription(QuickForm $form)
     {
         return false;
@@ -21,6 +31,17 @@ abstract class JobHook
         // TODO: Can be overridden, double-check whether this is necessary
     }
 
+    public function setDefinition(DirectorJob $definition)
+    {
+        $this->jobDefinition = $definition;
+        return $this;
+    }
+
+    protected function getSetting($key, $default = null)
+    {
+        return $this->jobDefinition->getSetting($key, $default);
+    }
+
     public function getName()
     {
         $parts = explode('\\', get_class($this));
@@ -63,5 +84,35 @@ abstract class JobHook
         return $this->db;
     }
 
+    protected function output($message)
+    {
+        $this->output[] = $message;
+        return $this;
+    }
+
+    /**
+     * printf helper method
+     *
+     * @param  string $message Format string
+     * @param  mixed  ...$arg  Format string argument
+     *
+     * @return self
+     */
+    protected function printf($message)
+    {
+        $args = array_slice(func_get_args(), 1);
+        return $this->output(vsprintf($message, $args));
+    }
+
+    protected function warning($message)
+    {
+        $this->warnings[] = $message;
+        return $this;
+    }
 
+    protected function error($message)
+    {
+        $this->errors[] = $message;
+        return $this;
+    }
 }



More information about the icinga-checkins mailing list