diff --git a/lib/Cake/Error/exceptions.php b/lib/Cake/Error/exceptions.php index 3a7b46912..992aacf60 100644 --- a/lib/Cake/Error/exceptions.php +++ b/lib/Cake/Error/exceptions.php @@ -441,7 +441,7 @@ class MissingDatasourceConfigException extends CakeException { */ class MissingDatasourceException extends CakeException { - protected $_messageTemplate = 'Datasource class %s could not be found.'; + protected $_messageTemplate = 'Datasource class %s could not be found. %s'; } diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index 4619c2ade..a756c75bb 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -99,9 +99,17 @@ class ConnectionManager { $conn = self::$_connectionsEnum[$name]; $class = $conn['classname']; - self::$_dataSources[$name] = new $class(self::$config->{$name}); - self::$_dataSources[$name]->configKeyName = $name; + $instance = new $class(self::$config->{$name}); + $instance->configKeyName = $name; + if (!$instance instanceof Datasource) { + throw new MissingDatasourceException(array( + 'class' => $class, + 'plugin' => null, + 'message' => 'Only classes extending Datasource can be used as datasources.' + )); + } + self::$_dataSources[$name] = $instance; return self::$_dataSources[$name]; } diff --git a/lib/Cake/View/Errors/missing_datasource.ctp b/lib/Cake/View/Errors/missing_datasource.ctp index 25cebf68e..c6d712e18 100644 --- a/lib/Cake/View/Errors/missing_datasource.ctp +++ b/lib/Cake/View/Errors/missing_datasource.ctp @@ -22,6 +22,9 @@ $pluginDot = empty($plugin) ? null : $plugin . '.';

: ' . $pluginDot . $class . ''); ?> + + +

: