Create a new driver instance.

@param string $driver

@throws \InvalidArgumentException

@return ProviderInterface
777054
protected function createDriver($driver)
    {
        if (isset($this->initialDrivers[$driver])) {
            $provider = $this->initialDrivers[$driver];
            $provider = __NAMESPACE__.'\\Providers\\'.$provider.'Provider';

            return $this->buildProvider($provider, $this->formatConfig($this->config->get($driver)));
        }

        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver);
        }

        throw new InvalidArgumentException("Driver [$driver] not supported.");
    }
1099067
protected function createConnection( $driver, $connection, $database, $prefix = '', array $config = [] )
	{
		if( $resolver = Connection::getResolver($driver) )
		{
			return $resolver( $connection, $database, $prefix, $config );
		}

		switch( $driver )
		{
			case 'mysql':
				return new MySqlConnection( $connection, $database, $prefix, $config );
			/* TODO add support
			 * case 'pgsql':
				return new PostgresConnection( $connection, $database, $prefix, $config );*/
		}

		throw new InvalidArgumentException( "Unsupported driver [{$driver}]" );
	}
60294
private function buildCompressor($driver)
    {
        if ($driver instanceof CompressorInterface) {
            return $driver;
        }

        if (class_exists($driver)) {
            $driverClass = $driver;
        } elseif (is_string($driver)) {
            $driver = ucfirst(strtolower($driver));
            $driverClass = '\\ImageCompressor\\Driver\\' . $driver;

        }

        if (class_exists($driverClass) && is_subclass_of($driverClass, CompressorInterface::class)) {
            return new $driverClass;
        } else {
            throw new \InvalidArgumentException('Image compressor driver not found');
        }
    }
110736
public function getManager(Driver $driver)
    {
        if (!in_array($driver->getDriver(), array_keys($this->managers))) {
            throw new DriverNotFoundException($driver->getDriver());
        }

        $manager = $this->managers[$driver->getDriver()];
        $manager->setModelClass($this->modelClass);

        return $manager;
    }
739918
public function removeProvider(string $key): ProviderInterface
    {
        if (!isset($this->providers[$key])) {
            throw new InvalidArgumentException('key', sprintf('Provider under key "%s" not found', $key));
        }

        return $this->providers[$key];
    }
915267
protected function createCacheHandler($driver)
    {
        $store = $this->app['config']->get('session.store') ?: $driver;

        $minutes = $this->app['config']['session.lifetime'];

        return new CacheBasedSessionHandler(clone $this->app['cache']->store($store), $minutes);
    }
1281703
public function connect(): DriverInterface
    {
        try {
            $connection = new PDO(
                $this->getDsn(),
                $this->getParam('username'),
                $this->getParam('password'),
                $this->getOptions()
            );
            $this->setInstance($connection);

        } catch (SQLException $e) {
            // __construct
        }

        return $this;
    }
361946
public static function setDriver($driver)
    {

        if (!self::isInstanceOf($driver, YamlInterface::class)) {
            if (self::isString($driver) || self::isStringObject($driver)) {
                $driver = StdObjectWrapper::toString($driver);
                $driver = new $driver;
                if (self::isInstanceOf($driver, YamlInterface::class)) {
                    self::$customDriver = $driver;

                    return;
                }
            }
            throw new YamlException(AbstractException::MSG_INVALID_ARG, ['$driver', YamlInterface::class]);
        }
        self::$customDriver = $driver;

        return;
    }
404064
public function driver($driver = null)
    {
        $driver = $driver ?: $this->getDefaultDriver();

        if (is_null($driver)) {
            throw new InvalidArgumentException(sprintf('Unable to resolve NULL driver for [%s].', get_called_class()));
        }

        // If the given driver has not been created before, we will create the instances
        // here and cache it so we can return it next time very quickly. If there is
        // already a driver created by this name, we'll just return that instance.
        if (! isset($this->drivers[$driver])) {
            $this->drivers[$driver] = $this->createDriver($driver);
        }

        return $this->drivers[$driver];
    }
