]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/extlib/CAS/PGTStorage/pgt-db.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / plugins / CasAuthentication / extlib / CAS / PGTStorage / pgt-db.php
1 <?php\r
2 /*\r
3  * Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.\r
4  * All rights reserved.\r
5  * \r
6  * Redistribution and use in source and binary forms, with or without\r
7  * modification, are permitted provided that the following conditions are met:\r
8  * \r
9  *     * Redistributions of source code must retain the above copyright notice,\r
10  *       this list of conditions and the following disclaimer.\r
11  *     * Redistributions in binary form must reproduce the above copyright notice,\r
12  *       this list of conditions and the following disclaimer in the documentation\r
13  *       and/or other materials provided with the distribution.\r
14  *     * Neither the name of the ESUP-Portail consortium & the JA-SIG\r
15  *       Collaborative nor the names of its contributors may be used to endorse or\r
16  *       promote products derived from this software without specific prior\r
17  *       written permission.\r
18 \r
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\r
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29  */\r
30 \r
31 /**\r
32  * @file CAS/PGTStorage/pgt-db.php\r
33  * Basic class for PGT database storage\r
34  */\r
35 \r
36 /**\r
37  * @class PGTStorageDB\r
38  * The PGTStorageDB class is a class for PGT database storage. An instance of \r
39  * this class is returned by CASClient::SetPGTStorageDB().\r
40  *\r
41  * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>\r
42  *\r
43  * @ingroup internalPGTStorageDB\r
44  */\r
45 \r
46 class PGTStorageDB extends PGTStorage\r
47 {\r
48   /** \r
49    * @addtogroup internalPGTStorageDB\r
50    * @{ \r
51    */\r
52 \r
53   /**\r
54    * a string representing a PEAR DB URL to connect to the database. Written by\r
55    * PGTStorageDB::PGTStorageDB(), read by getURL().\r
56    *\r
57    * @hideinitializer\r
58    * @private\r
59    */\r
60   var $_url='';\r
61 \r
62   /**\r
63    * This method returns the PEAR DB URL to use to connect to the database.\r
64    *\r
65    * @return a PEAR DB URL\r
66    *\r
67    * @private\r
68    */\r
69   function getURL()\r
70     {\r
71       return $this->_url;\r
72     }\r
73 \r
74   /**\r
75    * The handle of the connection to the database where PGT's are stored. Written by\r
76    * PGTStorageDB::init(), read by getLink().\r
77    *\r
78    * @hideinitializer\r
79    * @private\r
80    */\r
81   var $_link = null;\r
82 \r
83   /**\r
84    * This method returns the handle of the connection to the database where PGT's are \r
85    * stored.\r
86    *\r
87    * @return a handle of connection.\r
88    *\r
89    * @private\r
90    */\r
91   function getLink()\r
92     {\r
93       return $this->_link;\r
94     }\r
95 \r
96   /**\r
97    * The name of the table where PGT's are stored. Written by \r
98    * PGTStorageDB::PGTStorageDB(), read by getTable().\r
99    *\r
100    * @hideinitializer\r
101    * @private\r
102    */\r
103   var $_table = '';\r
104 \r
105   /**\r
106    * This method returns the name of the table where PGT's are stored.\r
107    *\r
108    * @return the name of a table.\r
109    *\r
110    * @private\r
111    */\r
112   function getTable()\r
113     {\r
114       return $this->_table;\r
115     }\r
116 \r
117   // ########################################################################\r
118   //  DEBUGGING\r
119   // ########################################################################\r
120   \r
121   /**\r
122    * This method returns an informational string giving the type of storage\r
123    * used by the object (used for debugging purposes).\r
124    *\r
125    * @return an informational string.\r
126    * @public\r
127    */\r
128   function getStorageType()\r
129     {\r
130       return "database";\r
131     }\r
132 \r
133   /**\r
134    * This method returns an informational string giving informations on the\r
135    * parameters of the storage.(used for debugging purposes).\r
136    *\r
137    * @public\r
138    */\r
139   function getStorageInfo()\r
140     {\r
141       return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';\r
142     }\r
143 \r
144   // ########################################################################\r
145   //  CONSTRUCTOR\r
146   // ########################################################################\r
147   \r
148   /**\r
149    * The class constructor, called by CASClient::SetPGTStorageDB().\r
150    *\r
151    * @param $cas_parent the CASClient instance that creates the object.\r
152    * @param $user the user to access the data with\r
153    * @param $password the user's password\r
154    * @param $database_type the type of the database hosting the data\r
155    * @param $hostname the server hosting the database\r
156    * @param $port the port the server is listening on\r
157    * @param $database the name of the database\r
158    * @param $table the name of the table storing the data\r
159    *\r
160    * @public\r
161    */\r
162   function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)\r
163     {\r
164       phpCAS::traceBegin();\r
165 \r
166       // call the ancestor's constructor\r
167       $this->PGTStorage($cas_parent);\r
168 \r
169       if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;\r
170       if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;\r
171       if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;\r
172       if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;\r
173       if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;\r
174 \r
175       // build and store the PEAR DB URL\r
176       $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;\r
177 \r
178       // XXX should use setURL and setTable\r
179       phpCAS::traceEnd();\r
180     }\r
181   \r
182   // ########################################################################\r
183   //  INITIALIZATION\r
184   // ########################################################################\r
185   \r
186   /**\r
187    * This method is used to initialize the storage. Halts on error.\r
188    *\r
189    * @public\r
190    */\r
191   function init()\r
192     {\r
193       phpCAS::traceBegin();\r
194       // if the storage has already been initialized, return immediatly\r
195       if ( $this->isInitialized() )\r
196                 return;\r
197       // call the ancestor's method (mark as initialized)\r
198       parent::init();\r
199       \r
200           //include phpDB library (the test was introduced in release 0.4.8 for \r
201           //the integration into Tikiwiki).\r
202           if (!class_exists('DB')) {\r
203                 include_once('DB.php');\r
204           }\r
205 \r
206       // try to connect to the database\r
207       $this->_link = DB::connect($this->getURL());\r
208       if ( DB::isError($this->_link) ) {\r
209         phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');\r
210       }\r
211       var_dump($this->_link);\r
212       phpCAS::traceBEnd();\r
213     }\r
214 \r
215   /** @} */\r
216 }\r
217 \r
218 ?>