Throw exceptions when non Datasource classes are used as Datasources.

Using models as datasources can cause segmentation faults. Guard against
that by checking types and raising exceptions early.

Fixes #3694
This commit is contained in:
mark_story 2013-03-12 21:56:08 -04:00
parent 73310f9bfd
commit 3d4ebc038c
3 changed files with 14 additions and 3 deletions

View file

@ -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];
}