-<?php
-
-/**
- * @file CAS/PGTStorage/pgt-db.php
- * Basic class for PGT database storage
- */
-
-/**
- * @class PGTStorageDB
- * The PGTStorageDB class is a class for PGT database storage. An instance of
- * this class is returned by CASClient::SetPGTStorageDB().
- *
- * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
- *
- * @ingroup internalPGTStorageDB
- */
-
-class PGTStorageDB extends PGTStorage
-{
- /**
- * @addtogroup internalPGTStorageDB
- * @{
- */
-
- /**
- * a string representing a PEAR DB URL to connect to the database. Written by
- * PGTStorageDB::PGTStorageDB(), read by getURL().
- *
- * @hideinitializer
- * @private
- */
- var $_url='';
-
- /**
- * This method returns the PEAR DB URL to use to connect to the database.
- *
- * @return a PEAR DB URL
- *
- * @private
- */
- function getURL()
- {
- return $this->_url;
- }
-
- /**
- * The handle of the connection to the database where PGT's are stored. Written by
- * PGTStorageDB::init(), read by getLink().
- *
- * @hideinitializer
- * @private
- */
- var $_link = null;
-
- /**
- * This method returns the handle of the connection to the database where PGT's are
- * stored.
- *
- * @return a handle of connection.
- *
- * @private
- */
- function getLink()
- {
- return $this->_link;
- }
-
- /**
- * The name of the table where PGT's are stored. Written by
- * PGTStorageDB::PGTStorageDB(), read by getTable().
- *
- * @hideinitializer
- * @private
- */
- var $_table = '';
-
- /**
- * This method returns the name of the table where PGT's are stored.
- *
- * @return the name of a table.
- *
- * @private
- */
- function getTable()
- {
- return $this->_table;
- }
-
- // ########################################################################
- // DEBUGGING
- // ########################################################################
-
- /**
- * This method returns an informational string giving the type of storage
- * used by the object (used for debugging purposes).
- *
- * @return an informational string.
- * @public
- */
- function getStorageType()
- {
- return "database";
- }
-
- /**
- * This method returns an informational string giving informations on the
- * parameters of the storage.(used for debugging purposes).
- *
- * @public
- */
- function getStorageInfo()
- {
- return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
- }
-
- // ########################################################################
- // CONSTRUCTOR
- // ########################################################################
-
- /**
- * The class constructor, called by CASClient::SetPGTStorageDB().
- *
- * @param $cas_parent the CASClient instance that creates the object.
- * @param $user the user to access the data with
- * @param $password the user's password
- * @param $database_type the type of the database hosting the data
- * @param $hostname the server hosting the database
- * @param $port the port the server is listening on
- * @param $database the name of the database
- * @param $table the name of the table storing the data
- *
- * @public
- */
- function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
- {
- phpCAS::traceBegin();
-
- // call the ancestor's constructor
- $this->PGTStorage($cas_parent);
-
- if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
- if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
- if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
- if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
- if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
-
- // build and store the PEAR DB URL
- $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;
-
- // XXX should use setURL and setTable
- phpCAS::traceEnd();
- }
-
- // ########################################################################
- // INITIALIZATION
- // ########################################################################
-
- /**
- * This method is used to initialize the storage. Halts on error.
- *
- * @public
- */
- function init()
- {
- phpCAS::traceBegin();
- // if the storage has already been initialized, return immediatly
- if ( $this->isInitialized() )
- return;
- // call the ancestor's method (mark as initialized)
- parent::init();
-
- //include phpDB library (the test was introduced in release 0.4.8 for
- //the integration into Tikiwiki).
- if (!class_exists('DB')) {
- include_once('DB.php');
- }
-
- // try to connect to the database
- $this->_link = DB::connect($this->getURL());
- if ( DB::isError($this->_link) ) {
- phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');
- }
- var_dump($this->_link);
- phpCAS::traceBEnd();
- }
-
- /** @} */
-}
-
+<?php\r
+/*\r
+ * Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.\r
+ * All rights reserved.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions are met:\r
+ * \r
+ * * Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the following disclaimer.\r
+ * * Redistributions in binary form must reproduce the above copyright notice,\r
+ * this list of conditions and the following disclaimer in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ * * Neither the name of the ESUP-Portail consortium & the JA-SIG\r
+ * Collaborative nor the names of its contributors may be used to endorse or\r
+ * promote products derived from this software without specific prior\r
+ * written permission.\r
+\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\r
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+/**\r
+ * @file CAS/PGTStorage/pgt-db.php\r
+ * Basic class for PGT database storage\r
+ */\r
+\r
+/**\r
+ * @class PGTStorageDB\r
+ * The PGTStorageDB class is a class for PGT database storage. An instance of \r
+ * this class is returned by CASClient::SetPGTStorageDB().\r
+ *\r
+ * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>\r
+ *\r
+ * @ingroup internalPGTStorageDB\r
+ */\r
+\r
+class PGTStorageDB extends PGTStorage\r
+{\r
+ /** \r
+ * @addtogroup internalPGTStorageDB\r
+ * @{ \r
+ */\r
+\r
+ /**\r
+ * a string representing a PEAR DB URL to connect to the database. Written by\r
+ * PGTStorageDB::PGTStorageDB(), read by getURL().\r
+ *\r
+ * @hideinitializer\r
+ * @private\r
+ */\r
+ var $_url='';\r
+\r
+ /**\r
+ * This method returns the PEAR DB URL to use to connect to the database.\r
+ *\r
+ * @return a PEAR DB URL\r
+ *\r
+ * @private\r
+ */\r
+ function getURL()\r
+ {\r
+ return $this->_url;\r
+ }\r
+\r
+ /**\r
+ * The handle of the connection to the database where PGT's are stored. Written by\r
+ * PGTStorageDB::init(), read by getLink().\r
+ *\r
+ * @hideinitializer\r
+ * @private\r
+ */\r
+ var $_link = null;\r
+\r
+ /**\r
+ * This method returns the handle of the connection to the database where PGT's are \r
+ * stored.\r
+ *\r
+ * @return a handle of connection.\r
+ *\r
+ * @private\r
+ */\r
+ function getLink()\r
+ {\r
+ return $this->_link;\r
+ }\r
+\r
+ /**\r
+ * The name of the table where PGT's are stored. Written by \r
+ * PGTStorageDB::PGTStorageDB(), read by getTable().\r
+ *\r
+ * @hideinitializer\r
+ * @private\r
+ */\r
+ var $_table = '';\r
+\r
+ /**\r
+ * This method returns the name of the table where PGT's are stored.\r
+ *\r
+ * @return the name of a table.\r
+ *\r
+ * @private\r
+ */\r
+ function getTable()\r
+ {\r
+ return $this->_table;\r
+ }\r
+\r
+ // ########################################################################\r
+ // DEBUGGING\r
+ // ########################################################################\r
+ \r
+ /**\r
+ * This method returns an informational string giving the type of storage\r
+ * used by the object (used for debugging purposes).\r
+ *\r
+ * @return an informational string.\r
+ * @public\r
+ */\r
+ function getStorageType()\r
+ {\r
+ return "database";\r
+ }\r
+\r
+ /**\r
+ * This method returns an informational string giving informations on the\r
+ * parameters of the storage.(used for debugging purposes).\r
+ *\r
+ * @public\r
+ */\r
+ function getStorageInfo()\r
+ {\r
+ return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';\r
+ }\r
+\r
+ // ########################################################################\r
+ // CONSTRUCTOR\r
+ // ########################################################################\r
+ \r
+ /**\r
+ * The class constructor, called by CASClient::SetPGTStorageDB().\r
+ *\r
+ * @param $cas_parent the CASClient instance that creates the object.\r
+ * @param $user the user to access the data with\r
+ * @param $password the user's password\r
+ * @param $database_type the type of the database hosting the data\r
+ * @param $hostname the server hosting the database\r
+ * @param $port the port the server is listening on\r
+ * @param $database the name of the database\r
+ * @param $table the name of the table storing the data\r
+ *\r
+ * @public\r
+ */\r
+ function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)\r
+ {\r
+ phpCAS::traceBegin();\r
+\r
+ // call the ancestor's constructor\r
+ $this->PGTStorage($cas_parent);\r
+\r
+ if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;\r
+ if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;\r
+ if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;\r
+ if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;\r
+ if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;\r
+\r
+ // build and store the PEAR DB URL\r
+ $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;\r
+\r
+ // XXX should use setURL and setTable\r
+ phpCAS::traceEnd();\r
+ }\r
+ \r
+ // ########################################################################\r
+ // INITIALIZATION\r
+ // ########################################################################\r
+ \r
+ /**\r
+ * This method is used to initialize the storage. Halts on error.\r
+ *\r
+ * @public\r
+ */\r
+ function init()\r
+ {\r
+ phpCAS::traceBegin();\r
+ // if the storage has already been initialized, return immediatly\r
+ if ( $this->isInitialized() )\r
+ return;\r
+ // call the ancestor's method (mark as initialized)\r
+ parent::init();\r
+ \r
+ //include phpDB library (the test was introduced in release 0.4.8 for \r
+ //the integration into Tikiwiki).\r
+ if (!class_exists('DB')) {\r
+ include_once('DB.php');\r
+ }\r
+\r
+ // try to connect to the database\r
+ $this->_link = DB::connect($this->getURL());\r
+ if ( DB::isError($this->_link) ) {\r
+ phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');\r
+ }\r
+ var_dump($this->_link);\r
+ phpCAS::traceBEnd();\r
+ }\r
+\r
+ /** @} */\r
+}\r
+\r