Factory method to set the driver that created this exception.

@param DriverInterface $driver The driver
480935
public static function from(DriverInterface $driver, $message = '', $code = 0, \Exception $previous = null)
    {
        //make sure that empty arguments don't get passed to exceptions as
        //they have default messages and codes.
        $self = $message ? ($code ? new static($message, $code, $previous) : new static($message)) : new static();

        $self->setDriver($driver);

        return $self;
    }
250458
public function driver($driver)
    {
        if (!isset($this->drivers[$driver])) {
            $this->drivers[$driver] = $this->createDriver($driver);
        }

        return $this->drivers[$driver];
    }
594805
public function setDisplayer(DisplayerInterface $displayer)
    {
        $this->displayer = $displayer;

        if ( ! isset($this->exceptionHandler)) return;

        $this->exceptionHandler->setDisplayer($displayer);
    }
1028616
private function addDisabledCommand(AbstractDriver $driver)
    {
        foreach ($this->commands as $name => $command) {
            $interface = $this->getInterfaceByCmd($name);
            if (!$driver instanceof $interface) {
                $driver->addDisabledCmd($name);
            }
        }

        return $this;
    }
822957
protected function createDriver($driver): Contracts\Factory
    {
        if (\is_null($this->setupDriverConfig($driver))) {
            throw new InvalidArgumentException("Driver [$driver] not supported.");
        }

        return new $this->resolver($this->app, $this, $driver);
    }
640432
public function connect(): DriverInterface
    {
        // URL options
        $options = $this->getConfig()->get();

        // TODO: This option should be optional, in addition, it may not be an array
        // Driver options
        $optionsDriver = $options['driver_options']->get();

        try {
            $connection = new MongoManager(
                $this->getDsn(),
                $this->getOptions($options, self::AVAILABLE_OPTIONS),
                $this->getOptions($optionsDriver, self::AVAILABLE_DRIVER_OPTIONS)
            );
            $this->setInstance($connection);

        } catch (RuntimeException $e) {
            new Exception('Unable to connect');
        } catch (InvalidArgumentException $e) {
            new Exception('Invalid argument provided');
        }

        return $this;
    }
70250
public function setDriver($name)
    {
        $class = '\\Samurai\\Onikiri\\Driver\\' . ucfirst($name) . 'Driver';
        if (! class_exists($class)) throw new \InvalidArgumentException("No such driver. -> {$name}");
        
        $driver = new $class();
        $this->driver = $driver;
    }
124065
public static function create(string $driver) : Backend
    {
        if (strpos($driver, '\\') === false) {
            $class = __NAMESPACE__ . '\\Drivers\\' . studly_case($driver);
        } else {
            $class = $driver;
        }

        if (!class_exists($class)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Class `%s` does not exist, so it\'s far from being a good settings backend candidate',
                    $class
                )
            );
        }

        return app()->make($class);
    }
953569
public function registerDriver($name, DriverInterface $driver)
    {
        $name = strtolower($name);
        $this->drivers[$name] = $driver;
    }
335983
public function addDriver(DriverInterface $driver, /*# int */ $factor = 1)
    {
        // get unique driver id
        $id = $this->getDriverId($driver);

        // fix factor range: 1 - 10
        $this->factors[$id] = $this->fixFactor($factor);

        // add to the pool
        $this->drivers[$id] = $driver;

        return $this;
    }
33042
private static function setKeyAndMethod($driver, $key, $method): void
    {
        $driver->setKey($key);
        if ($method !== null) {
            $driver->setMethod($method);
        }
    }
1043893
public function setDriver(\BearFramework\App\IDataDriver $driver): self
    {
        if ($this->driver !== null) {
            throw new \Exception('A data driver is already set!');
        }
        $this->driver = $driver;
        if ($this->filenameProtocol !== null) {
            \BearFramework\Internal\DataItemStreamWrapper::$environment[$this->filenameProtocol] = [$this, $driver];
        }
        return $this;
    }
849391
final private static function getFactory($driver) {
        $key = array_search(strtolower($driver), array_map('strtolower', array_keys(self::$factories)));
        if($key === false) throw new DriverException('Driver not found');
        $factories = array_values(self::$factories);
        return $factories[$key];
    }
789659
public static function getInstance(array $config = array(), DriverInterface $driver = null)
    {
        static $instance = null;

        if (null === $instance) {
            $instance = new static();
        }

        if ($config) {
            $instance->config = $config;
        }

        if ($driver) {
            $instance->driver = $driver;
        }

        return $instance;
    }
1066401
public function addDriver(string $name, DriverInterface $driver): DatabaseManager
    {
        if (isset($this->drivers[$name])) {
            throw new DBALException("Connection '{$name}' already exists");
        }

        $this->drivers[$name] = $driver;

        return $this;
    }
413211
public function driver(?string $driver = null): self
    {
        $driver = $driver ? $driver : $this->app->make('config')->get('microservice-client.client');

        $connections = array_keys($this->app->make('config')->get('microservice-client.clients'));
        if (! in_array($driver, $connections, true)) {
            throw new DomainException("The Driver[{$driver}] not exists");
        }

        $this->driver = $driver;

        return $this;
    }
209125
public function setCacheDriver($cacheDriver = '')
    {
        if ($cacheDriver != self::DEFAULT_DRIVERS && (extension_loaded($cacheDriver))) {
            $this->cacheDriver = $cacheDriver;
            $this->debug->debug(__FUNCTION__, 'Set Cache Driver: ' . json_encode($cacheDriver) . ' and server is supported');
        } else {
            $this->debug->error(__FUNCTION__, 'Set Cache Driver: ' . json_encode($cacheDriver) . ' and server is not supported, user default driver: ' . self::DEFAULT_DRIVERS);
            $this->cacheDriver = self::DEFAULT_DRIVERS;
        }
        $this->debug->debug(__FUNCTION__, 'setCacheDriver: ', $this->cacheDriver);
    }