1<?php
2
3function php_error_handler($errno, $errstr, $errfile, $errline)
4{
5    if (error_reporting() && $errno != 2048) {
6        var_dump('error_msg', "<b>$errfile ($errline)</b><br />$errstr");
7    }
8}
9
10set_error_handler('php_error_handler');
11
12require_once 'LiveUser/Admin.php';
13// Please configure the following file according to your environment
14
15$GLOBALS['_LIVEUSER_DEBUG'] = true;
16
17$db_user = 'root';
18$db_pass = '';
19$db_host = 'localhost';
20$db_name = 'liveuser_admin_test_example1';
21
22$dsn = "mysql://$db_user:$db_pass@$db_host/$db_name";
23
24$backends = array(
25    'DB' => array(
26        'options' => array()
27    ),
28    'MDB' => array(
29        'options' => array()
30    ),
31    'MDB2' => array(
32        'options' => array(
33            'debug' => true,
34            'debug_handler' => 'echoQuery',
35        )
36    )
37);
38
39if (!array_key_exists('storage', $_GET)) {
40    $storage = 'MDB2';
41} elseif (isset($backends[$_GET['storage']])) {
42    $storage = strtoupper($_GET['storage']);
43} else {
44    exit('storage Backend not found.');
45}
46
47require_once $storage.'.php';
48
49function echoQuery(&$db, $scope, $message)
50{
51    Var_Dump::display($scope.': '.$message);
52}
53
54$dummy = new $storage;
55$db = $dummy->connect($dsn, $backends[$storage]['options']);
56
57if (PEAR::isError($db)) {
58    echo $db->getMessage() . ' ' . $db->getUserInfo();
59    die();
60}
61
62$db->setFetchMode(constant($storage.'_FETCHMODE_ASSOC'));
63
64$conf =
65    array(
66        'debug' => true,
67        'session'  => array(
68            'name'     => 'PHPSESSION',
69            'varname'  => 'ludata'
70        ),
71        'login' => array(
72            'force'    => false,
73        ),
74        'logout' => array(
75            'destroy'  => true,
76        ),
77        'authContainers' => array(
78            'DB_Local' => array(
79                'type' => $storage,
80                'expireTime'    => 3600,
81                'idleTime'      => 1800,
82                'storage' => array(
83                    'dbc' => $db,
84                    'dsn' => $dsn,
85                    'prefix' => 'liveuser_',
86                    'tables' => array(
87                        'users' => array(
88                            'fields' => array(
89                                'name' => false,
90                                'email' => false,
91                            ),
92                        ),
93                    ),
94                    'fields' => array(
95                        'name' => 'text',
96                        'email' => 'text',
97                    ),
98                    'alias' => array(
99                        'name' => 'name',
100                        'email' => 'email',
101                        'auth_user_id' => 'user_id',
102                    ),
103                    // 'force_seq' => false
104                ),
105            )
106        ),
107        'permContainer' => array(
108            'type'  => 'Complex',
109            'alias' => array(),
110            'storage' => array(
111                $storage => array(
112                    'dbc' => $db,
113                    'dsn' => $dsn,
114                    'prefix' => 'liveuser_',
115                    'tables' => array(),
116                    'fields' => array(),
117                    'alias' => array(),
118                    // 'force_seq' => false
119                ),
120            ),
121        ),
122    );
123
124$admin =& LiveUser_Admin::factory($conf);
125$logconf = array('mode' => 0666, 'timeFormat' => '%X %x');
126$logger = &Log::factory('file', 'liveuser_test.log', 'ident', $logconf);
127$admin->log->addChild($logger);
128$admin->init();
129