Add or reuse a connection

@param $uriString
@return \ByJG\AnyDataset\Db\DbDriverInterface
322093
public function addConnection($uriString)
    {
        if (!isset(self::$connectionList[$uriString])) {
            self::$connectionList[$uriString] = Factory::getDbRelationalInstance($uriString);

            if (self::$transaction) {
                self::$connectionList[$uriString]->beginTransaction();
            }
        }

        return self::$connectionList[$uriString];
    }
1051482
public function add(Connection $connection)
    {
        $key = md5(serialize($connection->getParams()));
        if (isset($this->connections[$key]) && $connection !== $this->connections[$key]) {
            throw new \InvalidArgumentException('Expects a non registered connection.');
        }
        $this->connections[$key] = $connection;
    }
1082745
public function addUrl(Url $url)
    {
        if (!$this->urls->contains($url)) {
            $this->urls->add($url);
            $url->setSiteroot($this);
        }

        return $this;
    }
1323180
public function connection()
    {
        if (!is_object($this->db)) {
            $this->db = new DB;
            $this->db->addConnection($this->database);
            $this->db->setEventDispatcher(new Dispatcher(new Container));
            $this->db->setAsGlobal();
            $this->db->bootEloquent();
        }

        return $this;
    }
809249
public function add($uri, $storage, $name = null, $methods = null){
        $route = new Route($uri, $storage, $methods);
        if($name !== null){
            $this->routes[$name] = $route;
        }else{
            $this->routes[] = $route;
        }
        return $route;
    }
600883
public static function createFromString($uri) {

            $parts = parse_url($uri);

            $scheme     = (isset($parts['scheme']) ? $parts['scheme'] : '');

            $user       = new User(
                (isset($parts['user']) ? $parts['user'] : null),
                (isset($parts['pass']) ? $parts['pass'] : null)
            );

            $host       = new Host(isset($parts['host']) ? $parts['host'] : '');
            $port       = intval(isset($parts['port']) ? $parts['port'] : null);
            $path       = new Path(isset($parts['path']) ? $parts['path'] : '');

            if(!empty($parts['query'])) {
                $query  = Query::createFromString($parts['query']);
            }
            else {
                $query  = new Query(array());
            }


            $fragment   = (isset($parts['fragment']) ? $parts['fragment'] : '');

            return new self($scheme, $user, $host, $port, $path, $query, $fragment);

        }
1087139
public static String removeQuerystring(String uriString) {
        URI uri = createURI(uriString);
        try {
            return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null)
                    .toASCIIString();
        } catch (URISyntaxException e) {
            throw new InvalidUriException(e);
        }
    }
672156
public static function createFromConnectionString($connectionString)
    {
        $tokenizedSettings = self::parseAndValidateKeys($connectionString);

        // Devstore case
        $matchedSpecs = self::matchedSpecification(
            $tokenizedSettings,
            self::allRequired(self::$_useDevelopmentStorageSetting),
            self::optional(self::$_developmentStorageProxyUriSetting)
        );
        if ($matchedSpecs) {
            $proxyUri = Utilities::tryGetValueInsensitive(
                Resources::DEVELOPMENT_STORAGE_PROXY_URI_NAME,
                $tokenizedSettings
            );

            return self::_getDevelopmentStorageAccount($proxyUri);
        }

        // Automatic case
        $matchedSpecs = self::matchedSpecification(
            $tokenizedSettings,
            self::allRequired(
                self::$_defaultEndpointsProtocolSetting,
                self::$_accountNameSetting,
                self::$_accountKeySetting
            ),
            self::optional(
                self::$_blobEndpointSetting,
                self::$_queueEndpointSetting,
                self::$_tableEndpointSetting
            )
        );
        if ($matchedSpecs) {
            return self::_createStorageServiceSettings(
                $tokenizedSettings,
                self::_getDefaultServiceEndpoint(
                    $tokenizedSettings,
                    Resources::BLOB_BASE_DNS_NAME
                ),
                self::_getDefaultServiceEndpoint(
                    $tokenizedSettings,
                    Resources::QUEUE_BASE_DNS_NAME
                ),
                self::_getDefaultServiceEndpoint(
                    $tokenizedSettings,
                    Resources::TABLE_BASE_DNS_NAME
                )
            );
        }

        // Explicit case
        $matchedSpecs = self::matchedSpecification(
            $tokenizedSettings,
            self::atLeastOne(
                self::$_blobEndpointSetting,
                self::$_queueEndpointSetting,
                self::$_tableEndpointSetting
            ),
            self::allRequired(
                self::$_accountNameSetting,
                self::$_accountKeySetting
            )
        );
        if ($matchedSpecs) {
            return self::_createStorageServiceSettings($tokenizedSettings);
        }

        self::noMatch($connectionString);
        return null;
    }
769310
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
    {
        $clone = clone $this;
        $clone->uri = $uri;

        if ($uri->getHost() !== '') {
            $clone->headers->set('Host', $uri->getHost());
        }

        return $clone;
    }
