aboutsummaryrefslogtreecommitdiff
path: root/src/callnotifier/Log.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-07-26 07:49:09 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-07-26 07:49:09 +0200
commitb618b8360a69ada6b0ca412d5d15d7ec1edb9e82 (patch)
tree56f51cc63a62fc106633d7b4bde1ef3e41e80041 /src/callnotifier/Log.php
parente60135e26ab4b374642f6f9293ddcac26adcacc8 (diff)
downloadauerswald-callnotifier-b618b8360a69ada6b0ca412d5d15d7ec1edb9e82.tar.gz
auerswald-callnotifier-b618b8360a69ada6b0ca412d5d15d7ec1edb9e82.zip
introduce separate log object and callmonitor
Diffstat (limited to 'src/callnotifier/Log.php')
-rw-r--r--src/callnotifier/Log.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/callnotifier/Log.php b/src/callnotifier/Log.php
new file mode 100644
index 0000000..9f7a654
--- /dev/null
+++ b/src/callnotifier/Log.php
@@ -0,0 +1,57 @@
+<?php
+namespace callnotifier;
+
+class Log
+{
+ /**
+ * Array of logger object arrays.
+ * Key is the notification type, value is an array of logger objects
+ * that want to get notified about the type.
+ *
+ * @var array
+ */
+ protected $logger = array(
+ 'msgData' => array(),
+ 'edss1msg' => array(),
+ );
+
+ /**
+ * Add a logger
+ *
+ * @param Logger $logger Logger object to register
+ * @param array|string $types Single notification type or array of such
+ * types. "*" means "register for all types".
+ *
+ * @return self
+ */
+ public function addLogger(Logger $logger, $types)
+ {
+ if ($types == '*') {
+ $types = array_keys($this->logger);
+ }
+ $types = (array)$types;
+
+ foreach ($types as $type) {
+ if (!isset($this->logger[$type])) {
+ throw new \Exception('Unknown log type: ' . $type);
+ }
+ $this->logger[$type][] = $logger;
+ }
+ }
+
+ public function log($type, $arData)
+ {
+ if (!isset($this->logger[$type])) {
+ throw new \Exception('Unknown log type: ' . $type);
+ }
+
+ if (count($this->logger[$type])) {
+ foreach ($this->logger[$type] as $logger) {
+ $logger->log($type, $arData);
+ }
+ }
+ }
+
+}
+
+?>