]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/extlib/CAS/PGTStorage/pgt-file.php
Removed unused stub class
[quix0rs-gnu-social.git] / plugins / CasAuthentication / extlib / CAS / PGTStorage / pgt-file.php
1 <?php
2
3 /**
4  * @file CAS/PGTStorage/pgt-file.php
5  * Basic class for PGT file storage
6  */
7
8 /**
9  * @class PGTStorageFile
10  * The PGTStorageFile class is a class for PGT file storage. An instance of 
11  * this class is returned by CASClient::SetPGTStorageFile().
12  *
13  * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
14  *
15  * @ingroup internalPGTStorageFile
16  */
17
18 class PGTStorageFile extends PGTStorage
19 {
20   /** 
21    * @addtogroup internalPGTStorageFile 
22    * @{ 
23    */
24
25   /**
26    * a string telling where PGT's should be stored on the filesystem. Written by
27    * PGTStorageFile::PGTStorageFile(), read by getPath().
28    *
29    * @private
30    */
31   var $_path;
32
33   /**
34    * This method returns the name of the directory where PGT's should be stored 
35    * on the filesystem.
36    *
37    * @return the name of a directory (with leading and trailing '/')
38    *
39    * @private
40    */
41   function getPath()
42     {
43       return $this->_path;
44     }
45
46   /**
47    * a string telling the format to use to store PGT's (plain or xml). Written by
48    * PGTStorageFile::PGTStorageFile(), read by getFormat().
49    *
50    * @private
51    */
52   var $_format;
53
54   /**
55    * This method returns the format to use when storing PGT's on the filesystem.
56    *
57    * @return a string corresponding to the format used (plain or xml).
58    *
59    * @private
60    */
61   function getFormat()
62     {
63       return $this->_format;
64     }
65
66   // ########################################################################
67   //  DEBUGGING
68   // ########################################################################
69   
70   /**
71    * This method returns an informational string giving the type of storage
72    * used by the object (used for debugging purposes).
73    *
74    * @return an informational string.
75    * @public
76    */
77   function getStorageType()
78     {
79       return "file";
80     }
81
82   /**
83    * This method returns an informational string giving informations on the
84    * parameters of the storage.(used for debugging purposes).
85    *
86    * @return an informational string.
87    * @public
88    */
89   function getStorageInfo()
90     {
91       return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';
92     }
93
94   // ########################################################################
95   //  CONSTRUCTOR
96   // ########################################################################
97   
98   /**
99    * The class constructor, called by CASClient::SetPGTStorageFile().
100    *
101    * @param $cas_parent the CASClient instance that creates the object.
102    * @param $format the format used to store the PGT's (`plain' and `xml' allowed).
103    * @param $path the path where the PGT's should be stored
104    *
105    * @public
106    */
107   function PGTStorageFile($cas_parent,$format,$path)
108     {
109       phpCAS::traceBegin();
110       // call the ancestor's constructor
111       $this->PGTStorage($cas_parent);
112
113       if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;
114       if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH;
115
116       // check that the path is an absolute path
117       if (getenv("OS")=="Windows_NT"){
118         
119          if (!preg_match('`^[a-zA-Z]:`', $path)) {
120                 phpCAS::error('an absolute path is needed for PGT storage to file');
121         }
122         
123       }
124       else
125       {
126       
127         if ( $path[0] != '/' ) {
128                         phpCAS::error('an absolute path is needed for PGT storage to file');
129         }
130
131         // store the path (with a leading and trailing '/')      
132         $path = preg_replace('|[/]*$|','/',$path);
133         $path = preg_replace('|^[/]*|','/',$path);
134       }
135       
136       $this->_path = $path;
137       // check the format and store it
138       switch ($format) {
139       case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN:
140       case CAS_PGT_STORAGE_FILE_FORMAT_XML:
141         $this->_format = $format;
142         break;
143       default:
144         phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');
145       }
146       phpCAS::traceEnd();      
147     }
148
149   // ########################################################################
150   //  INITIALIZATION
151   // ########################################################################
152   
153   /**
154    * This method is used to initialize the storage. Halts on error.
155    *
156    * @public
157    */
158   function init()
159     {
160       phpCAS::traceBegin();
161       // if the storage has already been initialized, return immediatly
162       if ( $this->isInitialized() )
163         return;
164       // call the ancestor's method (mark as initialized)
165       parent::init();
166       phpCAS::traceEnd();      
167     }
168
169   // ########################################################################
170   //  PGT I/O
171   // ########################################################################
172
173   /**
174    * This method returns the filename corresponding to a PGT Iou.
175    *
176    * @param $pgt_iou the PGT iou.
177    *
178    * @return a filename
179    * @private
180    */
181   function getPGTIouFilename($pgt_iou)
182     {
183       phpCAS::traceBegin();
184       $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();
185       phpCAS::traceEnd($filename);
186       return $filename;
187     }
188   
189   /**
190    * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a
191    * warning on error.
192    *
193    * @param $pgt the PGT
194    * @param $pgt_iou the PGT iou
195    *
196    * @public
197    */
198   function write($pgt,$pgt_iou)
199     {
200       phpCAS::traceBegin();
201       $fname = $this->getPGTIouFilename($pgt_iou);
202       if ( $f=fopen($fname,"w") ) {
203         if ( fputs($f,$pgt) === FALSE ) {
204           phpCAS::error('could not write PGT to `'.$fname.'\'');
205         }
206         fclose($f);
207       } else {
208         phpCAS::error('could not open `'.$fname.'\'');
209       }
210       phpCAS::traceEnd();      
211     }
212
213   /**
214    * This method reads a PGT corresponding to a PGT Iou and deletes the 
215    * corresponding file.
216    *
217    * @param $pgt_iou the PGT iou
218    *
219    * @return the corresponding PGT, or FALSE on error
220    *
221    * @public
222    */
223   function read($pgt_iou)
224     {
225       phpCAS::traceBegin();
226       $pgt = FALSE;
227       $fname = $this->getPGTIouFilename($pgt_iou);
228       if ( !($f=fopen($fname,"r")) ) {
229         phpCAS::trace('could not open `'.$fname.'\'');
230       } else {
231         if ( ($pgt=fgets($f)) === FALSE ) {
232           phpCAS::trace('could not read PGT from `'.$fname.'\'');
233         } 
234         fclose($f);
235       }
236
237       // delete the PGT file
238       @unlink($fname);
239
240       phpCAS::traceEnd($pgt);
241       return $pgt;
242     }
243   
244   /** @} */
245   
246 }
247
248   
249 ?>