Add Notification Storage handler that uses Horde_Session
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 14 Oct 2010 17:43:02 +0000 (11:43 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 15 Oct 2010 16:37:59 +0000 (10:37 -0600)
framework/Core/lib/Horde/Core/Factory/Notification.php
framework/Core/lib/Horde/Core/Notification/Storage/Session.php [new file with mode: 0644]
framework/Core/lib/Horde/Session.php
framework/Core/package.xml

index 1295f6c..6c46b50 100644 (file)
@@ -7,7 +7,9 @@ class Horde_Core_Factory_Notification
 {
     public function create(Horde_Injector $injector)
     {
-        $notify = Horde_Notification::singleton();
+        $notify = new Horde_Notification_Handler(
+            new Horde_Core_Notification_Storage_Session()
+        );
 
         $notify->addType('default', '*', 'Horde_Core_Notification_Status');
         $notify->addType('status', 'horde.*', 'Horde_Core_Notification_Status');
diff --git a/framework/Core/lib/Horde/Core/Notification/Storage/Session.php b/framework/Core/lib/Horde/Core/Notification/Storage/Session.php
new file mode 100644 (file)
index 0000000..1af241f
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * A class that stores notifications in the session, using Horde_Session.
+ *
+ * @author   Michael Slusarz <slusarz@curecanti.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Core
+ * @package  Core
+ */
+
+/**
+ * A class that stores notifications in the session, using Horde_Session.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@curecanti.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Core
+ * @package  Core
+ */
+class Horde_Core_Notification_Storage_Session
+implements Horde_Notification_Storage_Interface
+{
+    /**
+     */
+    public function get($key)
+    {
+        return $GLOBALS['session']['horde:notify/' . $key];
+    }
+
+    /**
+     */
+    public function set($key, $value)
+    {
+        $GLOBALS['session']['horde:notify/' . $key] = $value;
+    }
+
+    /**
+     */
+    public function exists($key)
+    {
+        return isset($GLOBALS['session']['horde:notify/' . $key]);
+    }
+
+    /**
+     */
+    public function clear($key)
+    {
+        unset($GLOBALS['session']['horde:notify/' . $key]);
+    }
+
+    /**
+     */
+    public function push($listener, Horde_Notification_Event $event)
+    {
+        global $session;
+
+        $events = $session['horde:notify/' . $listener . ';array'];
+        $events[] = $event;
+        $session['horde:notify/' . $listener . ';object'] = $events;
+    }
+
+}
index 0983bc2..4995c75 100644 (file)
@@ -333,13 +333,13 @@ class Horde_Session implements ArrayAccess
          * given page load.  Thus, for arrays ans objects, it is beneficial to
          * always convert to string representations so that the object/array
          * does not need to be rebuilt every time the session is reloaded. */
-        if (is_object($value)) {
+        if (is_object($value) || ($ob->type == 'object')) {
             $value = serialize($value);
             if ($this->_lzf) {
                 $value = lzf_compress($value);
             }
             $_SESSION[self::SERIALIZED][$ob->key] = 's';
-        } elseif (is_array($value)) {
+        } elseif (is_array($value) || ($ob->type == 'array')) {
             $value = json_encode($value);
             if ($this->_lzf) {
                 $value = lzf_compress($value);
index b896d95..e25bafb 100644 (file)
@@ -174,6 +174,9 @@ Application Framework.</description>
        </dir> <!-- /lib/Horde/Core/Mime/Viewer -->
       </dir> <!-- /lib/Horde/Core/Mime -->
       <dir name="Notification">
+       <dir name="Storage">
+        <file name="Session.php" role="php" />
+       </dir> <!-- /lib/Horde/Core/Notification/Storage -->
        <file name="Hordelog.php" role="php" />
        <file name="Status.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Notification -->
@@ -471,6 +474,7 @@ Application Framework.</description>
    <install as="Horde/Core/LoginTasks/Backend/Horde.php" name="lib/Horde/Core/LoginTasks/Backend/Horde.php" />
    <install as="Horde/Core/Mime/Viewer/Syntaxhighlighter.php" name="lib/Horde/Core/Mime/Viewer/Syntaxhighlighter.php" />
    <install as="Horde/Core/Mime/Viewer/Vcard.php" name="lib/Horde/Core/Mime/Viewer/Vcard.php" />
+   <install as="Horde/Core/Notification/Storage/Session.php" name="lib/Horde/Core/Notification/Storage/Session.php" />
    <install as="Horde/Core/Notification/Hordelog.php" name="lib/Horde/Core/Notification/Hordelog.php" />
    <install as="Horde/Core/Notification/Status.php" name="lib/Horde/Core/Notification/Status.php" />
    <install as="Horde/Core/Perms/Ui.php" name="lib/Horde/Core/Perms/Ui.php" />