From 96398e9766bdc03e1b89c4892d1ff00a9514cd53 Mon Sep 17 00:00:00 2001 From: Prince John Santillan <60916966+princejohnsantillan@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:41:09 +0800 Subject: [PATCH] [11.x] Make MultipleInstanceManager driver field customizable (#51905) * make MultipleInstanceManager driver field customizable * formatting --------- Co-authored-by: Taylor Otwell --- .../Support/MultipleInstanceManager.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Support/MultipleInstanceManager.php b/src/Illuminate/Support/MultipleInstanceManager.php index de403fda4a33..3525cf3c0798 100644 --- a/src/Illuminate/Support/MultipleInstanceManager.php +++ b/src/Illuminate/Support/MultipleInstanceManager.php @@ -29,6 +29,13 @@ abstract class MultipleInstanceManager */ protected $customCreators = []; + /** + * The key name of the "driver" equivalent configuration option. + * + * @var string + */ + protected $driverKey = 'driver'; + /** * Create a new manager instance. * @@ -104,19 +111,19 @@ protected function resolve($name) throw new InvalidArgumentException("Instance [{$name}] is not defined."); } - if (! array_key_exists('driver', $config)) { - throw new RuntimeException("Instance [{$name}] does not specify a driver."); + if (! array_key_exists($this->driverKey, $config)) { + throw new RuntimeException("Instance [{$name}] does not specify a {$this->driverKey}."); } - if (isset($this->customCreators[$config['driver']])) { + if (isset($this->customCreators[$config[$this->driverKey]])) { return $this->callCustomCreator($config); } else { - $driverMethod = 'create'.ucfirst($config['driver']).'Driver'; + $createMethod = 'create'.ucfirst($config[$this->driverKey]).ucfirst($this->driverKey); - if (method_exists($this, $driverMethod)) { - return $this->{$driverMethod}($config); + if (method_exists($this, $createMethod)) { + return $this->{$createMethod}($config); } else { - throw new InvalidArgumentException("Instance driver [{$config['driver']}] is not supported."); + throw new InvalidArgumentException("Instance {$this->driverKey} [{$config[$this->driverKey]}] is not supported."); } } } @@ -129,7 +136,7 @@ protected function resolve($name) */ protected function callCustomCreator(array $config) { - return $this->customCreators[$config['driver']]($this->app, $config); + return $this->customCreators[$config[$this->driverKey]]($this->app, $config); } /**