701581
private function createConfigurationDriver()
    {
        $reflection = new \ReflectionClass($this->driverClass());

        /** @var ConfigurationInterface $config */
        $config = $reflection->hasMethod('__construct')
            ? $reflection->newInstanceArgs([$this->file])
            : $reflection->newInstance();
        return $config;
    }
1200619
public function driver(AbstractDriver $driver = null)
    {
        if ($driver === null) {
            return $this->getDriver();
        }

        return $this->setDriver($driver);
    }
664169
public static function make(array $options = [], $driver = null)
    {
        $class = null;

        if (!$driver && isset($options['driver'])) {
            $driver = $options['driver'];
            unset($options['driver']);
        }

        /** @var LockInterface $class */
        if (isset(self::$driverMap[$driver])) {
            $class = self::$driverMap[$driver];

        } else {
            foreach ([self::DRIVER_SEM, self::DRIVER_FILE] as $name) {
                $class = self::$driverMap[$name];

                if ($class::isSupported()){
                    break;
                }
            }
        }

        if (!$class) {
            throw new \RuntimeException('No available driver! MAP: ' . implode(',', self::$driverMap));
        }

        return new $class($options);
    }
1206434
public function driver($driver = '')
    {
        if (isset($this->drivers[$driver]) || isset($this->extends[$driver])) {
            $driver = $this->buildDriver($driver);

            return $this->initalizeDriver($driver);
        } else {
            throw new DriverNotFoundException(sprintf('%s driver is not found', $driver));
        }
    }
950802
public function driver($driver = '', array $configs = [])
    {
        $driverList = $this->getDriverList();

        if (!count($configs)) {
            $configs = isset($this->getConfig()[$driver]) ? $this->getConfig()[$driver] : [];
        }

        if (isset($driverList[$driver])) {
            $driver = $driverList[$driver];
        }

        if (is_string($driver)) {
            $driver = new $driver;
        }

        return $this->setDriver($driver, $configs);
    }
335910
public static function createDbo($driver, array $options)
    {
        // Sanitize the database connector options.
        $options['driver'] = preg_replace('/[^A-Z0-9_\.-]/i', '', $driver);
        $options['database'] = $options['database'] ?? null;
        $options['select'] = $options['select'] ?? true;

        // Use custom Resource
        $resource = $options['resource'] ?? null;

        // Derive the class name from the driver.
        $class = '\\Windwalker\\Database\\Driver\\' . ucfirst(strtolower($options['driver'])) . '\\'
            . ucfirst(strtolower($options['driver'])) . 'Driver';

        // If the class still doesn't exist we have nothing left to do but throw an exception.  We did our best.
        if (!class_exists($class)) {
            throw new \RuntimeException(sprintf('Unable to load Database Driver: %s', $options['driver']));
        }

        /** @var DatabaseDriverInterface $class */
        if (!$class::isSupported()) {
            throw new \RangeException('Database driver ' . $driver . ' not supported.');
        }

        // Create our new Driver connector based on the options given.
        try {
            $instance = new $class($resource, $options);
        } catch (\RuntimeException $e) {
            throw new \RuntimeException(sprintf('Unable to connect to the Database: %s', $e->getMessage()));
        }

        return $instance;
    }
852555
public function setDriver($driver) {

    	if(false === is_string($driver)) {
    		return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($driver)), E_USER_ERROR);
    	}

        if(false === class_exists($driver)) {

            $driver = __NAMESPACE__ . '\\Driver\\' . $driver;
        
            if(false === class_exists($driver)) {
        		return trigger_error(sprintf('Driver "%s" does not exists', $driver), E_USER_ERROR);
        	}
        }

        $this -> driver = $driver;

        return $this;
    }
538820
public static function driver($uri, ConfigInterface $config = null)
    {
        return new Driver(self::formatUri($uri), $config);
    }