Development

/branches/1.0/lib/database/sfDatabase.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/database/sfDatabase.class.php

Revision 7791, 4.0 kB (checked in by fabien, 7 years ago)

updated Sean Kerr email address

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * sfDatabase is a base abstraction class that allows you to setup any type of
14  * database connection via a configuration file.
15  *
16  * @package    symfony
17  * @subpackage database
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @author     Sean Kerr <sean@code-box.org>
20  * @version    SVN: $Id$
21  */
22 abstract class sfDatabase
23 {
24   protected
25     $connection      = null,
26     $parameterHolder = null,
27     $resource        = null;
28
29   /**
30    * Connects to the database.
31    *
32    * @throws <b>sfDatabaseException</b> If a connection could not be created
33    */
34   abstract function connect();
35
36   /**
37    * Retrieves the database connection associated with this sfDatabase implementation.
38    *
39    * When this is executed on a Database implementation that isn't an
40    * abstraction layer, a copy of the resource will be returned.
41    *
42    * @return mixed A database connection
43    *
44    * @throws <b>sfDatabaseException</b> If a connection could not be retrieved
45    */
46   public function getConnection()
47   {
48     if ($this->connection == null)
49     {
50       $this->connect();
51     }
52
53     return $this->connection;
54   }
55
56   /**
57    * Retrieves a raw database resource associated with this sfDatabase implementation.
58    *
59    * @return mixed A database resource
60    *
61    * @throws <b>sfDatabaseException</b> If a resource could not be retrieved
62    */
63   public function getResource()
64   {
65     if ($this->resource == null)
66     {
67       $this->connect();
68     }
69
70     return $this->resource;
71   }
72
73   /**
74    * Initializes this sfDatabase object.
75    *
76    * @param array An associative array of initialization parameters
77    *
78    * @return bool true, if initialization completes successfully, otherwise false
79    *
80    * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfDatabase object
81    */
82   public function initialize($parameters = array())
83   {
84     $this->parameterHolder = new sfParameterHolder();
85     $this->parameterHolder->add($parameters);
86   }
87
88   /**
89    * Gets the parameter holder for this object.
90    *
91    * @return sfParameterHolder A sfParameterHolder instance
92    */
93   public function getParameterHolder()
94   {
95     return $this->parameterHolder;
96   }
97
98   /**
99    * Gets the parameter associated with the given key.
100    *
101    * This is a shortcut for:
102    *
103    * <code>$this->getParameterHolder()->get()</code>
104    *
105    * @param string The key name
106    * @param string The default value
107    * @param string The namespace to use
108    *
109    * @return string The value associated with the key
110    *
111    * @see sfParameterHolder
112    */
113   public function getParameter($name, $default = null, $ns = null)
114   {
115     return $this->parameterHolder->get($name, $default, $ns);
116   }
117
118   /**
119    * Returns true if the given key exists in the parameter holder.
120    *
121    * This is a shortcut for:
122    *
123    * <code>$this->getParameterHolder()->has()</code>
124    *
125    * @param string The key name
126    * @param string The namespace to use
127    *
128    * @return boolean true if the given key exists, false otherwise
129    *
130    * @see sfParameterHolder
131    */
132   public function hasParameter($name, $ns = null)
133   {
134     return $this->parameterHolder->has($name, $ns);
135   }
136
137   /**
138    * Sets the value for the given key.
139    *
140    * This is a shortcut for:
141    *
142    * <code>$this->getParameterHolder()->set()</code>
143    *
144    * @param string The key name
145    * @param string The value
146    * @param string The namespace to use
147    *
148    * @see sfParameterHolder
149    */
150   public function setParameter($name, $value, $ns = null)
151   {
152     $this->parameterHolder->set($name, $value, $ns);
153   }
154
155   /**
156    * Executes the shutdown procedure.
157    *
158    * @return void
159    *
160    * @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database
161    */
162   abstract function shutdown();
163 }
164
Note: See TracBrowser for help on using the browser.