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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<?php
/*
* struct.php - Abstraction for complex type.
*
* Copyright (C) 2006 - Marcus Lunzenauer <mlunzena@uos.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
/**
* Abstraction for complex type
*
* @package studip
* @subpackage ws
*
* @abstract
*
* @author mlunzena
* @copyright (c) Authors
* @version $Id: struct.php 3888 2006-09-06 13:27:19Z mlunzena $
*/
class Studip_Ws_Struct {
/**
* Class-level constructor. Initialize your struct within using
* ClassName::add_element('name', 'type', $options)
*
* @abstract
*
* @return void
*/
function init() {
}
/**
* <MethodDescription>
*
* @access protected
*
* @param string <description>
* @param mixed <description>
* @param array <description>
*
* @return type <description>
*/
function add_element($name = NULL, $type = NULL, $options = array()) {
# static var setup
static $elements;
if (is_null($elements))
$elements = array();
# setter functionality
if (!is_null($name)) {
# no doublets
if (isset($elements[$name])) {
trigger_error(sprintf('Element %s already defined.', $name),
E_USER_ERROR);
return;
}
# store it
$elements[$name] = new Studip_Ws_StructElement($name, $type, $options);
return;
}
# getter functionality
return $elements;
}
/**
* <MethodDescription>
*
* @param string <description>
*
* @return array <description>
*/
function &get_struct_elements($class = NULL) {
static $once;
# call 'init' once
if (is_null($once)) {
# guess class name if not given (does not work in PHP5 anymore?!)
if (is_null($class)) {
$backtrace = debug_backtrace();
$class = $backtrace[0]['class'];
}
# call "class" constructor
call_user_func(array($class, 'init'));
$once = call_user_func(array($class, 'add_element'));
}
return $once;
}
function __toString() {
return get_class($this);
}
}
/**
* Abstraction for complex type elements.
*
* @package studip
* @subpackage ws
*
* @author mlunzena
* @copyright (c) Authors
* @version $Id: struct.php 3888 2006-09-06 13:27:19Z mlunzena $
*/
class Studip_Ws_StructElement {
/**
* The name of the element.
*
* @access private
* @var string
*/
var $name;
/**
* The type of the element.
*
* @access private
* @var mixed
*/
var $type;
/**
* Options for the element.
*
* @access private
* @var array
*/
var $options;
/**
* Constructor.
*
* @param string the name of the element.
* @param mixed the type of the element.
* @param array options for the element.
*
* @return void
*/
function __construct($name, $type, $options = array()) {
$this->name = (string) $name;
$this->type = Studip_Ws_Type::translate($type);
$this->options = $options;
}
function __toString() {
return get_class($this);
}
}
|