/dev/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/trunk

« back to all changes in this revision

Viewing changes to classes/options.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class OPTIONS {
 
4
 var $options;
 
5
    
 
6
 function __construct(&$req = NULL, &$override = NULL) {
 
7
    global $OPTIONS;
 
8
 
 
9
    if ($req instanceof REQUEST) $props = &$req->props;
 
10
    else $props = &$req;
 
11
    
 
12
    $this->options = array();
 
13
    if ($override) $this->options[] = &$override;
 
14
    
 
15
    if (($req)&&(isset($props['db_server']))) {
 
16
        $sname = $props['db_server']; $slen = strlen($sname);
 
17
        
 
18
        if (isset($props['db_name'])) {
 
19
            $dname = "__" . $props['db_name']; $dlen = strlen($dname);
 
20
 
 
21
            if (isset($props['db_group'])) {
 
22
                $gname = $props['db_group'];
 
23
            }
 
24
        }
 
25
 
 
26
        foreach (array_keys($OPTIONS) as $regex) {
 
27
            if (!strncmp($regex, $sname, $slen)) {
 
28
                $len = strlen($regex);
 
29
                if ($len == $slen) $sopts = &$OPTIONS[$regex];
 
30
                elseif (($dname)&&(!strcmp(substr($regex, $slen, $dlen), $dname))) {
 
31
                    $pos = strpos($regex, "__", $slen + $dlen);
 
32
 
 
33
                    if ($pos === false) $dopts = &$OPTIONS[$regex];
 
34
                    else if (($gname)&&(!strcmp(substr($regex, $pos + 2), $gname))) {
 
35
                        $gopts = &$OPTIONS[$regex];
 
36
                        if (($sopts)&&($dopts)) break;
 
37
                    }
 
38
                }
 
39
            }
 
40
        }
 
41
        
 
42
        if ($gopts) $this->options[] = &$gopts;
 
43
        if ($dopts) $this->options[] = &$dopts;
 
44
        if ($sopts) $this->options[] = &$sopts;
 
45
    }
 
46
    if (isset($OPTIONS['default'])) $this->options[] = &$OPTIONS['default'];
 
47
 }
 
48
 
 
49
 function Get($prop, $default=NULL) {
 
50
    foreach ($this->options as &$opts) {
 
51
        if (isset($opts[$prop])) return $opts[$prop];
 
52
    }
 
53
    return $default;
 
54
 }
 
55
}
 
56
 
 
57
 
 
58
?>
 
 
b'\\ No newline at end of file'