ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
InternalCAS_PGTStorageDb

Functions

 CAS_PGTStorage_Db::_getPdo ()
 This method returns the PDO object to use for database interactions. More...
 
 CAS_PGTStorage_Db::_getTable ()
 This method returns the table to use when storing/retrieving PGT's. More...
 
 CAS_PGTStorage_Db::getStorageType ()
 This method returns an informational string giving the type of storage used by the object (used for debugging purposes). More...
 
 CAS_PGTStorage_Db::getStorageInfo ()
 This method returns an informational string giving informations on the parameters of the storage. More...
 
 CAS_PGTStorage_Db::__construct ( $cas_parent, $dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
 The class constructor. More...
 
 CAS_PGTStorage_Db::init ()
 This method is used to initialize the storage. More...
 
 CAS_PGTStorage_Db::_setErrorMode ()
 This method will enable the Exception error mode on the PDO object. More...
 
 CAS_PGTStorage_Db::_resetErrorMode ()
 this method will reset the error mode on the PDO object More...
 
 CAS_PGTStorage_Db::createTableSql ()
 This method returns the query used to create a pgt storage table. More...
 
 CAS_PGTStorage_Db::storePgtSql ()
 This method returns the query used to store a pgt. More...
 
 CAS_PGTStorage_Db::retrievePgtSql ()
 This method returns the query used to retrieve a pgt. More...
 
 CAS_PGTStorage_Db::deletePgtSql ()
 This method returns the query used to delete a pgt. More...
 
 CAS_PGTStorage_Db::createTable ()
 This method creates the database table used to store pgt's and pgtiou's. More...
 
 CAS_PGTStorage_Db::write ($pgt, $pgt_iou)
 This method stores a PGT and its corresponding PGT Iou in the database. More...
 
 CAS_PGTStorage_Db::read ($pgt_iou)
 This method reads a PGT corresponding to a PGT Iou and deletes the corresponding db entry. More...
 

Variables

 CAS_PGTStorage_Db::$_pdo
 the PDO object to use for database interactions More...
 
 CAS_PGTStorage_Db::$_dsn
 database connection options to use when creating a new PDO object More...
 
 CAS_PGTStorage_Db::$_username
 
 CAS_PGTStorage_Db::$_password
 
 CAS_PGTStorage_Db::$_table_options
 
 CAS_PGTStorage_Db::$_table
 the table to use for storing/retrieving pgt's More...
 
 CAS_PGTStorage_Db::$_errMode
 attribute that stores the previous error mode for the PDO handle while processing a transaction More...
 

Detailed Description

Function Documentation

◆ __construct()

CAS_PGTStorage_Db::__construct (   $cas_parent,
  $dsn_or_pdo,
  $username = '',
  $password = '',
  $table = '',
  $driver_options = null 
)

The class constructor.

Parameters
CAS_Client$cas_parentthe CAS_Client instance that creates the object.
string$dsn_or_pdoa dsn string to use for creating a PDO object or a PDO object
string$usernamethe username to use when connecting to the database
string$passwordthe password to use when connecting to the database
string$tablethe table to use for storing and retrieving PGT's
string$driver_optionsany driver options to use when connecting to the database

Definition at line 138 of file Db.php.

141 {
143 // call the ancestor's constructor
144 parent::__construct($cas_parent);
145
146 // set default values
147 if ( empty($table) ) {
149 }
150 if ( !is_array($driver_options) ) {
151 $driver_options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
152 }
153
154 // store the specified parameters
155 if ($dsn_or_pdo instanceof PDO) {
156 $this->_pdo = $dsn_or_pdo;
157 } else {
158 $this->_dsn = $dsn_or_pdo;
159 $this->_username = $username;
160 $this->_password = $password;
161 $this->_driver_options = $driver_options;
162 }
163
164 // store the table name
165 $this->_table = $table;
166
168 }
const CAS_PGT_STORAGE_DB_DEFAULT_TABLE
Definition: Db.php:30
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:638
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
Definition: CAS.php:591
$password
Definition: pwgen.php:17
if(empty($password)) $table
Definition: pwgen.php:24

References $password, $table, CAS_PGT_STORAGE_DB_DEFAULT_TABLE, phpCAS\traceBegin(), and phpCAS\traceEnd().

+ Here is the call graph for this function:

◆ _getPdo()

CAS_PGTStorage_Db::_getPdo ( )
private

This method returns the PDO object to use for database interactions.

Returns
the PDO object

Definition at line 63 of file Db.php.

64 {
65 return $this->_pdo;
66 }
$_pdo
the PDO object to use for database interactions
Definition: Db.php:56

References CAS_PGTStorage_Db\$_pdo.

Referenced by CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), CAS_PGTStorage_Db\createTable(), CAS_PGTStorage_Db\read(), and CAS_PGTStorage_Db\write().

