Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / lib / phpcas / PGTStorage / pgt-db.php @ b67d8923

Historique | Voir | Annoter | Télécharger (4,86 ko)

1
<?php
2

    
3
/**
4
 * @file CAS/PGTStorage/pgt-db.php
5
 * Basic class for PGT database storage
6
 */
7

    
8
// include phpDB library (the test was introduced in release 0.4.8 for 
9
// the integration into Tikiwiki).
10
if (!class_exists('DB')) {
11
  include_once('DB.php');
12
}
13

    
14
/**
15
 * @class PGTStorageDB
16
 * The PGTStorageDB class is a class for PGT database storage. An instance of 
17
 * this class is returned by CASClient::SetPGTStorageDB().
18
 *
19
 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
20
 *
21
 * @ingroup internalPGTStorageDB
22
 */
23

    
24
class PGTStorageDB extends PGTStorage
25
{
26
  /** 
27
   * @addtogroup internalPGTStorageDB
28
   * @{ 
29
   */
30

    
31
  /**
32
   * a string representing a PEAR DB URL to connect to the database. Written by
33
   * PGTStorageDB::PGTStorageDB(), read by getURL().
34
   *
35
   * @hideinitializer
36
   * @private
37
   */
38
  var $_url='';
39

    
40
  /**
41
   * This method returns the PEAR DB URL to use to connect to the database.
42
   *
43
   * @return a PEAR DB URL
44
   *
45
   * @private
46
   */
47
  function getURL()
48
    {
49
      return $this->_url;
50
    }
51

    
52
  /**
53
   * The handle of the connection to the database where PGT's are stored. Written by
54
   * PGTStorageDB::init(), read by getLink().
55
   *
56
   * @hideinitializer
57
   * @private
58
   */
59
  var $_link = null;
60

    
61
  /**
62
   * This method returns the handle of the connection to the database where PGT's are 
63
   * stored.
64
   *
65
   * @return a handle of connection.
66
   *
67
   * @private
68
   */
69
  function getLink()
70
    {
71
      return $this->_link;
72
    }
73

    
74
  /**
75
   * The name of the table where PGT's are stored. Written by 
76
   * PGTStorageDB::PGTStorageDB(), read by getTable().
77
   *
78
   * @hideinitializer
79
   * @private
80
   */
81
  var $_table = '';
82

    
83
  /**
84
   * This method returns the name of the table where PGT's are stored.
85
   *
86
   * @return the name of a table.
87
   *
88
   * @private
89
   */
90
  function getTable()
91
    {
92
      return $this->_table;
93
    }
94

    
95
  // ########################################################################
96
  //  DEBUGGING
97
  // ########################################################################
98
  
99
  /**
100
   * This method returns an informational string giving the type of storage
101
   * used by the object (used for debugging purposes).
102
   *
103
   * @return an informational string.
104
   * @public
105
   */
106
  function getStorageType()
107
    {
108
      return "database";
109
    }
110

    
111
  /**
112
   * This method returns an informational string giving informations on the
113
   * parameters of the storage.(used for debugging purposes).
114
   *
115
   * @public
116
   */
117
  function getStorageInfo()
118
    {
119
      return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
120
    }
121

    
122
  // ########################################################################
123
  //  CONSTRUCTOR
124
  // ########################################################################
125
  
126
  /**
127
   * The class constructor, called by CASClient::SetPGTStorageDB().
128
   *
129
   * @param $cas_parent the CASClient instance that creates the object.
130
   * @param $user the user to access the data with
131
   * @param $password the user's password
132
   * @param $database_type the type of the database hosting the data
133
   * @param $hostname the server hosting the database
134
   * @param $port the port the server is listening on
135
   * @param $database the name of the database
136
   * @param $table the name of the table storing the data
137
   *
138
   * @public
139
   */
140
  function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
141
    {
142
      phpCAS::traceBegin();
143

    
144
      // call the ancestor's constructor
145
      $this->PGTStorage($cas_parent);
146

    
147
      if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
148
      if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
149
      if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
150
      if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
151
      if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
152

    
153
      // build and store the PEAR DB URL
154
      $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;
155

    
156
      // XXX should use setURL and setTable
157
      phpCAS::traceEnd();
158
    }
159
  
160
  // ########################################################################
161
  //  INITIALIZATION
162
  // ########################################################################
163
  
164
  /**
165
   * This method is used to initialize the storage. Halts on error.
166
   *
167
   * @public
168
   */
169
  function init()
170
    {
171
      phpCAS::traceBegin();
172
      // if the storage has already been initialized, return immediatly
173
      if ( $this->isInitialized() )
174
        return;
175
      // call the ancestor's method (mark as initialized)
176
      parent::init();
177
      
178
      // try to connect to the database
179
      $this->_link = DB::connect($this->getURL());
180
      if ( DB::isError($this->_link) ) {
181
        phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');
182
      }
183
      var_dump($this->_link);
184
      phpCAS::traceBEnd();
185
    }
186

    
187
  /** @} */
188
}
189

    
190
?>
Redmine Appliance - Powered by TurnKey Linux