mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Lazy loading connections in ConnectionManager, changing some class names and imports
This commit is contained in:
parent
09120b715c
commit
7828f7d2fb
5 changed files with 17 additions and 23 deletions
|
@ -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;
|
||||
|
@ -91,11 +90,16 @@ class ConnectionManager {
|
|||
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'];
|
||||
|
||||
|
@ -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'));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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>';
|
||||
|
|
Loading…
Reference in a new issue