summaryrefslogtreecommitdiffstats
path: root/examples/class/framework.class.php
blob: 0461da7ad0cadb0210c7b528fcac007bb24d399e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

abstract class Framework
{
    /*
     * Get the absolute path on this server for the root of this app
     */
    function ar()
    {
        return substr($_SERVER['PHP_SELF'], 0, -10); // 10 = length of "/index.php"
    }

    /*
     * Get the absolute path to the current page
     */
    function ap()
    {
        return $this->ar() . $_REQUEST['path'];
    }

    /*
     * Redirect to the given URL and die
     */
    function redirectTo($url)
    {
        header("Location: " . $url);
        exit;
    }

    /*
     * Get or create the app's database connection object (this is a singleton object and dependent on system-level config)
     */
    static function getDbConnection()
    {
        global $_SCROTT;

        if (self::$dbobj != null)
            return self::$dbobj;

        switch ($_SCROTT['dbEngine'])
        {
        case "mysql":
            $host     = $_SCROTT['dbAddress'];
            $username = $_SCROTT['dbUser'];
            $password = $_SCROTT['dbPass'];
            $dbName   = $_SCROTT['dbName'];
            self::$dbobj = new Mysql($host, $username, $password, $dbName);
            break;

        default:
            throw new Exception("Problem with Scrott Configuration. Invalid database engine specified.");
            break;
        }

        return self::$dbobj;
    }
}

?>