4 * @file CAS/PGTStorage/pgt-file.php
\r
5 * Basic class for PGT file storage
\r
9 * @class PGTStorageFile
\r
10 * The PGTStorageFile class is a class for PGT file storage. An instance of
\r
11 * this class is returned by CASClient::SetPGTStorageFile().
\r
13 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
\r
15 * @ingroup internalPGTStorageFile
\r
18 class PGTStorageFile extends PGTStorage
\r
21 * @addtogroup internalPGTStorageFile
\r
26 * a string telling where PGT's should be stored on the filesystem. Written by
\r
27 * PGTStorageFile::PGTStorageFile(), read by getPath().
\r
34 * This method returns the name of the directory where PGT's should be stored
\r
35 * on the filesystem.
\r
37 * @return the name of a directory (with leading and trailing '/')
\r
43 return $this->_path;
\r
47 * a string telling the format to use to store PGT's (plain or xml). Written by
\r
48 * PGTStorageFile::PGTStorageFile(), read by getFormat().
\r
55 * This method returns the format to use when storing PGT's on the filesystem.
\r
57 * @return a string corresponding to the format used (plain or xml).
\r
61 function getFormat()
\r
63 return $this->_format;
\r
66 // ########################################################################
\r
68 // ########################################################################
\r
71 * This method returns an informational string giving the type of storage
\r
72 * used by the object (used for debugging purposes).
\r
74 * @return an informational string.
\r
77 function getStorageType()
\r
83 * This method returns an informational string giving informations on the
\r
84 * parameters of the storage.(used for debugging purposes).
\r
86 * @return an informational string.
\r
89 function getStorageInfo()
\r
91 return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';
\r
94 // ########################################################################
\r
96 // ########################################################################
\r
99 * The class constructor, called by CASClient::SetPGTStorageFile().
\r
101 * @param $cas_parent the CASClient instance that creates the object.
\r
102 * @param $format the format used to store the PGT's (`plain' and `xml' allowed).
\r
103 * @param $path the path where the PGT's should be stored
\r
107 function PGTStorageFile($cas_parent,$format,$path)
\r
109 phpCAS::traceBegin();
\r
110 // call the ancestor's constructor
\r
111 $this->PGTStorage($cas_parent);
\r
113 if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
\r
114 if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH;
\r
116 // check that the path is an absolute path
\r
117 if (getenv("OS")=="Windows_NT"){
\r
119 if (!preg_match('`^[a-zA-Z]:`', $path)) {
\r
120 phpCAS::error('an absolute path is needed for PGT storage to file');
\r
127 if ( $path[0] != '/' ) {
\r
128 phpCAS::error('an absolute path is needed for PGT storage to file');
\r
131 // store the path (with a leading and trailing '/')
\r
132 $path = preg_replace('|[/]*$|','/',$path);
\r
133 $path = preg_replace('|^[/]*|','/',$path);
\r
136 $this->_path = $path;
\r
137 // check the format and store it
\r
139 case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN:
\r
140 case CAS_PGT_STORAGE_FILE_FORMAT_XML:
\r
141 $this->_format = $format;
\r
144 phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
\r
146 phpCAS::traceEnd();
\r
149 // ########################################################################
\r
151 // ########################################################################
\r
154 * This method is used to initialize the storage. Halts on error.
\r
160 phpCAS::traceBegin();
\r
161 // if the storage has already been initialized, return immediatly
\r
162 if ( $this->isInitialized() )
\r
164 // call the ancestor's method (mark as initialized)
\r
166 phpCAS::traceEnd();
\r
169 // ########################################################################
\r
171 // ########################################################################
\r
174 * This method returns the filename corresponding to a PGT Iou.
\r
176 * @param $pgt_iou the PGT iou.
\r
178 * @return a filename
\r
181 function getPGTIouFilename($pgt_iou)
\r
183 phpCAS::traceBegin();
\r
184 $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();
\r
185 phpCAS::traceEnd($filename);
\r
190 * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a
\r
191 * warning on error.
\r
193 * @param $pgt the PGT
\r
194 * @param $pgt_iou the PGT iou
\r
198 function write($pgt,$pgt_iou)
\r
200 phpCAS::traceBegin();
\r
201 $fname = $this->getPGTIouFilename($pgt_iou);
\r
202 if ( $f=fopen($fname,"w") ) {
\r
203 if ( fputs($f,$pgt) === FALSE ) {
\r
204 phpCAS::error('could not write PGT to `'.$fname.'\'');
\r
208 phpCAS::error('could not open `'.$fname.'\'');
\r
210 phpCAS::traceEnd();
\r
214 * This method reads a PGT corresponding to a PGT Iou and deletes the
\r
215 * corresponding file.
\r
217 * @param $pgt_iou the PGT iou
\r
219 * @return the corresponding PGT, or FALSE on error
\r
223 function read($pgt_iou)
\r
225 phpCAS::traceBegin();
\r
227 $fname = $this->getPGTIouFilename($pgt_iou);
\r
228 if ( !($f=fopen($fname,"r")) ) {
\r
229 phpCAS::trace('could not open `'.$fname.'\'');
\r
231 if ( ($pgt=fgets($f)) === FALSE ) {
\r
232 phpCAS::trace('could not read PGT from `'.$fname.'\'');
\r
237 // delete the PGT file
\r
240 phpCAS::traceEnd($pgt);
\r