30define(
'CAS_PGT_STORAGE_DB_DEFAULT_TABLE',
'cas_pgts');
115 return 'table=`'.$this->_getTable().
'\'';
144 parent::__construct($cas_parent);
150 if ( !is_array($driver_options) ) {
151 $driver_options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
155 if ($dsn_or_pdo instanceof PDO) {
156 $this->_pdo = $dsn_or_pdo;
158 $this->_dsn = $dsn_or_pdo;
159 $this->_username = $username;
161 $this->_driver_options = $driver_options;
191 if (!($this->_pdo instanceof PDO)) {
193 $this->_pdo =
new PDO(
194 $this->_dsn, $this->_username, $this->_password,
195 $this->_driver_options
198 catch(PDOException $e) {
199 phpCAS::error(
'Database connection error: ' . $e->getMessage());
225 $this->_errMode = $pdo->getAttribute(PDO::ATTR_ERRMODE);
226 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
238 $pdo->setAttribute(PDO::ATTR_ERRMODE, $this->_errMode);
255 return 'CREATE TABLE ' . $this->
_getTable()
256 .
' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)';
267 return 'INSERT INTO ' . $this->
_getTable()
268 .
' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)';
280 return 'SELECT pgt FROM ' . $this->
_getTable() .
' WHERE pgt_iou = :pgt_iou';
291 return 'DELETE FROM ' . $this->
_getTable() .
' WHERE pgt_iou = :pgt_iou';
317 $pdo->beginTransaction();
319 $query = $pdo->query($this->createTableSQL());
324 catch(PDOException $e) {
329 catch(PDOException $e) {
331 phpCAS::error(
'error creating PGT storage table: ' . $e->getMessage());
349 public function write($pgt, $pgt_iou)
358 $pdo->beginTransaction();
361 $query->bindValue(
':pgt', $pgt, PDO::PARAM_STR);
362 $query->bindValue(
':pgt_iou', $pgt_iou, PDO::PARAM_STR);
368 catch(PDOException $e) {
373 catch(PDOException $e) {
375 phpCAS::error(
'error writing PGT to database: ' . $e->getMessage());
402 $pdo->beginTransaction();
406 $query->bindValue(
':pgt_iou', $pgt_iou, PDO::PARAM_STR);
408 $pgt =
$query->fetchColumn(0);
413 $query->bindValue(
':pgt_iou', $pgt_iou, PDO::PARAM_STR);
419 catch(PDOException $e) {
424 catch(PDOException $e) {
426 phpCAS::trace(
'error reading PGT from database: ' . $e->getMessage());
const CAS_PGT_STORAGE_DB_DEFAULT_TABLE
An exception for terminatinating execution or to throw for unit testing.
Basic class for PGT storage The CAS_PGTStorage_AbstractStorage class is a generic class for PGT stora...
Basic class for PGT database storage The CAS_PGTStorage_Db class is a class for PGT database storage.
$_table
the table to use for storing/retrieving pgt's
read($pgt_iou)
This method reads a PGT corresponding to a PGT Iou and deletes the corresponding db entry.
_resetErrorMode()
this method will reset the error mode on the PDO object
$_errMode
attribute that stores the previous error mode for the PDO handle while processing a transaction
_getPdo()
This method returns the PDO object to use for database interactions.
getStorageType()
This method returns an informational string giving the type of storage used by the object (used for d...
write($pgt, $pgt_iou)
This method stores a PGT and its corresponding PGT Iou in the database.
createTableSql()
This method returns the query used to create a pgt storage table.
_getTable()
This method returns the table to use when storing/retrieving PGT's.
init()
This method is used to initialize the storage.
getStorageInfo()
This method returns an informational string giving informations on the parameters of the storage.
storePgtSql()
This method returns the query used to store a pgt.
$_pdo
the PDO object to use for database interactions
createTable()
This method creates the database table used to store pgt's and pgtiou's.
_setErrorMode()
This method will enable the Exception error mode on the PDO object.
retrievePgtSql()
This method returns the query used to retrieve a pgt.
__construct( $cas_parent, $dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
The class constructor.
$_dsn
database connection options to use when creating a new PDO object
deletePgtSql()
This method returns the query used to delete a pgt.
isInitialized()
This method tells if the storage has already been intialized.
static trace($str)
This method is used to log something in debug mode.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
if(empty($password)) $table