00001 <?php
00002
00018 class PGTStorageFile extends PGTStorage
00019 {
00031 var $_path;
00032
00041 function getPath()
00042 {
00043 return $this->_path;
00044 }
00045
00052 var $_format;
00053
00061 function getFormat()
00062 {
00063 return $this->_format;
00064 }
00065
00066
00067
00068
00069
00077 function getStorageType()
00078 {
00079 return "file";
00080 }
00081
00089 function getStorageInfo()
00090 {
00091 return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';
00092 }
00093
00094
00095
00096
00097
00107 function PGTStorageFile($cas_parent,$format,$path)
00108 {
00109 phpCAS::traceBegin();
00110
00111 $this->PGTStorage($cas_parent);
00112
00113 if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
00114 if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH;
00115
00116
00117 if (getenv("OS")=="Windows_NT"){
00118
00119 if (!preg_match('`^[a-zA-Z]:`', $path)) {
00120 phpCAS::error('an absolute path is needed for PGT storage to file');
00121 }
00122
00123 }
00124 else
00125 {
00126
00127 if ( $path[0] != '/' ) {
00128 phpCAS::error('an absolute path is needed for PGT storage to file');
00129 }
00130
00131
00132 $path = preg_replace('|[/]*$|','/',$path);
00133 $path = preg_replace('|^[/]*|','/',$path);
00134 }
00135
00136 $this->_path = $path;
00137
00138 switch ($format) {
00139 case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN:
00140 case CAS_PGT_STORAGE_FILE_FORMAT_XML:
00141 $this->_format = $format;
00142 break;
00143 default:
00144 phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
00145 }
00146 phpCAS::traceEnd();
00147 }
00148
00149
00150
00151
00152
00158 function init()
00159 {
00160 phpCAS::traceBegin();
00161
00162 if ( $this->isInitialized() )
00163 return;
00164
00165 parent::init();
00166 phpCAS::traceEnd();
00167 }
00168
00169
00170
00171
00172
00181 function getPGTIouFilename($pgt_iou)
00182 {
00183 phpCAS::traceBegin();
00184 $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();
00185 phpCAS::traceEnd($filename);
00186 return $filename;
00187 }
00188
00198 function write($pgt,$pgt_iou)
00199 {
00200 phpCAS::traceBegin();
00201 $fname = $this->getPGTIouFilename($pgt_iou);
00202 if ( $f=fopen($fname,"w") ) {
00203 if ( fputs($f,$pgt) === FALSE ) {
00204 phpCAS::error('could not write PGT to `'.$fname.'\'');
00205 }
00206 fclose($f);
00207 } else {
00208 phpCAS::error('could not open `'.$fname.'\'');
00209 }
00210 phpCAS::traceEnd();
00211 }
00212
00223 function read($pgt_iou)
00224 {
00225 phpCAS::traceBegin();
00226 $pgt = FALSE;
00227 $fname = $this->getPGTIouFilename($pgt_iou);
00228 if ( !($f=fopen($fname,"r")) ) {
00229 phpCAS::trace('could not open `'.$fname.'\'');
00230 } else {
00231 if ( ($pgt=fgets($f)) === FALSE ) {
00232 phpCAS::trace('could not read PGT from `'.$fname.'\'');
00233 }
00234 fclose($f);
00235 }
00236
00237
00238 @unlink($fname);
00239
00240 phpCAS::traceEnd($pgt);
00241 return $pgt;
00242 }
00243
00246 }
00247
00248
00249 ?>