+ Here is the caller graph for this function:

◆ _getTable()

CAS_PGTStorage_Db::_getTable ( )
private

This method returns the table to use when storing/retrieving PGT's.

Returns
the name of the pgt storage table.

Definition at line 86 of file Db.php.

87 {
88 return $this->_table;
89 }
$_table
the table to use for storing/retrieving pgt's
Definition: Db.php:79

References CAS_PGTStorage_Db\$_table.

Referenced by CAS_PGTStorage_Db\createTableSql(), CAS_PGTStorage_Db\deletePgtSql(), CAS_PGTStorage_Db\retrievePgtSql(), and CAS_PGTStorage_Db\storePgtSql().

+ Here is the caller graph for this function:

◆ _resetErrorMode()

CAS_PGTStorage_Db::_resetErrorMode ( )
private

this method will reset the error mode on the PDO object

Returns
void

Definition at line 234 of file Db.php.

235 {
236 // get PDO object and reset the error mode to what it was originally
237 $pdo = $this->_getPdo();
238 $pdo->setAttribute(PDO::ATTR_ERRMODE, $this->_errMode);
239 }
_getPdo()
This method returns the PDO object to use for database interactions.
Definition: Db.php:63

References CAS_PGTStorage_Db\_getPdo().

Referenced by CAS_PGTStorage_Db\createTable(), CAS_PGTStorage_Db\read(), and CAS_PGTStorage_Db\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _setErrorMode()

CAS_PGTStorage_Db::_setErrorMode ( )
private

This method will enable the Exception error mode on the PDO object.

Returns
void

Definition at line 221 of file Db.php.

222 {
223 // get PDO object and enable exception error mode
224 $pdo = $this->_getPdo();
225 $this->_errMode = $pdo->getAttribute(PDO::ATTR_ERRMODE);
226 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
227 }

References CAS_PGTStorage_Db\_getPdo().

Referenced by CAS_PGTStorage_Db\createTable(), CAS_PGTStorage_Db\read(), and CAS_PGTStorage_Db\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTable()

CAS_PGTStorage_Db::createTable ( )

This method creates the database table used to store pgt's and pgtiou's.

Returns
void

Definition at line 303 of file Db.php.

304 {
306
307 // initialize this PGTStorage object if it hasn't been initialized yet
308 if ( !$this->isInitialized() ) {
309 $this->init();
310 }
311
312 // initialize the PDO object for this method
313 $pdo = $this->_getPdo();
314 $this->_setErrorMode();
315
316 try {
317 $pdo->beginTransaction();
318
319 $query = $pdo->query($this->createTableSQL());
320 $query->closeCursor();
321
322 $pdo->commit();
323 }
324 catch(PDOException $e) {
325 // attempt rolling back the transaction before throwing a phpCAS error
326 try {
327 $pdo->rollBack();
328 }
329 catch(PDOException $e) {
330 }
331 phpCAS::error('error creating PGT storage table: ' . $e->getMessage());
332 }
333
334 // reset the PDO object
335 $this->_resetErrorMode();
336
338 }
_resetErrorMode()
this method will reset the error mode on the PDO object
Definition: Db.php:234
init()
This method is used to initialize the storage.
Definition: Db.php:179
_setErrorMode()
This method will enable the Exception error mode on the PDO object.
Definition: Db.php:221
isInitialized()
This method tells if the storage has already been intialized.
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:543
$query

References $query, CAS_PGTStorage_Db\_getPdo(), CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), phpCAS\error(), CAS_PGTStorage_Db\init(), CAS_PGTStorage_AbstractStorage\isInitialized(), phpCAS\traceBegin(), and phpCAS\traceEnd().

