Go to the documentation of this file.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 CAS_PGTStorage_File extends CAS_PGTStorage_AbstractStorage
00046 {
00058 var $_path;
00059
00068 function getPath()
00069 {
00070 return $this->_path;
00071 }
00072
00073
00074
00075
00076
00084 function getStorageType()
00085 {
00086 return "file";
00087 }
00088
00096 function getStorageInfo()
00097 {
00098 return 'path=`'.$this->getPath().'\'';
00099 }
00100
00101
00102
00103
00104
00113 function __construct($cas_parent,$path)
00114 {
00115 phpCAS::traceBegin();
00116
00117 parent::__construct($cas_parent);
00118
00119 if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH;
00120
00121 if (getenv("OS")=="Windows_NT"){
00122
00123 if (!preg_match('`^[a-zA-Z]:`', $path)) {
00124 phpCAS::error('an absolute path is needed for PGT storage to file');
00125 }
00126
00127 }
00128 else
00129 {
00130
00131 if ( $path[0] != '/' ) {
00132 phpCAS::error('an absolute path is needed for PGT storage to file');
00133 }
00134
00135
00136 $path = preg_replace('|[/]*$|','/',$path);
00137 $path = preg_replace('|^[/]*|','/',$path);
00138 }
00139
00140 $this->_path = $path;
00141 phpCAS::traceEnd();
00142 }
00143
00144
00145
00146
00147
00153 function init()
00154 {
00155 phpCAS::traceBegin();
00156
00157 if ( $this->isInitialized() )
00158 return;
00159
00160 parent::init();
00161 phpCAS::traceEnd();
00162 }
00163
00164
00165
00166
00167
00176 function getPGTIouFilename($pgt_iou)
00177 {
00178 phpCAS::traceBegin();
00179 $filename = $this->getPath().$pgt_iou.'.plain';
00180 phpCAS::traceEnd($filename);
00181 return $filename;
00182 }
00183
00193 function write($pgt,$pgt_iou)
00194 {
00195 phpCAS::traceBegin();
00196 $fname = $this->getPGTIouFilename($pgt_iou);
00197 if(!file_exists($fname)){
00198 if ($f=fopen($fname,"w") ) {
00199 if ( fputs($f,$pgt) === FALSE ) {
00200 phpCAS::error('could not write PGT to `'.$fname.'\'');
00201 }
00202 fclose($f);
00203 } else {
00204 phpCAS::error('could not open `'.$fname.'\'');
00205 }
00206 }else{
00207 phpCAS::error('File exists: `'.$fname.'\'');
00208 }
00209 phpCAS::traceEnd();
00210 }
00211
00222 function read($pgt_iou)
00223 {
00224 phpCAS::traceBegin();
00225 $pgt = FALSE;
00226 $fname = $this->getPGTIouFilename($pgt_iou);
00227 if (file_exists($fname)){
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 }else{
00240 phpCAS::trace('No such file `'.$fname.'\'');
00241 }
00242 phpCAS::traceEnd($pgt);
00243 return $pgt;
00244 }
00245
00248 }
00249
00250
00251 ?>