Hylax: Add Application class to replace lib/base.php
authorBen Klang <ben@alkaloid.net>
Fri, 8 Jan 2010 15:09:27 +0000 (10:09 -0500)
committerBen Klang <ben@alkaloid.net>
Fri, 8 Jan 2010 15:09:27 +0000 (10:09 -0500)
hylax/lib/Application.php [new file with mode: 0644]

diff --git a/hylax/lib/Application.php b/hylax/lib/Application.php
new file mode 100644 (file)
index 0000000..e033c83
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/**
+ * Hylax Application class file.
+ *
+ * This file brings in all of the dependencies that every Hylax script will
+ * need, and sets up objects that all scripts use.
+ *
+ * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * $Horde: incubator/hylax/lib/base.php,v 1.16 2009/07/13 20:05:46 slusarz Exp $
+ */
+
+if (!defined('HYLAX_BASE')) {
+    define('HYLAX_BASE', dirname(__FILE__). '/..');
+}
+
+if (!defined('HORDE_BASE')) {
+    /* If horde does not live directly under the app directory, the HORDE_BASE
+     * constant should be defined in config/horde.local.php. */
+    if (file_exists(HYLAX_BASE. '/config/horde.local.php')) {
+        include HYLAX_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', HYLAX_BASE . '/..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ * Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
+
+class Hylax_Application extends Horde_Registry_Application
+{
+    function __constructor($args = array())
+    {
+        if (!empty($args['init'])) {
+
+            // Registry.
+            $registry = Horde_Registry::singleton();
+            $GLOBALS['registry'] = &$registry;
+            
+            try {
+                $registry->pushApp('hylax', !defined('AUTH_HANDLER'));
+            } catch (Horde_Exception $e) {
+                if ($e->getCode() == 'permission_denied') {
+                    Horde::authenticationFailureRedirect();
+                }
+                Horde::fatal($e, __FILE__, __LINE__, false);
+            }
+
+            $conf = &$GLOBALS['conf'];
+            define('HYLAX_TEMPLATES', $registry->get('templates'));
+
+            /* Notification system. */
+            $notification = Horde_Notification::singleton();
+            $notification->attach('status');
+            $GLOBALS['notification'] = &$notification;
+
+            /* Find the base file path of Hylax. */
+            define('HYLAX_BASE', dirname(__FILE__) . '/..');
+
+            /* Hylax Driver */
+            $gateway = Hylax_Driver::singleton($conf['fax']['driver'], $conf['fax']['params']);
+
+            /* Hylax storage driver. */
+            $hylax_storage = Hylax_Storage::singleton('sql', $conf['sql']);
+
+            /* Start compression, if requested. */
+            Horde::compressOutput();
+        }
+    }
+
+    public function perms()
+    {
+        static $perms = array();
+        if (!empty($perms)) {
+            return $perms;
+        }
+
+        return $perms;
+    }
+}
\ No newline at end of file