+ Here is the call graph for this function:

◆ createTableSql()

CAS_PGTStorage_Db::createTableSql ( )
protected

This method returns the query used to create a pgt storage table.

Returns
the create table SQL, no bind params in query

Definition at line 253 of file Db.php.

254 {
255 return 'CREATE TABLE ' . $this->_getTable()
256 . ' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)';
257 }
_getTable()
This method returns the table to use when storing/retrieving PGT's.
Definition: Db.php:86

References CAS_PGTStorage_Db\_getTable().

+ Here is the call graph for this function:

◆ deletePgtSql()

CAS_PGTStorage_Db::deletePgtSql ( )
protected

This method returns the query used to delete a pgt.

Returns
the delete PGT SQL, :pgt_iou is the only bind param contained in the query

Definition at line 289 of file Db.php.

290 {
291 return 'DELETE FROM ' . $this->_getTable() . ' WHERE pgt_iou = :pgt_iou';
292 }

References CAS_PGTStorage_Db\_getTable().

Referenced by CAS_PGTStorage_Db\read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStorageInfo()

CAS_PGTStorage_Db::getStorageInfo ( )

This method returns an informational string giving informations on the parameters of the storage.

(used for debugging purposes).

Returns
an informational string.

Reimplemented from CAS_PGTStorage_AbstractStorage.

Definition at line 113 of file Db.php.

114 {
115 return 'table=`'.$this->_getTable().'\'';
116 }

◆ getStorageType()

CAS_PGTStorage_Db::getStorageType ( )

This method returns an informational string giving the type of storage used by the object (used for debugging purposes).

Returns
an informational string.

Reimplemented from CAS_PGTStorage_AbstractStorage.

Definition at line 101 of file Db.php.

102 {
103 return "db";
104 }

◆ init()

CAS_PGTStorage_Db::init ( )

This method is used to initialize the storage.

Halts on error.

Returns
void

Reimplemented from CAS_PGTStorage_AbstractStorage.

Definition at line 179 of file Db.php.

180 {
182 // if the storage has already been initialized, return immediatly
183 if ($this->isInitialized()) {
184 return;
185 }
186
187 // initialize the base object
188 parent::init();
189
190 // create the PDO object if it doesn't exist already
191 if (!($this->_pdo instanceof PDO)) {
192 try {
193 $this->_pdo = new PDO(
194 $this->_dsn, $this->_username, $this->_password,
195 $this->_driver_options
196 );
197 }
198 catch(PDOException $e) {
199 phpCAS::error('Database connection error: ' . $e->getMessage());
200 }
201 }
202
204 }

References phpCAS\error(), CAS_PGTStorage_AbstractStorage\isInitialized(), phpCAS\traceBegin(), and phpCAS\traceEnd().

Referenced by CAS_PGTStorage_Db\createTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

CAS_PGTStorage_Db::read (   $pgt_iou)

This method reads a PGT corresponding to a PGT Iou and deletes the corresponding db entry.

Parameters
string$pgt_iouthe PGT iou
Returns
the corresponding PGT, or FALSE on error

Reimplemented from CAS_PGTStorage_AbstractStorage.

Definition at line 392 of file Db.php.

393 {
395 $pgt = false;
396
397 // initialize the PDO object for this method
398 $pdo = $this->_getPdo();
399 $this->_setErrorMode();
400
401 try {
402 $pdo->beginTransaction();
403
404 // fetch the pgt for the specified pgt_iou
405 $query = $pdo->prepare($this->retrievePgtSql());
406 $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR);
407 $query->execute();
408 $pgt = $query->fetchColumn(0);
409 $query->closeCursor();
410
411 // delete the specified pgt_iou from the database
412 $query = $pdo->prepare($this->deletePgtSql());
413 $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR);
414 $query->execute();
415 $query->closeCursor();
416
417 $pdo->commit();
418 }
419 catch(PDOException $e) {
420 // attempt rolling back the transaction before throwing a phpCAS error
421 try {
422 $pdo->rollBack();
423 }
424 catch(PDOException $e) {
425 }
426 phpCAS::trace('error reading PGT from database: ' . $e->getMessage());
427 }
428
429 // reset the PDO object
430 $this->_resetErrorMode();
431
433 return $pgt;
434 }
retrievePgtSql()
This method returns the query used to retrieve a pgt.
Definition: Db.php:278
deletePgtSql()
This method returns the query used to delete a pgt.
Definition: Db.php:289
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:579

