mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-09 21:12:41 +00:00
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:
parent
73310f9bfd
commit
3d4ebc038c
3 changed files with 14 additions and 3 deletions
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue