00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00045 class PGTStorageFile extends PGTStorage
00046 {
00058 var $_path;
00059
00068 function getPath()
00069 {
00070 return $this->_path;
00071 }
00072
00079 var $_format;
00080
00088 function getFormat()
00089 {
00090 return $this->_format;
00091 }
00092
00093
00094
00095
00096
00104 function getStorageType()
00105 {
00106 return "file";
00107 }
00108
00116 function getStorageInfo()
00117 {
00118 return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';
00119 }
00120
00121
00122
00123
00124
00134 function PGTStorageFile($cas_parent,$format,$path)
00135 {
00136 phpCAS::traceBegin();
00137
00138 $this->PGTStorage($cas_parent);
00139
00140 if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
00141 if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH;
00142
00143
00144 if (getenv("OS")=="Windows_NT"){
00145
00146 if (!preg_match('`^[a-zA-Z]:`', $path)) {
00147 phpCAS::error('an absolute path is needed for PGT storage to file');
00148 }
00149
00150 }
00151 else
00152 {
00153
00154 if ( $path[0] != '/' ) {
00155 phpCAS::error('an absolute path is needed for PGT storage to file');
00156 }
00157
00158
00159 $path = preg_replace('|[/]*$|','/',$path);
00160 $path = preg_replace('|^[/]*|','/',$path);
00161 }
00162
00163 $this->_path = $path;
00164
00165 switch ($format) {
00166 case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN:
00167 case CAS_PGT_STORAGE_FILE_FORMAT_XML:
00168 $this->_format = $format;
00169 break;
00170 default:
00171 phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
00172 }
00173 phpCAS::traceEnd();
00174 }
00175
00176
00177
00178
00179
00185 function init()
00186 {
00187 phpCAS::traceBegin();
00188
00189 if ( $this->isInitialized() )
00190 return;
00191
00192 parent::init();
00193 phpCAS::traceEnd();
00194 }
00195
00196
00197
00198
00199
00208 function getPGTIouFilename($pgt_iou)
00209 {
00210 phpCAS::traceBegin();
00211 $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();
00212 phpCAS::traceEnd($filename);
00213 return $filename;
00214 }
00215
00225 function write($pgt,$pgt_iou)
00226 {
00227 phpCAS::traceBegin();
00228 $fname = $this->getPGTIouFilename($pgt_iou);
00229 if ( $f=fopen($fname,"w") ) {
00230 if ( fputs($f,$pgt) === FALSE ) {
00231 phpCAS::error('could not write PGT to `'.$fname.'\'');
00232 }
00233 fclose($f);
00234 } else {
00235 phpCAS::error('could not open `'.$fname.'\'');
00236 }
00237 phpCAS::traceEnd();
00238 }
00239
00250 function read($pgt_iou)
00251 {
00252 phpCAS::traceBegin();
00253 $pgt = FALSE;
00254 $fname = $this->getPGTIouFilename($pgt_iou);
00255 if ( !($f=fopen($fname,"r")) ) {
00256 phpCAS::trace('could not open `'.$fname.'\'');
00257 } else {
00258 if ( ($pgt=fgets($f)) === FALSE ) {
00259 phpCAS::trace('could not read PGT from `'.$fname.'\'');
00260 }
00261 fclose($f);
00262 }
00263
00264
00265 @unlink($fname);
00266
00267 phpCAS::traceEnd($pgt);
00268 return $pgt;
00269 }
00270
00273 }
00274
00275
00276 ?>