Browse Source

Lazy loading connections in ConnectionManager, changing some class names and imports

José Lorenzo Rodríguez 15 years ago
parent
commit
7828f7d2fb

+ 8 - 8
lib/Cake/Model/ConnectionManager.php

@@ -69,7 +69,6 @@ class ConnectionManager {
 		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;
@@ -92,10 +91,15 @@ class ConnectionManager {
 		}
 
 		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'];
 
@@ -222,13 +226,9 @@ class ConnectionManager {
  *
  * @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'));
 		}

+ 1 - 4
lib/Cake/Model/Datasource/CakeSession.php

@@ -559,10 +559,7 @@ class CakeSession {
  */
 	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));
 		}

+ 3 - 1
lib/Cake/Model/Datasource/Database/Sqlite.php

@@ -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.
  *
@@ -26,7 +28,7 @@
  * @package datasources
  * @subpackage    cake.cake.libs.model.datasources.dbo
  */
-class DboSqlite extends DboSource {
+class Sqlite extends DboSource {
 
 /**
  * Datasource Description

+ 1 - 3
lib/Cake/Utility/File.php

@@ -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.

+ 4 - 7
lib/Cake/View/pages/home.ctp

@@ -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.');
@@ -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>';