From a94455c3b604e70539c540f605328ebba81ee185 Mon Sep 17 00:00:00 2001 From: overnick Date: Wed, 17 Apr 2019 15:23:02 +0800 Subject: [PATCH] support manage driver --- Manager.php | 82 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/Manager.php b/Manager.php index 9350630..4b0146b 100644 --- a/Manager.php +++ b/Manager.php @@ -1,11 +1,15 @@ configure = $config; $this->app = $app; + $this->driver = $driver; } /** @@ -73,18 +84,29 @@ public function setConfigure($key, $value) * * @return string */ - abstract public function getDefaultDriver(); + public function getDefaultDriver() + { + return $this->driver ?? $this->getConfigure('default'); + } + + /** + * @param $driver + * @return $this + */ + public function setDefaultDriver($driver = null) + { + $this->driver = $driver; + return $this; + } /** * Get a driver instance. * * @param string $driver - * @return mixed + * @return $this */ public function driver($driver = null) { - $driver = $driver ?: $this->getDefaultDriver(); - if (is_null($driver)) { throw new InvalidArgumentException(sprintf( 'Unable to resolve NULL driver for [%s].', static::class @@ -170,6 +192,50 @@ public function getDrivers() */ public function __call($method, $parameters) { - return $this->driver()->$method(...$parameters); + return $this->driver($this->getDefaultDriver())->$method(...$parameters); + } + + /** + * call the default driver instance. + * + * @param $name + * @return mixed + */ + public function __get($name) + { + return $this->driver($this->getDefaultDriver())->$name; } + + /** + * @param mixed $offset + * @param mixed $value + */ + public function offsetSet($offset, $value) + { + $this->extend($offset, $value); + } + + /** + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset) + { + return array_key_exists($offset, $this->getDrivers()); + } + + /** + * @param mixed $offset + * @return mixed|Manager + */ + public function offsetGet($offset) + { + return $this->driver($offset); + } + + public function offsetUnset($offset) + { + // TODO: Implement offsetUnset() method. + } + }