mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +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
|
@ -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';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ $pluginDot = empty($plugin) ? null : $plugin . '.';
|
|||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Datasource class %s could not be found.', '<em>' . $pluginDot . $class . '</em>'); ?>
|
||||
<?php if (isset($message)): ?>
|
||||
<?php echo h($message); ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
|
|
Loading…
Reference in a new issue