~cyrenity/zivios/devel

« back to all changes in this revision

Viewing changes to application/library/Ecl/Ldap/SchemaAttribute.php

  • Committer: Faraz Khan
  • Date: 2008-09-15 13:29:33 UTC
  • Revision ID: fkhan@zivios.org-20080915132933-d27jml5l29xw4gsr
Initial release to bazaar, code in sync with 0.5.0-release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright (c) 2008 Zivios, LLC.
 
4
 *
 
5
 * This file is part of Zivios.
 
6
 *
 
7
 * Zivios is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * Zivios is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with Zivios.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 * @package             Zivios
 
21
 * @copyright   Copyright (c) 2008 Zivios, LLC. (http://www.zivios.org)
 
22
 * @license             http://www.zivios.org/legal/license
 
23
 * @version             $Id: SchemaAttribute.php 908 2008-08-25 11:03:00Z fkhan $
 
24
 * @subpackage  Schema
 
25
 **/
 
26
 
 
27
class Ecl_Ldap_SchemaAttribute
 
28
{
 
29
        private $origline,$emsolcschema;
 
30
        public $prio,$name,$desc,$sup,$syntax,$equality,$substr,$singlevalue,$oidfamily,$oidvalue;
 
31
 
 
32
        public function __construct($emsolcschema,$attribline='')
 
33
        {
 
34
                $this->origline = $attribline;
 
35
                $this->emsolcschema = $emsolcschema;
 
36
                Ecl_Log::debug("Schema Parser started with $attribline");
 
37
                if ($attribline != '') {
 
38
                        $this->parse();
 
39
                }
 
40
 
 
41
        }
 
42
        public function setOid($family,$value=null)
 
43
        {
 
44
                if ($value == null) {
 
45
                        $this->oidvalue = $this->emsolcschema->getMaxOidAttrib($family);
 
46
                } else {
 
47
                        $this->oidvalue = $value;
 
48
                }
 
49
 
 
50
                $this->oidfamily = $family;
 
51
        }
 
52
        private function parseOid($oid)
 
53
        {
 
54
                $reversed = strrev($oid);
 
55
                $oidtokenized = explode('.',$reversed,2);
 
56
                $this->oidvalue=strrev($oidtokenized[0]);
 
57
                $this->oidfamily=strrev($oidtokenized[1]);
 
58
        }
 
59
        private function parse()
 
60
        {
 
61
                $line = $this->origline;
 
62
                $matches = array();
 
63
                preg_match_all("/^\{(\d+?)\}/",$line,$matches);
 
64
                $this->prio = $matches[1][0];
 
65
                preg_match_all("/\( ([\d\.]+?) /",$line,$matches);
 
66
                $this->parseOid($matches[1][0]);
 
67
                $this->name = Ecl_Util::magicParseValue($line,'NAME');
 
68
                $this->desc = Ecl_Util::magicParseValue($line,'DESC');
 
69
                $this->sup = Ecl_Util::magicParseValue($line,'SUP');
 
70
                $this->syntax = Ecl_Util::magicParseValue($line,'SYNTAX');
 
71
                $this->equality = Ecl_Util::magicParseValue($line,'EQUALITY');
 
72
                $this->substr = Ecl_Util::magicParseValue($line,'SUBSTR');
 
73
                $this->singlevalue = preg_match("/ SINGLE-VALUE /",$line);
 
74
                Ecl_Log::debug("Read in Schema entry with prio: $this->prio OID: $this->oidfamily $this->oidvalue   Name: $this->name \
 
75
                                Desc: $this->desc sup: $this->sup SYNTAX: $this->syntax EQUALITY: $this->equality \
 
76
                                substr: $this->substr Singlevalue=$this->singlevalue");
 
77
 
 
78
 
 
79
        }
 
80
        public function isValid()
 
81
        {
 
82
                // Stub function. Add validation here
 
83
                return 1;
 
84
        }
 
85
        public function render()
 
86
        {
 
87
 
 
88
 
 
89
                $line = "";
 
90
                $oid = $this->oidfamily.'.'.$this->oidvalue;
 
91
                Ecl_Log::debug("helo : $this->prio");
 
92
                $str = '{'.$this->prio.'}';
 
93
                Ecl_Log::debug("STR IS $str");
 
94
                Ecl_Log::debug("hello");
 
95
                if ($this->sup != '') {
 
96
 
 
97
                        $str .= "( $oid NAME '$this->name' DESC '$this->desc' SUP $this->sup )";
 
98
                }
 
99
                else {
 
100
 
 
101
                        //$str = "SYNTAX $this->syntax";
 
102
                        $str .= '( '.$oid.' NAME \''.$this->name.'\' DESC \''.$this->desc.'\' EQUALITY '.$this->equality.' SUBSTR '.$this->substr.' SYNTAX '.$this->syntax;
 
103
                        if ($this->singlevalue) {
 
104
                                $str .= " SINGLE-VALUE ";
 
105
                        }
 
106
                        $str .= ")";
 
107
 
 
108
 
 
109
                }
 
110
                return $str;
 
111
        }
 
112
 
 
113
}
 
 
b'\\ No newline at end of file'