935825
public function getParseUriString($uriString)
    {
        // Convert wildcards to RegEx
        $regex = str_replace(['/(:any?)', ':any', ':num'], ['/?([^/]+)?', '[^/]+', '[0-9]+'], $this->path);
        $regex = str_replace('/', '\/', $regex);

        $uriString = '/' . ltrim($uriString, '/');

        // CodeIgniter Like Routing
        if (preg_match('/' . $regex . '/', $uriString, $matches)) {

            // Remove first match
            array_shift($matches);

            return (count($matches) ? $matches : false);
        }

        // Laravel Like Routing
        if (preg_match("/{(.*)}/", $this->path)) {
            // Try to find from each parts
            $pathParts = explode('/', $this->path);
            $stringParts = explode('/', $uriString);

            $pathParts = array_filter($pathParts);
            $stringParts = array_filter($stringParts);

            $matches = [];
            $parameters = [];

            for ($i = 0; $i <= count($pathParts); $i++) {
                if (isset($pathParts[ $i ]) && isset($stringParts[ $i ])) {
                    if ($pathParts[ $i ] == $stringParts[ $i ]) {
                        $matches[ $i ] = $stringParts[ $i ];
                    }
                }

                if (isset($pathParts[ $i ])) {
                    if (preg_match("/{(.*)}/", $pathParts[ $i ])) {
                        $index = str_replace(['{$', '}'], '', $pathParts[ $i ]);
                        $parameters[ $index ] = isset($stringParts[ $i ]) ? $stringParts[ $i ] : null;
                    }
                }
            }

            return (count($matches) ? $parameters : false);
        }

        return false;
    }
1341488
public static function connectDbNew($dbParams) {
        self::validateDbParameters($dbParams);
        $dbParamsSan = self::sanitizeDbParameters($dbParams);
        $config = new Configuration();
        return DriverManager::getConnection($dbParamsSan, $config);        
    }
158186
public function db_connect($persistent = FALSE)
	{
		$this->options[PDO::ATTR_PERSISTENT] = $persistent;

		try
		{
			return new PDO($this->dsn, $this->username, $this->password, $this->options);
		}
		catch (PDOException $e)
		{
			if ($this->db_debug && empty($this->failover))
			{
				$this->display_error($e->getMessage(), '', TRUE);
			}

			return FALSE;
		}
	}
940964
public function isValidUriString($uriString)
    {
        $uriString = '/' . ltrim($uriString, '/');

        if (strtolower($uriString) === $this->path) {
            $this->closureParameters = array_merge(
                $this->closureParameters,
                array_filter(explode('/', $uriString))
            );

            return true;
        } elseif (false !== ($matches = $this->getParseUriString($uriString))) {
            $parameters = [];
            $closure = new \ReflectionFunction($this->closure);

            if (is_string(key($matches))) {
                foreach ($closure->getParameters() as $index => $parameter) {
                    if (($class = $parameter->getClass()) instanceof \ReflectionClass) {
                        $className = $class->getName();
                        if (class_exists($className)) {
                            if (isset($matches[ $parameter->name ])) {
                                $parameters[ $index ] = new $className($matches[ $parameter->name ]);
                            }
                        }
                    } elseif (isset($matches[ $parameter->name ])) {
                        $parameters[ $index ] = $matches[ $parameter->name ];
                    } else {
                        $parameters[ $index ] = null;
                    }
                }
            } else {
                foreach ($closure->getParameters() as $index => $parameter) {
                    if (isset($matches[ $index ])) {
                        $parameters[ $index ] = $matches[ $index ];
                    } else {
                        $parameters[ $index ] = null;
                    }
                }
            }

            $this->closureParameters = $parameters;

            return true;
        }

        return false;
    }
184928
public function connect()
    {
        if ($this->connection) {
            return $this;
        }

        $dsn = PdoHelper::getDsn($this->options['driver'], $this->options);

        try {
            $this->connection = new \PDO(
                $dsn,
                $this->options['user'],
                $this->options['password'],
                $this->options['driverOptions']
            );
        } catch (\PDOException $e) {
            throw new \RuntimeException(
                'Could not connect to PDO: ' . $e->getMessage() . '. DSN: ' . $dsn,
                (int) $e->getCode(),
                $e
            );
        }

        $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        return $this;
    }
494854
protected function getUdpConnector(string $server): UdpConnector
    {
        if (empty($this->udp[$server])) {
            $this->udp[$server] = new UdpConnector($server, $this->timeout);
        }
        
        return $this->udp[$server];
    }
486701
public function setDriver( IDriver $driver ) : Connection
   {

      $this->_driver = $driver;
      $this->_pdo    = null;

      return $this;

   }
597058
public static function addSerializerToDriver(Serializer $serializer, FileDriverProvider $provider): FileDriverProvider {
		if ($provider instanceof FileDriverWithSerializer) {
			$provider->addSerializer($serializer);
			return $provider;
		}
		return new FileDriverWithSerializer($serializer, $provider);
	}