• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/CAS/phpcas/source/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       return $this->getPath().$pgt_iou.'.'.$this->getFormat();
00174       phpCAS::traceEnd();      
00175     }
00176   
00186   function write($pgt,$pgt_iou)
00187     {
00188       phpCAS::traceBegin();
00189       $fname = $this->getPGTIouFilename($pgt_iou);
00190       if ( $f=fopen($fname,"w") ) {
00191         if ( fputs($f,$pgt) === FALSE ) {
00192           phpCAS::error('could not write PGT to `'.$fname.'\'');
00193         }
00194         fclose($f);
00195       } else {
00196         phpCAS::error('could not open `'.$fname.'\'');
00197       }
00198       phpCAS::traceEnd();      
00199     }
00200 
00211   function read($pgt_iou)
00212     {
00213       phpCAS::traceBegin();
00214       $pgt = FALSE;
00215       $fname = $this->getPGTIouFilename($pgt_iou);
00216       if ( !($f=fopen($fname,"r")) ) {
00217         phpCAS::trace('could not open `'.$fname.'\'');
00218       } else {
00219         if ( ($pgt=fgets($f)) === FALSE ) {
00220           phpCAS::trace('could not read PGT from `'.$fname.'\'');
00221         } 
00222         fclose($f);
00223       }
00224 
00225       // delete the PGT file
00226       @unlink($fname);
00227 
00228       phpCAS::traceEnd($pgt);
00229       return $pgt;
00230     }
00231   
00234 }
00235 
00236   
00237 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1