References $query, CAS_PGTStorage_Db\_getPdo(), CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), CAS_PGTStorage_Db\deletePgtSql(), CAS_PGTStorage_Db\retrievePgtSql(), phpCAS\trace(), phpCAS\traceBegin(), and phpCAS\traceEnd().

+ Here is the call graph for this function:

◆ retrievePgtSql()

CAS_PGTStorage_Db::retrievePgtSql ( )
protected

This method returns the query used to retrieve a pgt.

the first column of the first row should contain the pgt

Returns
the retrieve PGT SQL, :pgt_iou is the only bind param contained in the query

Definition at line 278 of file Db.php.

279 {
280 return 'SELECT pgt FROM ' . $this->_getTable() . ' WHERE pgt_iou = :pgt_iou';
281 }

References CAS_PGTStorage_Db\_getTable().

Referenced by CAS_PGTStorage_Db\read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storePgtSql()

CAS_PGTStorage_Db::storePgtSql ( )
protected

This method returns the query used to store a pgt.

Returns
the store PGT SQL, :pgt and :pgt_iou are the bind params contained in the query

Definition at line 265 of file Db.php.

266 {
267 return 'INSERT INTO ' . $this->_getTable()
268 . ' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)';
269 }

References CAS_PGTStorage_Db\_getTable().

Referenced by CAS_PGTStorage_Db\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

CAS_PGTStorage_Db::write (   $pgt,
  $pgt_iou 
)

This method stores a PGT and its corresponding PGT Iou in the database.

Echoes a warning on error.

Parameters
string$pgtthe PGT
string$pgt_iouthe PGT iou
Returns
void

Reimplemented from CAS_PGTStorage_AbstractStorage.

Definition at line 349 of file Db.php.

350 {
352
353 // initialize the PDO object for this method
354 $pdo = $this->_getPdo();
355 $this->_setErrorMode();
356
357 try {
358 $pdo->beginTransaction();
359
360 $query = $pdo->prepare($this->storePgtSql());
361 $query->bindValue(':pgt', $pgt, PDO::PARAM_STR);
362 $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR);
363 $query->execute();
364 $query->closeCursor();
365
366 $pdo->commit();
367 }
368 catch(PDOException $e) {
369 // attempt rolling back the transaction before throwing a phpCAS error
370 try {
371 $pdo->rollBack();
372 }
373 catch(PDOException $e) {
374 }
375 phpCAS::error('error writing PGT to database: ' . $e->getMessage());
376 }
377
378 // reset the PDO object
379 $this->_resetErrorMode();
380
382 }
storePgtSql()
This method returns the query used to store a pgt.
Definition: Db.php:265

References $query, CAS_PGTStorage_Db\_getPdo(), CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), phpCAS\error(), CAS_PGTStorage_Db\storePgtSql(), phpCAS\traceBegin(), and phpCAS\traceEnd().

+ Here is the call graph for this function:

Variable Documentation

◆ $_dsn

CAS_PGTStorage_Db::$_dsn
private

database connection options to use when creating a new PDO object

Definition at line 71 of file Db.php.

◆ $_errMode

CAS_PGTStorage_Db::$_errMode
private

attribute that stores the previous error mode for the PDO handle while processing a transaction

Definition at line 214 of file Db.php.

◆ $_password

CAS_PGTStorage_Db::$_password
private

Definition at line 73 of file Db.php.

◆ $_pdo

CAS_PGTStorage_Db::$_pdo
private

the PDO object to use for database interactions

Definition at line 56 of file Db.php.

Referenced by CAS_PGTStorage_Db\_getPdo().

◆ $_table

CAS_PGTStorage_Db::$_table
private

the table to use for storing/retrieving pgt's

Definition at line 79 of file Db.php.

Referenced by CAS_PGTStorage_Db\_getTable().

◆ $_table_options

CAS_PGTStorage_Db::$_table_options
private

Definition at line 74 of file Db.php.

◆ $_username

CAS_PGTStorage_Db::$_username
private

Definition at line 72 of file Db.php.