|
|
@@ -19,6 +19,7 @@ namespace Cake\Datasource;
|
|
|
use Cake\Core\App;
|
|
|
use Cake\Core\ObjectRegistry;
|
|
|
use Cake\Datasource\Exception\MissingDatasourceException;
|
|
|
+use Closure;
|
|
|
|
|
|
/**
|
|
|
* A registry object for connection instances.
|
|
|
@@ -68,24 +69,26 @@ class ConnectionRegistry extends ObjectRegistry
|
|
|
* If a callable is passed as first argument, The returned value of this
|
|
|
* function will be the result of the callable.
|
|
|
*
|
|
|
- * @param callable|object|string $class The classname or object to make.
|
|
|
+ * @param object|string $class The classname or object to make.
|
|
|
* @param string $alias The alias of the object.
|
|
|
* @param array<string, mixed> $config An array of settings to use for the datasource.
|
|
|
- * @return object A connection with the correct settings.
|
|
|
+ * @return \Cake\Datasource\ConnectionInterface A connection with the correct settings.
|
|
|
*/
|
|
|
- protected function _create(callable|object|string $class, string $alias, array $config): object
|
|
|
+ protected function _create(object|string $class, string $alias, array $config): ConnectionInterface
|
|
|
{
|
|
|
- if (is_callable($class)) {
|
|
|
- return $class($alias);
|
|
|
- }
|
|
|
+ if (is_string($class)) {
|
|
|
+ unset($config['className']);
|
|
|
|
|
|
- if (is_object($class)) {
|
|
|
- return $class;
|
|
|
+ /** @var \Cake\Datasource\ConnectionInterface */
|
|
|
+ return new $class($config);
|
|
|
}
|
|
|
|
|
|
- unset($config['className']);
|
|
|
+ if ($class instanceof Closure) {
|
|
|
+ return $class($alias);
|
|
|
+ }
|
|
|
|
|
|
- return new $class($config);
|
|
|
+ /** @var \Cake\Datasource\ConnectionInterface */
|
|
|
+ return $class;
|
|
|
}
|
|
|
|
|
|
/**
|