Remove Core dependency in horde/LoginTasks
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 May 2010 20:25:17 +0000 (14:25 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 19 May 2010 05:12:50 +0000 (23:12 -0600)
Framework libs other than Core must contain NO horde dependencies, even
if they are optional.

For testing: unit tests in the framework libraries should only test whether
the code contained in the library works. If we want to test things
dependent on Horde (the application), these tests should be in Core.

13 files changed:
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Core/Binder/LoginTasks.php [new file with mode: 0644]
framework/Core/lib/Horde/Core/Factory/LoginTasks.php [new file with mode: 0644]
framework/Core/lib/Horde/Core/LoginTasks/Backend/Horde.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml
framework/LoginTasks/lib/Horde/LoginTasks.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php [deleted file]
framework/LoginTasks/package.xml
framework/LoginTasks/test/Horde/LoginTasks/LoginTasksTest.php
framework/LoginTasks/test/Horde/LoginTasks/Stubs.php
horde/services/logintasks.php

index dc1f655..fae5115 100644 (file)
@@ -442,7 +442,7 @@ HTML;
      * @param string $type       The service to display.
      * <pre>
      * TODO
-     * 'ajax', 'cache', 'download', 'go', 'prefsapi'
+     * 'ajax', 'cache', 'download', 'go', 'logintasks', 'prefsapi'
      * 'help', 'problem', 'logout', 'login', 'options'
      * </pre>
      * @param string $app        The name of the current Horde application.
@@ -467,6 +467,9 @@ HTML;
         case 'login':
             return self::url($webroot . '/login.php');
 
+        case 'logintasks':
+            return self::url($webroot . '/services/logintasks.php')->add('app', $app);
+
         case 'options':
         case 'prefsapi':
             if (!in_array($GLOBALS['conf']['prefs']['driver'], array('', 'none'))) {
diff --git a/framework/Core/lib/Horde/Core/Binder/LoginTasks.php b/framework/Core/lib/Horde/Core/Binder/LoginTasks.php
new file mode 100644 (file)
index 0000000..304d8fd
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+/**
+ * @category Horde
+ * @package  Core
+ */
+class Horde_Core_Binder_LoginTasks implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        return new Horde_Core_Factory_LoginTasks($injector);
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+}
diff --git a/framework/Core/lib/Horde/Core/Factory/LoginTasks.php b/framework/Core/lib/Horde/Core/Factory/LoginTasks.php
new file mode 100644 (file)
index 0000000..3ee2e4e
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * A Horde_Injector:: based Horde_LoginTasks:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Core
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Core
+ */
+
+/**
+ * A Horde_Injector:: based Horde_LoginTasks:: factory.
+ *
+ * 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.
+ *
+ * @category Horde
+ * @package  Core
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Core
+ */
+class Horde_Core_Factory_LoginTasks
+{
+    /**
+     * Instances.
+     *
+     * @var array
+     */
+    private $_instances = array();
+
+    /**
+     * The injector.
+     *
+     * @var Horde_Injector
+     */
+    private $_injector;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Injector $injector  The injector to use.
+     */
+    public function __construct(Horde_Injector $injector)
+    {
+        $this->_injector = $injector;
+    }
+
+    /**
+     * Return the Horde_LoginTasks:: instance.
+     *
+     * @param string $app  The current application.
+     *
+     * @return Horde_LoginTasks  The singleton instance.
+     */
+    public function getOb($app)
+    {
+        if (!isset($this->_instances[$app])) {
+            $this->_instances[$app] = new Horde_LoginTasks(new Horde_Core_LoginTasks_Backend_Horde($app));
+        }
+
+        return $this->_instances[$app];
+    }
+
+}
diff --git a/framework/Core/lib/Horde/Core/LoginTasks/Backend/Horde.php b/framework/Core/lib/Horde/Core/LoginTasks/Backend/Horde.php
new file mode 100644 (file)
index 0000000..816608a
--- /dev/null
@@ -0,0 +1,172 @@
+<?php
+/**
+ * This class provides the Horde specific implementation of the LoginTasks
+ * backend.
+ *
+ * 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@horde.org>
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @category Horde
+ * @package  Core
+ */
+class Horde_Core_LoginTasks_Backend_Horde extends Horde_LoginTasks_Backend
+{
+    /**
+     * The Horde application that is currently active.
+     *
+     * @var string
+     */
+    private $_app;
+
+    /**
+     * Constructor.
+     *
+     * @param string $app  The currently active Horde application.
+     */
+    public function __construct($app)
+    {
+        $this->_app = $app;
+    }
+
+    /**
+     * Is the current session authenticated?
+     *
+     * @return boolean True if the user is authenticated, false otherwise.
+     */
+    public function isAuthenticated()
+    {
+        return (Horde_Auth::getAuth() !== false);
+    }
+
+    /**
+     * Retrieve a cached tasklist if it exists.
+     *
+     * @return Horde_LoginTasks_Tasklist|boolean  The cached task list or
+     *                                            false if no task list was
+     *                                            cached.
+     */
+    public function getTasklistFromCache()
+    {
+        if (isset($_SESSION['horde_logintasks'][$this->_app])) {
+            return @unserialize($_SESSION['horde_logintasks'][$this->_app]);
+        }
+        return false;
+    }
+
+    /**
+     * Store a login tasklist in the cache.
+     *
+     * @param Horde_LoginTasks_Tasklist|boolean $tasklist  The tasklist to be
+     *                                                     stored.
+     */
+    public function storeTasklistInCache($tasklist)
+    {
+        $_SESSION['horde_logintasks'][$this->_app] = serialize($tasklist);
+    }
+
+    /**
+     * Register the shutdown handler.
+     *
+     * @param array $shutdown  The shutdown function.
+     */
+    public function registerShutdown($shutdown)
+    {
+        register_shutdown_function($shutdown);
+    }
+
+    /**
+     * Get the class names of the task classes that need to be performed.
+     *
+     * @return array  An array of class names.
+     */
+    public function getTasks()
+    {
+        /* Add Horde tasks here if not yet run. */
+        $app_list = array($this->_app);
+        if (($this->_app != 'horde') &&
+            !isset($_SESSION['horde_logintasks']['horde'])) {
+            array_unshift($app_list, 'horde');
+        }
+
+        $tasks = array();
+
+        foreach ($app_list as $app) {
+            foreach (array_merge($GLOBALS['registry']->getAppDrivers($app, 'LoginTasks_SystemTask'), $GLOBALS['registry']->getAppDrivers($app, 'LoginTasks_Task')) as $val) {
+                $tasks[$val] = $app;
+            }
+        }
+
+        return $tasks;
+    }
+
+    /**
+     * Get the information about the last time the tasks were run. Array keys
+     * are app names, values are last run timestamps. Special key '_once'
+     * contains list of ONCE tasks previously run.
+     *
+     * @return array  The information about the last time the tasks were run.
+     */
+    public function getLastRun()
+    {
+        $lasttask_pref = @unserialize($GLOBALS['prefs']->getValue('last_logintasks'));
+        if (!is_array($lasttask_pref)) {
+            $lasttask_pref = array();
+        }
+
+        return $lasttask_pref;
+    }
+
+    /**
+     * Store the information about the last time the tasks were run.
+     *
+     * @param array $last  The information about the last time the tasks were
+     *                     run.
+     */
+    public function setLastRun(array $last)
+    {
+        $GLOBALS['prefs']->setValue('last_logintasks', serialize($last));
+    }
+
+    /**
+     * Mark the current time as time the login tasks were run for the last
+     * time.
+     */
+    public function markLastRun()
+    {
+        $lasttasks = $this->getLastRun();
+        $lasttasks[$this->_app] = time();
+        if (($this->_app != 'horde') &&
+            !isset($_SESSION['horde_logintasks']['horde'])) {
+            $lasttasks['horde'] = time();
+            $_SESSION['horde_logintasks']['horde'] = true;
+        }
+        $GLOBALS['prefs']->setValue('last_logintasks', serialize($lasttasks));
+    }
+
+    /**
+     * Redirect to the given URL.
+     *
+     * @param string $url  The URL to redirect to.
+     */
+    public function redirect($url)
+    {
+        header('Location: ' . $url);
+        exit;
+    }
+
+    /**
+     * Return the URL of the login tasks view.
+     *
+     * @param array $tasks  The tasks to be displayed next.
+     *
+     * @return string  The URL of the login tasks view.
+     */
+    public function getLoginTasksUrl(array $tasks = null)
+    {
+        return Horde::getServiceLink('logintasks', $this->_app);
+    }
+}
index 7014dca..77aa287 100644 (file)
@@ -240,6 +240,7 @@ class Horde_Registry
             'Horde_History' => new Horde_Core_Binder_History(),
             'Horde_Lock' => new Horde_Core_Binder_Lock(),
             'Horde_Log_Logger' => new Horde_Core_Binder_Logger(),
+            'Horde_LoginTasks' => new Horde_Core_Binder_LoginTasks(),
             'Horde_Mail' => new Horde_Core_Binder_Mail(),
             'Horde_Memcache' => new Horde_Core_Binder_Memcache(),
             'Horde_Notification' => new Horde_Core_Binder_Notification(),
@@ -1131,7 +1132,7 @@ class Horde_Registry
 
         /* Do login tasks. */
         if ($checkPerms) {
-            $tasks = Horde_LoginTasks::singleton($app);
+            $tasks = $GLOBALS['injector']->getInstance('Horde_LoginTasks')->getOb($app);
             if (!empty($options['logintasks'])) {
                 $tasks->runTasks(false, Horde::selfUrl(true, true, true));
             }
index 0239c9a..17cb7c8 100644 (file)
@@ -37,7 +37,8 @@ Application Framework.
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Import perms UI handling class from horde/Perms.
+ <notes>* Import Horde backend driver from horde/LoginTasks.
+ * Import perms UI handling class from horde/Perms.
  * Import prefs UI handling class from horde/Prefs.
  * Convert from PEAR Log to Horde_Log for logging.
  * Add Horde_Themes:: class.
@@ -77,6 +78,7 @@ Application Framework.
        <file name="Identity.php" role="php" />
        <file name="Lock.php" role="php" />
        <file name="Logger.php" role="php" />
+       <file name="LoginTasks.php" role="php" />
        <file name="Mail.php" role="php" />
        <file name="Memcache.php" role="php" />
        <file name="Notification.php" role="php" />
@@ -96,10 +98,16 @@ Application Framework.
        <file name="KolabServer.php" role="php" />
        <file name="KolabSession.php" role="php" />
        <file name="KolabStorage.php" role="php" />
+       <file name="LoginTasks.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Factory -->
       <dir name="Log">
        <file name="Logger.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Log -->
+      <dir name="LoginTasks">
+       <dir name="Backend">
+        <file name="Horde.php" role="php" />
+       </dir> <!-- /lib/Horde/Core/LoginTasks/Backend -->
+      </dir> <!-- /lib/Horde/Core/LoginTasks -->
       <dir name="Notification">
        <file name="Hordelog.php" role="php" />
        <file name="Status.php" role="php" />
@@ -183,6 +191,10 @@ Application Framework.
     <channel>pear.horde.org</channel>
    </package>
    <package>
+    <name>LoginTasks</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
     <name>Prefs</name>
     <channel>pear.horde.org</channel>
    </package>
@@ -239,6 +251,7 @@ Application Framework.
    <install name="lib/Horde/Core/Binder/Identity.php" as="Horde/Core/Binder/Identity.php" />
    <install name="lib/Horde/Core/Binder/Lock.php" as="Horde/Core/Binder/Lock.php" />
    <install name="lib/Horde/Core/Binder/Logger.php" as="Horde/Core/Binder/Logger.php" />
+   <install name="lib/Horde/Core/Binder/LoginTasks.php" as="Horde/Core/Binder/LoginTasks.php" />
    <install name="lib/Horde/Core/Binder/Mail.php" as="Horde/Core/Binder/Mail.php" />
    <install name="lib/Horde/Core/Binder/Memcache.php" as="Horde/Core/Binder/Memcache.php" />
    <install name="lib/Horde/Core/Binder/Notification.php" as="Horde/Core/Binder/Notification.php" />
@@ -256,7 +269,9 @@ Application Framework.
    <install name="lib/Horde/Core/Factory/KolabServer.php" as="Horde/Core/Factory/KolabServer.php" />
    <install name="lib/Horde/Core/Factory/KolabSession.php" as="Horde/Core/Factory/KolabSession.php" />
    <install name="lib/Horde/Core/Factory/KolabStorage.php" as="Horde/Core/Factory/KolabStorage.php" />
+   <install name="lib/Horde/Core/Factory/LoginTasks.php" as="Horde/Core/Factory/LoginTasks.php" />
    <install name="lib/Horde/Core/Log/Logger.php" as="Horde/Core/Log/Logger.php" />
+   <install name="lib/Horde/Core/LoginTasks/Backend/Horde.php" as="Horde/Core/LoginTasks/Backend/Horde.php" />
    <install name="lib/Horde/Core/Notification/Hordelog.php" as="Horde/Core/Notification/Hordelog.php" />
    <install name="lib/Horde/Core/Notification/Status.php" as="Horde/Core/Notification/Status.php" />
    <install name="lib/Horde/Core/Perms/Ui.php" as="Horde/Core/Perms/Ui.php" />
index a28b963..79e0932 100644 (file)
@@ -41,13 +41,6 @@ class Horde_LoginTasks
     const PRIORITY_NORMAL = 2;
 
     /**
-     * Singleton instance.
-     *
-     * @var array
-     */
-    static protected $_instances = array();
-
-    /**
      * The Horde_LoginTasks_Backend object provides all utilities we need for
      * handling the login tasks.
      *
@@ -63,36 +56,9 @@ class Horde_LoginTasks
     protected $_tasklist;
 
     /**
-     * Attempts to return a reference to a concrete Horde_LoginTasks
-     * instance based on $app. It will only create a new instance
-     * if no instance with the same parameters currently exists.
-     *
-     * This method must be invoked as:
-     *   $var = Horde_LoginTasks::singleton($app[, $params]);
-     *
-     * @param string $app  See self::__construct().
-     *
-     * @return Horde_LoginTasks  The singleton instance.
-     */
-    static public function singleton($app)
-    {
-        if (empty(self::$_instances[$app])) {
-            self::$_instances[$app] = new self(
-                new Horde_LoginTasks_Backend_Horde(
-                    $GLOBALS['registry'],
-                    $GLOBALS['prefs'],
-                    $app
-                )
-            );
-        }
-
-        return self::$_instances[$app];
-    }
-
-    /**
      * Constructor.
      *
-     * @param string $app  The name of the Horde application.
+     * @param Horde_LoginTasks_Backend $backend  The backend to use.
      */
     public function __construct(Horde_LoginTasks_Backend $backend)
     {
index 3fa7c8b..363a3bc 100644 (file)
@@ -18,40 +18,38 @@ abstract class Horde_LoginTasks_Backend
     /**
      * Is the current session authenticated?
      *
-     * @return boolean True if the user is authenticated, false otherwise.
+     * @return boolean  True if the user is authenticated, false otherwise.
      */
     abstract public function isAuthenticated();
 
     /**
      * Retrieve a cached tasklist if it exists.
      *
-     * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false
-     * if no task list was cached.
+     * @return Horde_LoginTasks_Tasklist|boolean  The cached task list or
+     *                                            false if no task list was
+     *                                            cached.
      */
     abstract public function getTasklistFromCache();
 
     /**
      * Store a login tasklist in the cache.
      *
-     * @param Horde_LoginTasks_Tasklist|boolean The tasklist to be stored.
-     *
-     * @return NULL
+     * @param Horde_LoginTasks_Tasklist|boolean $tasklist  The tasklist to be
+     *                                                     stored.
      */
     abstract public function storeTasklistInCache($tasklist);
 
     /**
      * Register the shutdown handler.
      *
-     * @param array The shutdown function
-     *
-     * @return NULL
+     * @param array $shutdown  The shutdown function.
      */
     abstract public function registerShutdown($shutdown);
 
     /**
      * Get the class names of the task classes that need to be performed.
      *
-     * @return array An array of class names.
+     * @return array  An array of class names.
      */
     abstract public function getTasks();
 
@@ -60,41 +58,37 @@ abstract class Horde_LoginTasks_Backend
      * are app names, values are last run timestamps. Special key '_once'
      * contains list of ONCE tasks previously run.
      *
-     * @return array The information about the last time the tasks were run.
+     * @return array  The information about the last time the tasks were run.
      */
     abstract public function getLastRun();
 
     /**
      * Store the information about the last time the tasks were run.
      *
-     * @param array $last The information about the last time the tasks were run.
-     *
-     * @return NULL
+     * @param array $last  The information about the last time the tasks were
+     *                     run.
      */
     abstract public function setLastRun(array $last);
 
     /**
-     * Mark the current time as time the login tasks were run for the last time.
-     *
-     * @return NULL
+     * Mark the current time as time the login tasks were run for the last
+     * time.
      */
     abstract public function markLastRun();
 
     /**
      * Redirect to the given URL.
      *
-     * @param string $url The URL to redirect to.
-     *
-     * @return NULL
+     * @param string $url  The URL to redirect to.
      */
     abstract public function redirect($url);
 
     /**
      * Return the URL of the login tasks view.
      *
-     * @param array $tasks The tasks to be displayed next.
+     * @param array $tasks  The tasks to be displayed next.
      *
-     * @return string The URL of the login tasks view
+     * @return string  The URL of the login tasks view
      */
     abstract public function getLoginTasksUrl(array $tasks = null);
-}
\ No newline at end of file
+}
diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php b/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php
deleted file mode 100644 (file)
index 1ec6eee..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-<?php
-/**
- * The Horde_LoginTasks_Backend_Horde:: class provides the Horde specific
- * implementation of the LoginTasks backend
- *
- * Copyright 2001-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@horde.org>
- * @author  Gunnar Wrobel <wrobel@pardus.de>
- * @package Horde_LoginTasks
- */
-class Horde_LoginTasks_Backend_Horde
-extends Horde_LoginTasks_Backend
-{
-    /**
-     * The Horde application that is currently active.
-     *
-     * @var string
-     */
-    private $_app;
-
-    /**
-     * The Horde registry.
-     *
-     * @var Horde_Registry
-     */
-    private $_registry;
-
-    /**
-     * The Horde preferences system
-     *
-     * @var Horde_Prefs
-     */
-    private $_prefs;
-
-    /**
-     * Constructor
-     *
-     * @param string $app The Horde application that is currently active.
-     */
-    public function __construct(
-        Horde_Registry $registry,
-        Horde_Prefs    $prefs,
-        $app
-    ) {
-        $this->_registry = $registry;
-        $this->_prefs    = $prefs;
-        $this->_app      = $app;
-    }
-    
-    /**
-     * Is the current session authenticated?
-     *
-     * @return boolean True if the user is authenticated, false otherwise.
-     */
-    public function isAuthenticated()
-    {
-        return (Horde_Auth::getAuth() !== false);
-    }
-
-    /**
-     * Retrieve a cached tasklist if it exists.
-     *
-     * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false
-     * if no task list was cached.
-     */
-    public function getTasklistFromCache()
-    {
-        if (isset($_SESSION['horde_logintasks'][$this->_app])) {
-            return @unserialize($_SESSION['horde_logintasks'][$this->_app]);
-        }
-        return false;
-    }
-
-    /**
-     * Store a login tasklist in the cache.
-     *
-     * @param Horde_LoginTasks_Tasklist|boolean The tasklist to be stored.
-     *
-     * @return NULL
-     */
-    public function storeTasklistInCache($tasklist)
-    {
-        $_SESSION['horde_logintasks'][$this->_app] = serialize($tasklist);
-    }
-
-    /**
-     * Register the shutdown handler.
-     *
-     * @param array The shutdown function
-     *
-     * @return NULL
-     */
-    public function registerShutdown($shutdown)
-    {
-        register_shutdown_function($shutdown);
-    }
-
-    /**
-     * Get the class names of the task classes that need to be performed.
-     *
-     * @return array An array of class names.
-     */
-    public function getTasks()
-    {
-        /* Add Horde tasks here if not yet run. */
-        $app_list = array($this->_app);
-        if (($this->_app != 'horde') &&
-            !isset($_SESSION['horde_logintasks']['horde'])) {
-            array_unshift($app_list, 'horde');
-        }
-
-        $tasks = array();
-
-        foreach ($app_list as $app) {
-            foreach (array_merge($this->_registry->getAppDrivers($app, 'LoginTasks_SystemTask'), $this->_registry->getAppDrivers($app, 'LoginTasks_Task')) as $val) {
-                $tasks[$val] = $app;
-            }
-        }
-        return $tasks;
-    }
-
-    /**
-     * Get the information about the last time the tasks were run. Array keys
-     * are app names, values are last run timestamps. Special key '_once'
-     * contains list of ONCE tasks previously run.
-     *
-     * @return array The information about the last time the tasks were run.
-     */
-    public function getLastRun()
-    {
-        $lasttask_pref = @unserialize($this->_prefs->getValue('last_logintasks'));
-        if (!is_array($lasttask_pref)) {
-            $lasttask_pref = array();
-        }
-        return $lasttask_pref;
-    }
-
-    /**
-     * Store the information about the last time the tasks were run.
-     *
-     * @param array $last The information about the last time the tasks were run.
-     *
-     * @return NULL
-     */
-    public function setLastRun(array $last)
-    {
-        $this->_prefs->setValue('last_logintasks', serialize($last));
-    }
-
-    /**
-     * Mark the current time as time the login tasks were run for the last time.
-     *
-     * @return NULL
-     */
-    public function markLastRun()
-    {
-        $lasttasks = $this->getLastRun();
-        $lasttasks[$this->_app] = time();
-        if (($this->_app != 'horde') &&
-            !isset($_SESSION['horde_logintasks']['horde'])) {
-            $lasttasks['horde'] = time();
-            $_SESSION['horde_logintasks']['horde'] = true;
-        }
-        $this->_prefs->setValue('last_logintasks', serialize($lasttasks));
-    }
-
-    /**
-     * Redirect to the given URL.
-     *
-     * @param string $url The URL to redirect to.
-     *
-     * @return NULL
-     */
-    public function redirect($url)
-    {
-        header('Location: ' . $url);
-        exit;
-    }
-
-    /**
-     * Return the URL of the login tasks view.
-     *
-     * @param array $tasks The tasks to be displayed next.
-     *
-     * @return string The URL of the login tasks view
-     */
-    public function getLoginTasksUrl(array $tasks = null)
-    {
-        return Horde::url(Horde_Util::addParameter($this->_registry->get('webroot', 'horde') . '/services/logintasks.php', array('app' => $this->_app)), true);
-    }
-}
\ No newline at end of file
index 646980c..ba58dab 100644 (file)
@@ -21,8 +21,8 @@
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
-* Added system tasks.
+ <notes>* Removed Core dependency.
+ * Added system tasks.
  * Added ONCE interval.
  * Renamed Maintenance:: -&gt; Horde_LoginTasks::.
  * Initial Horde 4 package.
@@ -32,9 +32,6 @@
    <dir name="lib">
     <dir name="Horde">
      <dir name="LoginTasks">
-      <dir name="Backend">
-       <file name="Horde.php" role="php" />
-      </dir> <!-- /lib/Horde/LoginTasks/Backend -->
       <file name="Backend.php" role="php" />
       <file name="SystemTask.php" role="php" />
       <file name="Task.php" role="php" />
     <channel>pear.horde.org</channel>
    </package>
   </required>
-  <optional>
-   <package>
-    <name>Auth</name>
-    <channel>pear.horde.org</channel>
-   </package>
-   <package>
-    <name>Core</name>
-    <channel>pear.horde.org</channel>
-   </package>
-   <package>
-    <name>Prefs</name>
-    <channel>pear.horde.org</channel>
-   </package>
-  </optional>
  </dependencies>
  <phprelease>
   <filelist>
@@ -91,7 +74,6 @@
    <install as="Horde/LoginTasks/SystemTask.php" name="lib/Horde/LoginTasks/SystemTask.php" />
    <install as="Horde/LoginTasks/Task.php" name="lib/Horde/LoginTasks/Task.php" />
    <install as="Horde/LoginTasks/Tasklist.php" name="lib/Horde/LoginTasks/Tasklist.php" />
-   <install as="Horde/LoginTasks/Backend/Horde.php" name="lib/Horde/LoginTasks/Backend/Horde.php" />
    <install as="Horde/LoginTasks/AllTests.php" name="test/Horde/LoginTasks/AllTests.php" />
    <install as="Horde/LoginTasks/Autoload.php" name="test/Horde/LoginTasks/Autoload.php" />
    <install as="Horde/LoginTasks/LoginTasksTest.php" name="test/Horde/LoginTasks/LoginTasksTest.php" />
index 1f126be..f0a88e9 100644 (file)
@@ -104,7 +104,6 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         $tasks = $this->_getLoginTasks(
             array('Horde_LoginTasks_Stub_Year'), true, $date
         );
-        $tasks->runTasks();
         $this->assertEquals(
             array(),
             Horde_LoginTasks_Stub_Task::$executed
@@ -241,11 +240,9 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
 
     public function testTasksThatRunOnceAreNotExecutedMoreThanOnce()
     {
-        $prefs = new Horde_LoginTasks_Stub_Prefs();
-
         Horde_LoginTasks_Stub_Once::$executed = array();
         $tasks = $this->_getLoginTasks(
-            array('Horde_LoginTasks_Stub_Once'), true, false, $prefs
+            array('Horde_LoginTasks_Stub_Once'), true, false
         );
         $tasks->runTasks();
         $this->assertEquals(
@@ -254,9 +251,8 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         );
 
         Horde_LoginTasks_Stub_Task::$executed = array();
-        $date = getdate();
         $tasks = $this->_getLoginTasks(
-            array('Horde_LoginTasks_Stub_Once'), true, false, $prefs
+            array('Horde_LoginTasks_Stub_Once'), true, true
         );
         $tasks->runTasks();
         $this->assertEquals(
@@ -267,7 +263,6 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
 
     public function testAllTasksGetRunIfNoTasksRequiresDisplay()
     {
-        $prefs = new Horde_LoginTasks_Stub_Prefs();
         Horde_LoginTasks_Stub_Task::$executed = array();
         $tasks = $this->_getLoginTasks(
             array(
@@ -275,17 +270,20 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
                 'Horde_LoginTasks_Stub_High',
             ),
             true,
-            false,
-            $prefs
+            false
         );
         $tasks->runTasks();
-        $v = $prefs->getValue('last_logintasks');
-        $this->assertTrue(!empty($v));
+        $this->assertEquals(
+            array(
+                'Horde_LoginTasks_Stub_High',
+                'Horde_LoginTasks_Stub_Task'
+            ),
+            Horde_LoginTasks_Stub_Task::$executed
+        );
     }
 
     public function testTheLastTimeOfCompletingTheLoginTasksWillBeStoredOnceAllTasksWereExcecuted()
     {
-        $prefs = new Horde_LoginTasks_Stub_Prefs();
         Horde_LoginTasks_Stub_Task::$executed = array();
         $tasks = $this->_getLoginTasks(
             array(
@@ -293,12 +291,10 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
                 'Horde_LoginTasks_Stub_High',
             ),
             true,
-            false,
-            $prefs
+            false
         );
         $tasks->runTasks();
-        $v = unserialize($prefs->getValue('last_logintasks'));
-        $this->assertTrue($v['horde'] > time() - 10);
+        $this->assertTrue(Horde_LoginTasks_Stub_Backend::$lastRun['test'] > time() - 10);
     }
 
     public function testAllTasksToBeRunBeforeTheFirstTaskRequiringDisplayGetExecutedInABatch()
@@ -334,7 +330,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
             true
         );
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(false, null)
         );
     }
@@ -423,7 +419,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         $tasks->runTasks(false, 'redirect');
         $tasks->displayTasks();
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(true)
         );
         $this->assertNull(
@@ -431,7 +427,8 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         );
         $tasks->displayTasks();
         $this->assertEquals(
-            'redirect', $tasks->runTasks(true)
+            'redirect',
+            $tasks->runTasks(true)
         );
     }
 
