ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 */
46{
58 var $_path;
59
68 function getPath()
69 {
70 return $this->_path;
71 }
72
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 {
137 // call the ancestor's constructor
138 $this->PGTStorage($cas_parent);
139
140 if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
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) {
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 }
174 }
175
176 // ########################################################################
177 // INITIALIZATION
178 // ########################################################################
179
185 function init()
186 {
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();
194 }
195
196 // ########################################################################
197 // PGT I/O
198 // ########################################################################
199
208 function getPGTIouFilename($pgt_iou)
209 {
211 $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();
213 return $filename;
214 }
215
225 function write($pgt,$pgt_iou)
226 {
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 }
238 }
239
250 function read($pgt_iou)
251 {
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?>
$filename
Definition: buildRTE.php:89
The PGTStorageFile class is a class for PGT file storage.
Definition: pgt-file.php:46
The PGTStorage class is a generic class for PGT storage.
Definition: pgt-main.php:46
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:544
trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:569
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
Definition: CAS.php:577
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:604
init()
This method is used to initialize the storage.
Definition: pgt-file.php:185
write($pgt, $pgt_iou)
This method stores a PGT and its corresponding PGT Iou into a file.
Definition: pgt-file.php:225
getPGTIouFilename($pgt_iou)
This method returns the filename corresponding to a PGT Iou.
Definition: pgt-file.php:208
read($pgt_iou)
This method reads a PGT corresponding to a PGT Iou and deletes the corresponding file.
Definition: pgt-file.php:250
getPath()
This method returns the name of the directory where PGT's should be stored on the filesystem.
Definition: pgt-file.php:68
getStorageType()
This method returns an informational string giving the type of storage used by the object (used for d...
Definition: pgt-file.php:104
PGTStorageFile($cas_parent, $format, $path)
The class constructor, called by CASClient::SetPGTStorageFile().
Definition: pgt-file.php:134
getStorageInfo()
This method returns an informational string giving informations on the parameters of the storage.
Definition: pgt-file.php:116
$_path
a string telling where PGT's should be stored on the filesystem.
Definition: pgt-file.php:58
getFormat()
This method returns the format to use when storing PGT's on the filesystem.
Definition: pgt-file.php:88
$_format
a string telling the format to use to store PGT's (plain or xml).
Definition: pgt-file.php:79
isInitialized()
This method tells if the storage has already been intialized.
Definition: pgt-main.php:160
PGTStorage($cas_parent)
The constructor of the class, should be called only by inherited classes.
Definition: pgt-main.php:63
const CAS_PGT_STORAGE_FILE_DEFAULT_PATH
Default path used when storing PGT's to file.
Definition: CAS.php:149
const CAS_PGT_STORAGE_FILE_FORMAT_PLAIN
phpCAS::setPGTStorageFile()'s 2nd parameter to write plain text files
Definition: CAS.php:153
const CAS_PGT_STORAGE_FILE_FORMAT_XML
phpCAS::setPGTStorageFile()'s 2nd parameter to write xml files
Definition: CAS.php:157
const CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT
Default format used when storing PGT's to file.
Definition: CAS.php:161
$path
Definition: index.php:22