ILIAS
release_4-3 Revision
◀ ilDoc Overview
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Groups
Pages
pgt-file.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are met:
8
*
9
* * Redistributions of source code must retain the above copyright notice,
10
* this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the ESUP-Portail consortium & the JA-SIG
15
* Collaborative nor the names of its contributors may be used to endorse or
16
* promote products derived from this software without specific prior
17
* written permission.
18
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
*/
45
class
PGTStorageFile
extends
PGTStorage
46
{
58
var
$_path
;
59
68
function
getPath
()
69
{
70
return
$this->_path
;
71
}
72
79
var
$_format
;
80
88
function
getFormat
()
89
{
90
return
$this->_format
;
91
}
92
93
// ########################################################################
94
// DEBUGGING
95
// ########################################################################
96
104
function
getStorageType
()
105
{
106
return
"file"
;
107
}
108
116
function
getStorageInfo
()
117
{
118
return
'path=`'
.$this->getPath().
'\'
, format=`
'.$this->getFormat().'
\
''
;
119
}
120
121
// ########################################################################
122
// CONSTRUCTOR
123
// ########################################################################
124
134
function
PGTStorageFile
($cas_parent,$format,
$path
)
135
{
136
phpCAS::traceBegin
();
137
// call the ancestor's constructor
138
$this->
PGTStorage
($cas_parent);
139
140
if
(empty($format) ) $format =
CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT
;
141
if
(empty(
$path
) )
$path
=
CAS_PGT_STORAGE_FILE_DEFAULT_PATH
;
142
143
// check that the path is an absolute path
144
if
(getenv(
"OS"
)==
"Windows_NT"
){
145
146
if
(!preg_match(
'`^[a-zA-Z]:`'
,
$path
)) {
147
phpCAS::error
(
'an absolute path is needed for PGT storage to file'
);
148
}
149
150
}
151
else
152
{
153
154
if
(
$path
[0] !=
'/'
) {
155
phpCAS::error
(
'an absolute path is needed for PGT storage to file'
);
156
}
157
158
// store the path (with a leading and trailing '/')
159
$path
= preg_replace(
'|[/]*$|'
,
'/'
,
$path
);
160
$path
= preg_replace(
'|^[/]*|'
,
'/'
,
$path
);
161
}
162
163
$this->_path =
$path
;
164
// check the format and store it
165
switch
($format) {
166
case
CAS_PGT_STORAGE_FILE_FORMAT_PLAIN
:
167
case
CAS_PGT_STORAGE_FILE_FORMAT_XML
:
168
$this->_format = $format;
169
break
;
170
default
:
171
phpCAS::error
(
'unknown PGT file storage format (`'
.
CAS_PGT_STORAGE_FILE_FORMAT_PLAIN
.
'\'
and `
'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'
\
' allowed)'
);
172
}
173
phpCAS::traceEnd
();
174
}
175
176
// ########################################################################
177
// INITIALIZATION
178
// ########################################################################
179
185
function
init
()
186
{
187
phpCAS::traceBegin
();
188
// if the storage has already been initialized, return immediatly
189
if
( $this->
isInitialized
() )
190
return
;
191
// call the ancestor's method (mark as initialized)
192
parent::init
();
193
phpCAS::traceEnd
();
194
}
195
196
// ########################################################################
197
// PGT I/O
198
// ########################################################################
199
208
function
getPGTIouFilename
($pgt_iou)
209
{
210
phpCAS::traceBegin
();
211
$filename
= $this->
getPath
().$pgt_iou.
'.'
.$this->
getFormat
();
212
phpCAS::traceEnd
(
$filename
);
213
return
$filename
;
214
}
215
225
function
write
($pgt,$pgt_iou)
226
{
227
phpCAS::traceBegin
();
228
$fname = $this->
getPGTIouFilename
($pgt_iou);
229
if
( $f=fopen($fname,
"w"
) ) {
230
if
( fputs($f,$pgt) === FALSE ) {
231
phpCAS::error
(
'could not write PGT to `'
.$fname.
'\''
);
232
}
233
fclose($f);
234
}
else
{
235
phpCAS::error
(
'could not open `'
.$fname.
'\''
);
236
}
237
phpCAS::traceEnd
();
238
}
239
250
function
read
($pgt_iou)
251
{
252
phpCAS::traceBegin
();
253
$pgt = FALSE;
254
$fname = $this->
getPGTIouFilename
($pgt_iou);
255
if
( !($f=fopen($fname,
"r"
)) ) {
256
phpCAS::trace
(
'could not open `'
.$fname.
'\''
);
257
}
else
{
258
if
( ($pgt=fgets($f)) === FALSE ) {
259
phpCAS::trace
(
'could not read PGT from `'
.$fname.
'\''
);
260
}
261
fclose($f);
262
}
263
264
// delete the PGT file
265
@unlink($fname);
266
267
phpCAS::traceEnd
($pgt);
268
return
$pgt;
269
}
270
273
}
274
275
276
?>
Services
CAS
lib
CAS
PGTStorage
pgt-file.php
Generated on Sat Apr 30 2016 19:00:53 for ILIAS by
1.8.1.2 (using
Doxyfile
)