Merge remote branch 'upstream/2.0' into 2.0

This commit is contained in:
Jeremy Harris 2011-01-17 20:07:22 -08:00
commit be563e1220
9 changed files with 120 additions and 30 deletions

View file

@ -370,6 +370,24 @@ class MissingShellFileException extends CakeException {
protected $_messageTemplate = "Shell file %s could not be loaded.";
}
/**
* Exception class to be thrown when a database file is not found
*
* @package cake.libs
*/
class MissingDatasourceConfigException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" could not be loaded.';
}
/**
* Exception class to be thrown when a database file is not found
*
* @package cake.libs
*/
class MissingDatasourceFileException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" could not be loaded.';
}
/**
* Exception class to be thrown when a database table is not found in the datasource
*

View file

@ -83,33 +83,27 @@ class ConnectionManager {
*
* @param string $name The name of the DataSource, as defined in app/config/database.php
* @return object Instance
* @throws MissingDatasourceConfigException
* @throws MissingDatasourceFileException
*/
public static function &getDataSource($name) {
public static function getDataSource($name) {
$_this = ConnectionManager::getInstance();
if (!empty($_this->_dataSources[$name])) {
$return = $_this->_dataSources[$name];
return $return;
return $_this->_dataSources[$name];
}
if (empty($_this->_connectionsEnum[$name])) {
trigger_error(__("ConnectionManager::getDataSource - Non-existent data source %s", $name), E_USER_ERROR);
$null = null;
return $null;
throw new MissingDatasourceConfigException(array('config' => $name));
}
$conn = $_this->_connectionsEnum[$name];
$class = $conn['classname'];
if ($_this->loadDataSource($name) === null) {
trigger_error(__("ConnectionManager::getDataSource - Could not load class %s", $class), E_USER_ERROR);
$null = null;
return $null;
}
$_this->loadDataSource($name);
$_this->_dataSources[$name] = new $class($_this->config->{$name});
$_this->_dataSources[$name]->configKeyName = $name;
$return = $_this->_dataSources[$name];
return $return;
return $_this->_dataSources[$name];
}
/**
@ -148,6 +142,7 @@ class ConnectionManager {
* or an array containing the filename (without extension) and class name of the object,
* to be found in app/models/datasources/ or cake/libs/model/datasources/.
* @return boolean True on success, null on failure or false if the class is already loaded
* @throws MissingDatasourceFileException
*/
public static function loadDataSource($connName) {
$_this = ConnectionManager::getInstance();
@ -170,8 +165,7 @@ class ConnectionManager {
$class = "{$conn['plugin']}.{$conn['classname']}";
if (!App::import('Datasource', $class, !is_null($conn['plugin']))) {
trigger_error(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s', $class), E_USER_ERROR);
return null;
throw new MissingDatasourceFileException(array('class' => $conn['classname'], 'plugin' => $conn['plugin']));
}
return true;
}

View file

@ -61,10 +61,10 @@ class Set {
* @param boolean $isArray Force to tell $var is an array when $var is empty
* @return mixed Either filtered array, or true/false when in callback
*/
public static function filter($var, $isArray = false) {
foreach ((array)$var as $k => $v) {
if (!empty($v) && is_array($v)) {
$var[$k] = array_filter($v, array('Set', '_filter'));
public static function filter(array $var) {
foreach ($var as $k => $v) {
if (is_array($v)) {
$var[$k] = Set::filter($v);
}
}
return array_filter($var, array('Set', '_filter'));

View file

@ -0,0 +1,29 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.libs.view.templates.errors
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<h2><?php echo __('Missing Datasource Configuration'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php echo __('The datasource configuration %1$s was not found in databases.php.', '<em>' . $config . '</em>'); ?>
</p>
<p class="notice">
<strong><?php echo __('Notice'); ?>: </strong>
<?php echo __('If you want to customize this error message, create %s', APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_datasource_config.ctp'); ?>
</p>
<?php echo $this->element('exception_stack_trace'); ?>

View file

@ -0,0 +1,29 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.libs.view.templates.errors
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<h2><?php echo __('Missing Datasource Class'); ?></h2>
<p class="error">
<strong><?php echo __('Error'); ?>: </strong>
<?php echo __('Datasource class %1$s was not found.', '<em>' . $class . '</em>'); ?>
</p>
<p class="notice">
<strong><?php echo __('Notice'); ?>: </strong>
<?php echo __('If you want to customize this error message, create %s', APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_datasource_file.ctp'); ?>
</p>
<?php echo $this->element('exception_stack_trace'); ?>

View file

@ -93,7 +93,6 @@ class PaginatorHelper extends AppHelper {
* @throws CakeException When the AjaxProvider helper does not implement a link method.
*/
function __construct(View $View, $settings = array()) {
parent::__construct($View, $settings);
$ajaxProvider = isset($settings['ajax']) ? $settings['ajax'] : 'Js';
$this->helpers[] = $ajaxProvider;
$this->_ajaxHelperClass = $ajaxProvider;
@ -106,6 +105,7 @@ class PaginatorHelper extends AppHelper {
__('%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname
));
}
parent::__construct($View, $settings);
}
/**

View file

@ -87,11 +87,15 @@ if (isset($filePresent)):
require LIBS . 'model' . DS . 'connection_manager.php';
}
$db = ConnectionManager::getInstance();
@$connected = $db->getDataSource('default');
try {
$connected = $db->getDataSource('default');
} catch (Exception $e) {
$connected = false;
}
?>
<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>';

View file

@ -81,12 +81,16 @@ class ConnectionManagerTest extends CakeTestCase {
$source = ConnectionManager::getDataSource(key($connections));
$this->assertTrue(is_object($source));
}
$this->expectError();
$source = ConnectionManager::getDataSource('non_existent_source');
$this->assertEqual($source, null);
/**
* testGetDataSourceException() method
*
* @return void
* @expectedException MissingDatasourceConfigException
*/
public function testGetDataSourceException() {
ConnectionManager::getDataSource('non_existent_source');
}
/**
@ -233,12 +237,17 @@ class ConnectionManagerTest extends CakeTestCase {
$loaded = ConnectionManager::loadDataSource($connection);
$this->assertEqual($loaded, !$exists, "%s Failed loading the {$connection['classname']} datasource");
}
}
/**
* testLoadDataSourceException() method
*
* @return void
* @expectedException MissingDatasourceFileException
*/
public function testLoadDataSourceException() {
$connection = array('classname' => 'NonExistentDataSource', 'filename' => 'non_existent');
$this->expectError();
$loaded = ConnectionManager::loadDataSource($connection);
$this->assertEqual($loaded, null);
}
/**

View file

@ -100,8 +100,15 @@ class SetTest extends CakeTestCase {
$result = Set::filter(array(1, array('empty', false)));
$expected = array(1, array('empty'));
$this->assertEqual($expected, $result);
$result = Set::filter(array(1, array('2', false, array(3, null))));
$expected = array(1, array('2', 2 => array(3)));
$this->assertEqual($expected, $result);
$this->assertSame(array(), Set::filter(array()));
}
/**
* testNumericArrayCheck method
*