CAS/PGTStorage/pgt-file.php

Go to the documentation of this file.
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   //  DEBUGGING
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   //  CONSTRUCTOR
00096   // ########################################################################
00097   
00107   function PGTStorageFile($cas_parent,$format,$path)
00108     {
00109       phpCAS::traceBegin();
00110       // call the ancestor's constructor
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       // check that the path is an absolute path
00117       if ( $path[0] != '/' ) {
00118         phpCAS::error('an absolute path is needed for PGT storage to file');
00119       }
00120 
00121       // store the path (with a leading and trailing '/')      
00122       $path = preg_replace('|[/]*$|','/',$path);
00123       $path = preg_replace('|^[/]*|','/',$path);
00124       $this->_path = $path;
00125 
00126       // check the format and store it
00127       switch ($format) {
00128       case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN:
00129       case CAS_PGT_STORAGE_FILE_FORMAT_XML:
00130         $this->_format = $format;
00131         break;
00132       default:
00133         phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
00134       }
00135       phpCAS::traceEnd();      
00136     }
00137 
00138   // ########################################################################
00139   //  INITIALIZATION
00140   // ########################################################################
00141   
00147   function init()
00148     {
00149       phpCAS::traceBegin();
00150       // if the storage has already been initialized, return immediatly
00151       if ( $this->isInitialized() )
00152         return;
00153       // call the ancestor's method (mark as initialized)
00154       parent::init();
00155       phpCAS::traceEnd();      
00156     }
00157 
00158   // ########################################################################
00159   //  PGT I/O
00160   // ########################################################################
00161 
00170   function getPGTIouFilename($pgt_iou)
00171     {
00172       phpCAS::traceBegin();
00173       $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();
00174       phpCAS::traceEnd($filename);
00175       return $filename;
00176     }
00177   
00187   function write($pgt,$pgt_iou)
00188     {
00189       phpCAS::traceBegin();
00190       $fname = $this->getPGTIouFilename($pgt_iou);
00191       if ( $f=fopen($fname,"w") ) {
00192         if ( fputs($f,$pgt) === FALSE ) {
00193           phpCAS::error('could not write PGT to `'.$fname.'\'');
00194         }
00195         fclose($f);
00196       } else {
00197         phpCAS::error('could not open `'.$fname.'\'');
00198       }
00199       phpCAS::traceEnd();      
00200     }
00201 
00212   function read($pgt_iou)
00213     {
00214       phpCAS::traceBegin();
00215       $pgt = FALSE;
00216       $fname = $this->getPGTIouFilename($pgt_iou);
00217       if ( !($f=fopen($fname,"r")) ) {
00218         phpCAS::trace('could not open `'.$fname.'\'');
00219       } else {
00220         if ( ($pgt=fgets($f)) === FALSE ) {
00221           phpCAS::trace('could not read PGT from `'.$fname.'\'');
00222         } 
00223         fclose($f);
00224       }
00225 
00226       // delete the PGT file
00227       @unlink($fname);
00228 
00229       phpCAS::traceEnd($pgt);
00230       return $pgt;
00231     }
00232   
00235 }
00236 
00237   
00238 ?>

Generated on Wed Mar 14 14:55:56 2007 for phpCAS by  doxygen 1.5.0