ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
pgt-file.php
Go to the documentation of this file.
1<?php
2
18class PGTStorageFile extends PGTStorage
19{
31 var $_path;
32
41 function getPath()
42 {
43 return $this->_path;
44 }
45
52 var $_format;
53
61 function getFormat()
62 {
63 return $this->_format;
64 }
65
66 // ########################################################################
67 // DEBUGGING
68 // ########################################################################
69
77 function getStorageType()
78 {
79 return "file";
80 }
81
89 function getStorageInfo()
90 {
91 return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';
92 }
93
94 // ########################################################################
95 // CONSTRUCTOR
96 // ########################################################################
97
107 function PGTStorageFile($cas_parent,$format,$path)
108 {
110 // call the ancestor's constructor
111 $this->PGTStorage($cas_parent);
112
113 if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
115
116 // check that the path is an absolute path
117 if ( $path[0] != '/' ) {
118 phpCAS::error('an absolute path is needed for PGT storage to file');
119 }
120
121 // store the path (with a leading and trailing '/')
122 $path = preg_replace('|[/]*$|','/',$path);
123 $path = preg_replace('|^[/]*|','/',$path);
124 $this->_path = $path;
125
126 // check the format and store it
127 switch ($format) {
130 $this->_format = $format;
131 break;
132 default:
133 phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
134 }
136 }
137
138 // ########################################################################
139 // INITIALIZATION
140 // ########################################################################
141
147 function init()
148 {
150 // if the storage has already been initialized, return immediatly
151 if ( $this->isInitialized() )
152 return;
153 // call the ancestor's method (mark as initialized)
154 parent::init();
156 }
157
158 // ########################################################################
159 // PGT I/O
160 // ########################################################################
161
170 function getPGTIouFilename($pgt_iou)
171 {
173 return $this->getPath().$pgt_iou.'.'.$this->getFormat();
175 }
176
186 function write($pgt,$pgt_iou)
187 {
189 $fname = $this->getPGTIouFilename($pgt_iou);
190 if ( $f=fopen($fname,"w") ) {
191 if ( fputs($f,$pgt) === FALSE ) {
192 phpCAS::error('could not write PGT to `'.$fname.'\'');
193 }
194 fclose($f);
195 } else {
196 phpCAS::error('could not open `'.$fname.'\'');
197 }
199 }
200
211 function read($pgt_iou)
212 {
214 $pgt = FALSE;
215 $fname = $this->getPGTIouFilename($pgt_iou);
216 if ( !($f=fopen($fname,"r")) ) {
217 phpCAS::trace('could not open `'.$fname.'\'');
218 } else {
219 if ( ($pgt=fgets($f)) === FALSE ) {
220 phpCAS::trace('could not read PGT from `'.$fname.'\'');
221 }
222 fclose($f);
223 }
224
225 // delete the PGT file
226 @unlink($fname);
227
228 phpCAS::traceEnd($pgt);
229 return $pgt;
230 }
231
234}
235
236
237?>
The PGTStorageFile class is a class for PGT file storage.
Definition: pgt-file.php:46
init()
This method is used to initialize the storage.
Definition: pgt-file.php:147
write($pgt, $pgt_iou)
This method stores a PGT and its corresponding PGT Iou into a file.
Definition: pgt-file.php:186
getPGTIouFilename($pgt_iou)
This method returns the filename corresponding to a PGT Iou.
Definition: pgt-file.php:170
read($pgt_iou)
This method reads a PGT corresponding to a PGT Iou and deletes the corresponding file.
Definition: pgt-file.php:211
getPath()
This method returns the name of the directory where PGT's should be stored on the filesystem.
Definition: pgt-file.php:41
getStorageType()
This method returns an informational string giving the type of storage used by the object (used for d...
Definition: pgt-file.php:77
PGTStorageFile($cas_parent, $format, $path)
The class constructor, called by CASClient::SetPGTStorageFile().
Definition: pgt-file.php:107
getStorageInfo()
This method returns an informational string giving informations on the parameters of the storage.
Definition: pgt-file.php:89
getFormat()
This method returns the format to use when storing PGT's on the filesystem.
Definition: pgt-file.php:61
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
getPGTIouFilename($pgt_iou)
This method returns the filename corresponding to a PGT Iou.
Definition: pgt-file.php:208
getPath()
This method returns the name of the directory where PGT's should be stored on the filesystem.
Definition: pgt-file.php:68
$_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