]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/extlib/CAS/PGTStorage/pgt-db.php
Tickets #2112, 2333, 1677, 2362, 2831: fix AJAX form posting on SSL page views with...
[quix0rs-gnu-social.git] / plugins / CasAuthentication / extlib / CAS / PGTStorage / pgt-db.php
1 <?php\r
2 \r
3 /**\r
4  * @file CAS/PGTStorage/pgt-db.php\r
5  * Basic class for PGT database storage\r
6  */\r
7 \r
8 /**\r
9  * @class PGTStorageDB\r
10  * The PGTStorageDB class is a class for PGT database storage. An instance of \r
11  * this class is returned by CASClient::SetPGTStorageDB().\r
12  *\r
13  * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>\r
14  *\r
15  * @ingroup internalPGTStorageDB\r
16  */\r
17 \r
18 class PGTStorageDB extends PGTStorage\r
19 {\r
20   /** \r
21    * @addtogroup internalPGTStorageDB\r
22    * @{ \r
23    */\r
24 \r
25   /**\r
26    * a string representing a PEAR DB URL to connect to the database. Written by\r
27    * PGTStorageDB::PGTStorageDB(), read by getURL().\r
28    *\r
29    * @hideinitializer\r
30    * @private\r
31    */\r
32   var $_url='';\r
33 \r
34   /**\r
35    * This method returns the PEAR DB URL to use to connect to the database.\r
36    *\r
37    * @return a PEAR DB URL\r
38    *\r
39    * @private\r
40    */\r
41   function getURL()\r
42     {\r
43       return $this->_url;\r
44     }\r
45 \r
46   /**\r
47    * The handle of the connection to the database where PGT's are stored. Written by\r
48    * PGTStorageDB::init(), read by getLink().\r
49    *\r
50    * @hideinitializer\r
51    * @private\r
52    */\r
53   var $_link = null;\r
54 \r
55   /**\r
56    * This method returns the handle of the connection to the database where PGT's are \r
57    * stored.\r
58    *\r
59    * @return a handle of connection.\r
60    *\r
61    * @private\r
62    */\r
63   function getLink()\r
64     {\r
65       return $this->_link;\r
66     }\r
67 \r
68   /**\r
69    * The name of the table where PGT's are stored. Written by \r
70    * PGTStorageDB::PGTStorageDB(), read by getTable().\r
71    *\r
72    * @hideinitializer\r
73    * @private\r
74    */\r
75   var $_table = '';\r
76 \r
77   /**\r
78    * This method returns the name of the table where PGT's are stored.\r
79    *\r
80    * @return the name of a table.\r
81    *\r
82    * @private\r
83    */\r
84   function getTable()\r
85     {\r
86       return $this->_table;\r
87     }\r
88 \r
89   // ########################################################################\r
90   //  DEBUGGING\r
91   // ########################################################################\r
92   \r
93   /**\r
94    * This method returns an informational string giving the type of storage\r
95    * used by the object (used for debugging purposes).\r
96    *\r
97    * @return an informational string.\r
98    * @public\r
99    */\r
100   function getStorageType()\r
101     {\r
102       return "database";\r
103     }\r
104 \r
105   /**\r
106    * This method returns an informational string giving informations on the\r
107    * parameters of the storage.(used for debugging purposes).\r
108    *\r
109    * @public\r
110    */\r
111   function getStorageInfo()\r
112     {\r
113       return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';\r
114     }\r
115 \r
116   // ########################################################################\r
117   //  CONSTRUCTOR\r
118   // ########################################################################\r
119   \r
120   /**\r
121    * The class constructor, called by CASClient::SetPGTStorageDB().\r
122    *\r
123    * @param $cas_parent the CASClient instance that creates the object.\r
124    * @param $user the user to access the data with\r
125    * @param $password the user's password\r
126    * @param $database_type the type of the database hosting the data\r
127    * @param $hostname the server hosting the database\r
128    * @param $port the port the server is listening on\r
129    * @param $database the name of the database\r
130    * @param $table the name of the table storing the data\r
131    *\r
132    * @public\r
133    */\r
134   function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)\r
135     {\r
136       phpCAS::traceBegin();\r
137 \r
138       // call the ancestor's constructor\r
139       $this->PGTStorage($cas_parent);\r
140 \r
141       if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;\r
142       if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;\r
143       if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;\r
144       if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;\r
145       if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;\r
146 \r
147       // build and store the PEAR DB URL\r
148       $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;\r
149 \r
150       // XXX should use setURL and setTable\r
151       phpCAS::traceEnd();\r
152     }\r
153   \r
154   // ########################################################################\r
155   //  INITIALIZATION\r
156   // ########################################################################\r
157   \r
158   /**\r
159    * This method is used to initialize the storage. Halts on error.\r
160    *\r
161    * @public\r
162    */\r
163   function init()\r
164     {\r
165       phpCAS::traceBegin();\r
166       // if the storage has already been initialized, return immediatly\r
167       if ( $this->isInitialized() )\r
168                 return;\r
169       // call the ancestor's method (mark as initialized)\r
170       parent::init();\r
171       \r
172           //include phpDB library (the test was introduced in release 0.4.8 for \r
173           //the integration into Tikiwiki).\r
174           if (!class_exists('DB')) {\r
175                 include_once('DB.php');\r
176           }\r
177 \r
178       // try to connect to the database\r
179       $this->_link = DB::connect($this->getURL());\r
180       if ( DB::isError($this->_link) ) {\r
181         phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');\r
182       }\r
183       var_dump($this->_link);\r
184       phpCAS::traceBEnd();\r
185     }\r
186 \r
187   /** @} */\r
188 }\r
189 \r
190 ?>