@@ -452,7 +449,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
             true
         );
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(false, 'redirect')
         );
         $this->assertEquals(
@@ -476,7 +473,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         $_POST['logintasks_confirm_0'] = true;
         $_POST['logintasks_confirm_1'] = true;
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(true)
         );
         $this->assertEquals(
@@ -512,7 +509,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
             $classes
         );
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(true)
         );
         $this->assertEquals(
@@ -538,7 +535,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         );
         $_POST['logintasks_confirm_0'] = true;
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(true)
         );
         $this->assertEquals(
@@ -567,7 +564,7 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         );
         $_POST['logintasks_confirm_0'] = true;
         $this->assertContains(
-            'http:///services/logintasks.php?app=test',
+            'URL',
             (string) $tasks->runTasks(true)
         );
         $this->assertEquals(
@@ -614,49 +611,31 @@ class Horde_LoginTasks_LoginTasksTest extends PHPUnit_Framework_TestCase
         );
     }
 
-    private function _getLoginTasks(
-        array $tasks = array(),
-        $authenticated = false,
-        $last_run = false,
-        $prefs = false
-    ) {
-        if ($authenticated) {
-            $_SESSION['horde_auth']['userId'] = 'test';
-        }
-        $last_time = false;
-        if ($last_run) {
-            $last_time = mktime(
-                $last_run['hours'],
-                $last_run['minutes'],
-                $last_run['seconds'],
-                $last_run['mon'],
-                $last_run['mday'],
-                $last_run['year']
-            );
-            $last_time = serialize(
-                array(
-                    'test' => $last_time
-                )
+    private function _getLoginTasks(array $tasks = array(),
+                                    $authenticated = false, $last_run = false)
+    {
+        $last_time = $last_run;
+        if ($last_time && !is_bool($last_time)) {
+            $last_time = array(
+                'test' => mktime(
+                              $last_run['hours'],
+                              $last_run['minutes'],
+                              $last_run['seconds'],
+                              $last_run['mon'],
+                              $last_run['mday'],
+                              $last_run['year']
+                          )
             );
         }
-        if (empty($prefs)) {
-            $GLOBALS['prefs'] = $this->getMock('Horde_Prefs', array(), array(), '', false, false);
-            $GLOBALS['prefs']->expects($this->any())
-                ->method('getValue')
-                ->will($this->returnValue($last_time));
-        } else {
-            $GLOBALS['prefs'] = $prefs;
+
+        $tasklist = array();
+        foreach ($tasks as $val) {
+            $tasklist[$val] = 'test';
         }
-        $GLOBALS['registry'] = $this->getMock('Horde_Registry', array(), array(), '', false, false);
-        $GLOBALS['registry']->expects($this->any())
-            ->method('getAppDrivers')
-            ->will($this->returnValue($tasks));
+
         return new Horde_LoginTasks(
-            new Horde_LoginTasks_Stub_Backend(
-                $GLOBALS['registry'],
-                $GLOBALS['prefs'],
-                'test'
-            )
+            new Horde_LoginTasks_Stub_Backend($tasklist, $authenticated, $last_time)
         );
     }
+
 }
index 0d7dd4a..013d321 100644 (file)
@@ -1,67 +1,72 @@
 <?php
 
-if (!class_exists('Horde_Prefs')) {
-    class Horde_Prefs {
-        public function setValue($pref, $val, $convert = true)
-        {
-        }
+class Horde_LoginTasks_Stub_Backend extends Horde_LoginTasks_Backend
+{
+    static public $lastRun;
+
+    private $_authenticated;
+    private $_tasklist;
+    private $_tasklistCache = false;
 
-        public function getValue($pref, $convert = true)
-        {
+    public function __construct(array $tasks, $authenticated = false,
+                                $last_run = false)
+    {
+        $this->_tasklist = $tasks;
+        $this->_authenticated = $authenticated;
+        if ($last_run !== true) {
+            self::$lastRun = $last_run;
         }
     }
-}
 
-if (!class_exists('Horde_Registry')) {
-    class Horde_Registry {
-        public function get($parameter, $app = null)
-        {
-        }
+    public function isAuthenticated()
+    {
+        return $this->_authenticated;
+    }
 
-        public function getAppDrivers($app, $prefix)
-        {
-        }
+    public function getTasklistFromCache()
+    {
+        return $this->_tasklistCache;
     }
-}
 
-if (!class_exists('Horde')) {
-    class Horde {
-        static public function url($url)
-        {
-            $url = new Horde_Url($url);
-            return 'http://' . (string) $url;
-        }
+    public function storeTasklistInCache($tasklist)
+    {
+        $this->_tasklistCache = $tasklist;
     }
-}
 
-if (!class_exists('Horde_Auth')) {
-    class Horde_Auth {
-        static public function getAuth()
-        {
-            return empty($_SESSION['horde_auth']['userId'])
-                ? false
-                : $_SESSION['horde_auth']['userId'];
-        }
+    public function registerShutdown($shutdown)
+    {
     }
-}
 
-class Horde_LoginTasks_Stub_Prefs
-extends Horde_Prefs
-{
-    private $_storage = array();
+    public function getTasks()
+    {
+        return $this->_tasklist;
+    }
+
+    public function getLastRun()
+    {
+        return self::$lastRun;
+    }
+
+    public function setLastRun(array $last)
+    {
+        self::$lastRun = $last;
+    }
 
-    public function __construct()
+    public function markLastRun()
     {
+        $lasttasks = $this->getLastRun();
+        $lasttasks['test'] = time();
+        self::$lastRun = $lasttasks;
     }
 
-    public function setValue($pref, $val, $convert = true)
+    public function redirect($url)
     {
-        $this->_storage[$pref] = $val;
+        return $url;
     }
 
-    public function getValue($pref, $convert = true)
+    public function getLoginTasksUrl(array $tasks = null)
     {
-        return isset($this->_storage[$pref]) ? $this->_storage[$pref] : null;
+        return 'URL';
     }
 }
 
@@ -71,9 +76,7 @@ extends Horde_LoginTasks_Task
     static public $executed;
 
     public $interval = Horde_LoginTasks::EVERY;
-
     public $display = Horde_LoginTasks::DISPLAY_NONE;
-
     public $priority = Horde_LoginTasks::PRIORITY_NORMAL;
 
     public function execute()
@@ -82,15 +85,6 @@ extends Horde_LoginTasks_Task
     }
 }
 
-class Horde_LoginTasks_Stub_Backend
-extends Horde_LoginTasks_Backend_Horde
-{
-    public function redirect($url)
-    {
-        return $url;
-    }
-}
-
 class Horde_LoginTasks_Stub_TaskTwo
 extends Horde_LoginTasks_Stub_Task
 {
@@ -172,4 +166,4 @@ class Horde_LoginTasks_Stub_Year
 extends Horde_LoginTasks_Stub_Task
 {
     public $interval = Horde_LoginTasks::YEARLY;
-}
\ No newline at end of file
+}
index e0317a5..c1dbe00 100644 (file)
@@ -16,13 +16,13 @@ Horde_Registry::appInit('horde', array('nologintasks' => true));
 
 /* If no 'module' parameter passed in, die with an error. */
 if (!($app = basename(Horde_Util::getFormData('app')))) {
-    throw new Horde_Exception("Do not directly access logintasks.php");
+    throw new Horde_Exception('Do not directly access logintasks.php.');
 }
 
 $registry->pushApp($app, array('logintasks' => false));
 
-if (!($tasks = Horde_LoginTasks::singleton($app))) {
-    throw new Horde_Exception("The Horde_LoginTasks:: class did not load successfully");
+if (!($tasks = $injector->getInstance('Horde_LoginTasks')->getOb($app))) {
+    throw new Horde_Exception('The Horde_LoginTasks:: class did not load successfully.');
 }
 
 /* If we are through with tasks, this call will redirect to application. */