Development

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

You must first sign up to be able to contribute.

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

Revision 7791, 2.1 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  * sfDatabaseManager allows you to setup your database connectivity before the
14  * request is handled. This eliminates the need for a filter to manage database
15  * connections.
16  *
17  * @package    symfony
18  * @subpackage database
19  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
20  * @author     Sean Kerr <sean@code-box.org>
21  * @version    SVN: $Id$
22  */
23 class sfDatabaseManager
24 {
25   protected
26     $databases = array();
27
28   /**
29    * Retrieves the database connection associated with this sfDatabase implementation.
30    *
31    * @param string A database name
32    *
33    * @return mixed A Database instance
34    *
35    * @throws <b>sfDatabaseException</b> If the requested database name does not exist
36    */
37   public function getDatabase($name = 'default')
38   {
39     if (isset($this->databases[$name]))
40     {
41       return $this->databases[$name];
42     }
43
44     // nonexistent database name
45     $error = 'Database "%s" does not exist';
46     $error = sprintf($error, $name);
47
48     throw new sfDatabaseException($error);
49   }
50
51   /**
52    * Initializes this sfDatabaseManager object
53    *
54    * @return bool true, if initialization completes successfully, otherwise false
55    *
56    * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfDatabaseManager object
57    */
58   public function initialize()
59   {
60     // load database configuration
61     require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/databases.yml'));
62   }
63
64   /**
65    * Executes the shutdown procedure
66    *
67    * @return void
68    *
69    * @throws <b>sfDatabaseException</b> If an error occurs while shutting down this DatabaseManager
70    */
71   public function shutdown()
72   {
73     // loop through databases and shutdown connections
74     foreach ($this->databases as $database)
75     {
76       $database->shutdown();
77     }
78   }
79 }
80
Note: See TracBrowser for help on using the browser.