Skip to content

Commit

Permalink
Lazy loading connections in ConnectionManager, changing some class na…
Browse files Browse the repository at this point in the history
…mes and imports
  • Loading branch information
lorenzo committed Dec 8, 2010
1 parent 09120b7 commit 7828f7d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
16 changes: 8 additions & 8 deletions lib/Cake/Model/ConnectionManager.php
Expand Up @@ -69,7 +69,6 @@ private static function init() {
include_once CONFIGS . 'database.php';
if (class_exists('DATABASE_CONFIG')) {
self::$config = new DATABASE_CONFIG();
self::_getConnectionObjects();
}
register_shutdown_function('ConnectionManager::shutdown');
self::$_init = true;
Expand All @@ -91,11 +90,16 @@ public static function getDataSource($name) {
return $return;
}

if (empty(self::$_connectionsEnum[$name])) {
self::_getConnectionObject($name);
}

if (empty(self::$_connectionsEnum[$name])) {
trigger_error(__("ConnectionManager::getDataSource - Non-existent data source %s", $name), E_USER_ERROR);
$null = null;
return $null;
}

$conn = self::$_connectionsEnum[$name];
$class = $conn['classname'];

Expand Down Expand Up @@ -222,13 +226,9 @@ public static function create($name = '', $config = array()) {
*
* @return void
*/
protected static function _getConnectionObjects() {
$connections = get_object_vars(self::$config);

if ($connections != null) {
foreach ($connections as $name => $config) {
self::$_connectionsEnum[$name] = self::_connectionData($config);
}
protected static function _getConnectionObject($name) {
if (!empty(self::$config->{$name})) {
self::$_connectionsEnum[$name] = self::_connectionData(self::$config->{$name});
} else {
throw new MissingConnectionException(array('class' => 'ConnectionManager'));
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -559,10 +559,7 @@ protected static function _configureSession() {
*/
protected static function _getHandler($handler) {
list($plugin, $class) = pluginSplit($handler, true);
$found = App::import('Lib', $plugin . 'session/' . $class);
if (!$found) {
App::import('Core', 'session/' . $class);
}
App::uses($class, $plugin . 'Model/Datasource/Session');
if (!class_exists($class)) {
throw new Exception(__('Could not load %s to handle the session.', $class));
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -18,6 +18,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('DboSource', 'Model/Datasource');

/**
* DBO implementation for the SQLite3 DBMS.
*
Expand All @@ -26,7 +28,7 @@
* @package datasources
* @subpackage cake.cake.libs.model.datasources.dbo
*/
class DboSqlite extends DboSource {
class Sqlite extends DboSource {

/**
* Datasource Description
Expand Down
4 changes: 1 addition & 3 deletions lib/Cake/Utility/File.php
Expand Up @@ -22,9 +22,7 @@
* Included libraries.
*
*/
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
App::uses('File', 'Utility');

/**
* Convenience class for reading, writing and appending to files.
Expand Down
11 changes: 4 additions & 7 deletions lib/Cake/View/pages/home.ctp
Expand Up @@ -72,7 +72,7 @@ endif;
?>
</p>
<?php
App::import('Core', 'Validation');
App::uses('Validation', 'Utility');
if (!Validation::alphaNumeric('cakephp')) {
echo '<p><span class="notice">';
__('PCRE has not been compiled with Unicode support.');
Expand All @@ -83,15 +83,12 @@ endif;
?>
<?php
if (isset($filePresent)):
if (!class_exists('ConnectionManager')) {
require LIBS . 'model' . DS . 'connection_manager.php';
}
$db = ConnectionManager::getInstance();
@$connected = $db->getDataSource('default');
App::uses('ConnectionManager', 'Model');
$connected = ConnectionManager::getDataSource('default');
?>
<p>
<?php
if ($connected->isConnected()):
if ($connected && $connected->isConnected()):
echo '<span class="notice success">';
echo __('Cake is able to connect to the database.');
echo '</span>';
Expand Down

0 comments on commit 7828f7d

Please sign in to comment.