phpCAS
version 1.4.0
CAS
PGTStorage
File.php
Go to the documentation of this file.
1
<?php
2
45
class
CAS_PGTStorage_File
extends
CAS_PGTStorage_AbstractStorage
46
{
58
var
$_path
;
59
68
function
getPath
()
69
{
70
return
$this->_path
;
71
}
72
73
// ########################################################################
74
// DEBUGGING
75
// ########################################################################
76
84
function
getStorageType
()
85
{
86
return
"file"
;
87
}
88
96
function
getStorageInfo
()
97
{
98
return
'path=`'
.$this->getPath().
'\''
;
99
}
100
101
// ########################################################################
102
// CONSTRUCTOR
103
// ########################################################################
104
115
function
__construct
($cas_parent,$path)
116
{
117
phpCAS::traceBegin
();
118
// call the ancestor's constructor
119
parent::__construct($cas_parent);
120
121
if
(empty($path)) {
122
$path =
CAS_PGT_STORAGE_FILE_DEFAULT_PATH
;
123
}
124
// check that the path is an absolute path
125
if
(getenv(
"OS"
)==
"Windows_NT"
|| strtoupper(substr(PHP_OS,0,3)) ==
'WIN'
) {
126
127
if
(!preg_match(
'`^[a-zA-Z]:`'
, $path)) {
128
phpCAS::error
(
'an absolute path is needed for PGT storage to file'
);
129
}
130
131
}
else
{
132
133
if
( $path[0] !=
'/'
) {
134
phpCAS::error
(
'an absolute path is needed for PGT storage to file'
);
135
}
136
137
// store the path (with a leading and trailing '/')
138
$path = preg_replace(
'|[/]*$|'
,
'/'
, $path);
139
$path = preg_replace(
'|^[/]*|'
,
'/'
, $path);
140
}
141
142
$this->_path = $path;
143
phpCAS::traceEnd
();
144
}
145
146
// ########################################################################
147
// INITIALIZATION
148
// ########################################################################
149
156
function
init
()
157
{
158
phpCAS::traceBegin
();
159
// if the storage has already been initialized, return immediatly
160
if
($this->
isInitialized
()) {
161
return
;
162
}
163
// call the ancestor's method (mark as initialized)
164
parent::init();
165
phpCAS::traceEnd
();
166
}
167
168
// ########################################################################
169
// PGT I/O
170
// ########################################################################
171
180
function
getPGTIouFilename
($pgt_iou)
181
{
182
phpCAS::traceBegin
();
183
$filename = $this->
getPath
().
"phpcas-"
.hash(
"sha256"
, $pgt_iou);
184
// $filename = $this->getPath().$pgt_iou.'.plain';
185
phpCAS::trace
(
"Sha256 filename:"
. $filename);
186
phpCAS::traceEnd
();
187
return
$filename;
188
}
189
201
function
write
($pgt,$pgt_iou)
202
{
203
phpCAS::traceBegin
();
204
$fname = $this->
getPGTIouFilename
($pgt_iou);
205
if
(!file_exists($fname)) {
206
touch($fname);
207
// Chmod will fail on windows
208
@chmod($fname, 0600);
209
if
($f=fopen($fname,
"w"
)) {
210
if
(fputs($f, $pgt) ===
false
) {
211
phpCAS::error
(
'could not write PGT to `'
.$fname.
'\''
);
212
}
213
phpCAS::trace
(
'Successful write of PGT to `'
.$fname.
'\''
);
214
fclose($f);
215
}
else
{
216
phpCAS::error
(
'could not open `'
.$fname.
'\''
);
217
}
218
}
else
{
219
phpCAS::error
(
'File exists: `'
.$fname.
'\''
);
220
}
221
phpCAS::traceEnd
();
222
}
223
234
function
read
($pgt_iou)
235
{
236
phpCAS::traceBegin
();
237
$pgt =
false
;
238
$fname = $this->
getPGTIouFilename
($pgt_iou);
239
if
(file_exists($fname)) {
240
if
(!($f=fopen($fname,
"r"
))) {
241
phpCAS::error
(
'could not open `'
.$fname.
'\''
);
242
}
else
{
243
if
(($pgt=fgets($f)) ===
false
) {
244
phpCAS::error
(
'could not read PGT from `'
.$fname.
'\''
);
245
}
246
phpCAS::trace
(
'Successful read of PGT to `'
.$fname.
'\''
);
247
fclose($f);
248
}
249
// delete the PGT file
250
@unlink($fname);
251
}
else
{
252
phpCAS::error
(
'No such file `'
.$fname.
'\''
);
253
}
254
phpCAS::traceEnd
($pgt);
255
return
$pgt;
256
}
257
260
}
261
?>
CAS_PGTStorage_File\getStorageType
getStorageType()
Definition:
File.php:84
CAS_PGTStorage_File\__construct
__construct($cas_parent, $path)
Definition:
File.php:115
phpCAS\error
static error($msg)
Definition:
CAS.php:580
CAS_PGT_STORAGE_FILE_DEFAULT_PATH
const CAS_PGT_STORAGE_FILE_DEFAULT_PATH
Definition:
CAS.php:155
CAS_PGTStorage_File\read
read($pgt_iou)
Definition:
File.php:234
CAS_PGTStorage_AbstractStorage\isInitialized
isInitialized()
Definition:
AbstractStorage.php:168
phpCAS\traceEnd
static traceEnd($res='')
Definition:
CAS.php:675
CAS_PGTStorage_File
Definition:
File.php:45
phpCAS\trace
static trace($str)
Definition:
CAS.php:616
CAS_PGTStorage_File\write
write($pgt, $pgt_iou)
Definition:
File.php:201
CAS_PGTStorage_AbstractStorage
Definition:
AbstractStorage.php:46
CAS_PGTStorage_File\init
init()
Definition:
File.php:156
CAS_PGTStorage_File\getPath
getPath()
Definition:
File.php:68
CAS_PGTStorage_File\getStorageInfo
getStorageInfo()
Definition:
File.php:96
CAS_PGTStorage_File\$_path
$_path
Definition:
File.php:58
phpCAS\traceBegin
static traceBegin()
Definition:
CAS.php:628
CAS_PGTStorage_File\getPGTIouFilename
getPGTIouFilename($pgt_iou)
Definition:
File.php:180
Generated by
1.8.13