ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
pgt-file.php
Go to the documentation of this file.
1 <?php
2 
18 class PGTStorageFile extends PGTStorage
19 {
31  var $_path;
32 
41  function getPath()
42  {
43  return $this->_path;
44  }
45 
52  var $_format;
53 
61  function getFormat()
62  {
63  return $this->_format;
64  }
65 
66  // ########################################################################
67  // DEBUGGING
68  // ########################################################################
69 
77  function getStorageType()
78  {
79  return "file";
80  }
81 
89  function getStorageInfo()
90  {
91  return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';
92  }
93 
94  // ########################################################################
95  // CONSTRUCTOR
96  // ########################################################################
97 
107  function PGTStorageFile($cas_parent,$format,$path)
108  {
110  // call the ancestor's constructor
111  $this->PGTStorage($cas_parent);
112 
113  if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
115 
116  // check that the path is an absolute path
117  if ( $path[0] != '/' ) {
118  phpCAS::error('an absolute path is needed for PGT storage to file');
119  }
120 
121  // store the path (with a leading and trailing '/')
122  $path = preg_replace('|[/]*$|','/',$path);
123  $path = preg_replace('|^[/]*|','/',$path);
124  $this->_path = $path;
125 
126  // check the format and store it
127  switch ($format) {
130  $this->_format = $format;
131  break;
132  default:
133  phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
134  }
135  phpCAS::traceEnd();
136  }
137 
138  // ########################################################################
139  // INITIALIZATION
140  // ########################################################################
141 
147  function init()
148  {
150  // if the storage has already been initialized, return immediatly
151  if ( $this->isInitialized() )
152  return;
153  // call the ancestor's method (mark as initialized)
154  parent::init();
155  phpCAS::traceEnd();
156  }
157 
158  // ########################################################################
159  // PGT I/O
160  // ########################################################################
161 
170  function getPGTIouFilename($pgt_iou)
171  {
173  return $this->getPath().$pgt_iou.'.'.$this->getFormat();
174  phpCAS::traceEnd();
175  }
176 
186  function write($pgt,$pgt_iou)
187  {
189  $fname = $this->getPGTIouFilename($pgt_iou);
190  if ( $f=fopen($fname,"w") ) {
191  if ( fputs($f,$pgt) === FALSE ) {
192  phpCAS::error('could not write PGT to `'.$fname.'\'');
193  }
194  fclose($f);
195  } else {
196  phpCAS::error('could not open `'.$fname.'\'');
197  }
198  phpCAS::traceEnd();
199  }
200 
211  function read($pgt_iou)
212  {
214  $pgt = FALSE;
215  $fname = $this->getPGTIouFilename($pgt_iou);
216  if ( !($f=fopen($fname,"r")) ) {
217  phpCAS::trace('could not open `'.$fname.'\'');
218  } else {
219  if ( ($pgt=fgets($f)) === FALSE ) {
220  phpCAS::trace('could not read PGT from `'.$fname.'\'');
221  }
222  fclose($f);
223  }
224 
225  // delete the PGT file
226  @unlink($fname);
227 
228  phpCAS::traceEnd($pgt);
229  return $pgt;
230  }
231 
234 }
235 
236 
237 ?>
const CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT
Default format used when storing PGT&#39;s to file.
Definition: CAS.php:161
getStorageInfo()
This method returns an informational string giving informations on the parameters of the storage...
Definition: pgt-file.php:89
getPath()
This method returns the name of the directory where PGT&#39;s should be stored on the filesystem...
Definition: pgt-file.php:41
getStorageType()
This method returns an informational string giving the type of storage used by the object (used for d...
Definition: pgt-file.php:77
init()
This method is used to initialize the storage.
Definition: pgt-file.php:147
const CAS_PGT_STORAGE_FILE_DEFAULT_PATH
Default path used when storing PGT&#39;s to file.
Definition: CAS.php:149
getPath()
This method returns the name of the directory where PGT&#39;s should be stored on the filesystem...
Definition: pgt-file.php:68
read($pgt_iou)
This method reads a PGT corresponding to a PGT Iou and deletes the corresponding file.
Definition: pgt-file.php:211
write($pgt, $pgt_iou)
This method stores a PGT and its corresponding PGT Iou into a file.
Definition: pgt-file.php:186
$_path
a string telling where PGT&#39;s should be stored on the filesystem.
Definition: pgt-file.php:58
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:604
getPGTIouFilename($pgt_iou)
This method returns the filename corresponding to a PGT Iou.
Definition: pgt-file.php:170
getFormat()
This method returns the format to use when storing PGT&#39;s on the filesystem.
Definition: pgt-file.php:88
The PGTStorageFile class is a class for PGT file storage.
Definition: pgt-file.php:45
const CAS_PGT_STORAGE_FILE_FORMAT_XML
phpCAS::setPGTStorageFile()&#39;s 2nd parameter to write xml files
Definition: CAS.php:157
PGTStorage($cas_parent)
The constructor of the class, should be called only by inherited classes.
Definition: pgt-main.php:63
getPGTIouFilename($pgt_iou)
This method returns the filename corresponding to a PGT Iou.
Definition: pgt-file.php:208
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:577
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:544
trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:569
getFormat()
This method returns the format to use when storing PGT&#39;s on the filesystem.
Definition: pgt-file.php:61
$path
Definition: index.php:22
const CAS_PGT_STORAGE_FILE_FORMAT_PLAIN
phpCAS::setPGTStorageFile()&#39;s 2nd parameter to write plain text files
Definition: CAS.php:153
PGTStorageFile($cas_parent, $format, $path)
The class constructor, called by CASClient::SetPGTStorageFile().
Definition: pgt-file.php:107
isInitialized()
This method tells if the storage has already been intialized.
Definition: pgt-main.php:160
The PGTStorage class is a generic class for PGT storage.
Definition: pgt-main.php:45
$_format
a string telling the format to use to store PGT&#39;s (plain or xml).
Definition: pgt-file.php:79