driverName = (string) $driverName; $this->hostname = self::HOST_DEFAULT; $this->port = self::suggestPortFromDriverName($driverName); $this->unixSocket = null; $this->memory = null; $this->filePath = null; $this->databaseName = null; $this->charset = self::suggestCharsetFromDriverName($driverName); $this->username = null; $this->password = null; } /** * Sets the hostname * * @param string|null $hostname the hostname where the database can be accessed, e.g. `db.example.com` * @return static this instance for chaining */ public function setHostname($hostname = null) { $this->hostname = $hostname !== null ? (string) $hostname : null; return $this; } /** * Sets the port number * * @param int|null $port the port number to use at the given host, e.g. `3306` or `5432` * @return static this instance for chaining */ public function setPort($port = null) { $this->port = $port !== null ? (int) $port : null; return $this; } /** * Sets the unix socket * * @param string|null $unixSocket the UNIX socket to use, e.g. `/tmp/db.sock` * @return static this instance for chaining */ public function setUnixSocket($unixSocket = null) { $this->unixSocket = $unixSocket !== null ? (string) $unixSocket : null; return $this; } /** * Sets whether to keep the database in memory only * * @param bool|null $memory whether to keep the database in memory only * @return static this instance for chaining */ public function setMemory($memory = null) { $this->memory = $memory !== null ? (bool) $memory : null; return $this; } /** * Sets the file path * * @param string|null $filePath the path to the file where the database can be accessed on disk, e.g. `/opt/databases/mydb.ext` * @return static this instance for chaining */ public function setFilePath($filePath = null) { $this->filePath = $filePath !== null ? (string) $filePath : null; return $this; } /** * Sets the database name * * @param string|null $databaseName the name of the database, e.g. `my_application` * @return static this instance for chaining */ public function setDatabaseName($databaseName = null) { $this->databaseName = $databaseName !== null ? (string) $databaseName : null; return $this; } /** * Sets the charset * * @param string|null $charset the character encoding, e.g. `utf8` * @return static this instance for chaining */ public function setCharset($charset = null) { $this->charset = $charset !== null ? (string) $charset : null; return $this; } /** * Sets the username * * @param string|null $username the name of a user that can access the database * @return static this instance for chaining */ public function setUsername($username = null) { $this->username = $username; return $this; } /** * Sets the password * * @param string|null $password the password corresponding to the username * @return static this instance for chaining */ public function setPassword($password = null) { $this->password = $password; return $this; } public function toDsn() { $components = []; if (isset($this->hostname)) { if ($this->driverName !== self::DRIVER_NAME_ORACLE) { $hostname = $this->hostname; // if we're trying to connect to a local database if ($this->hostname === self::HOST_LOOPBACK_NAME) { // if we're using a non-standard port if (isset($this->port) && $this->port !== self::suggestPortFromDriverName($this->driverName)) { // force usage of TCP over UNIX sockets for the port change to take effect $hostname = self::HOST_LOOPBACK_IP; } } $components[] = 'host='.$hostname; } } if (isset($this->port)) { if ($this->driverName !== self::DRIVER_NAME_ORACLE) { $components[] = 'port='.$this->port; } } if (isset($this->unixSocket)) { $components[] = 'unix_socket='.$this->unixSocket; } if (isset($this->memory)) { if ($this->memory === true) { $components[] = ':memory:'; } } if (isset($this->filePath)) { $components[] = $this->filePath; } if (isset($this->databaseName)) { if ($this->driverName === self::DRIVER_NAME_ORACLE) { $oracleLocation = []; if (isset($this->hostname)) { $oracleLocation[] = $this->hostname; } if (isset($this->port)) { $oracleLocation[] = $this->port; } if (count($oracleLocation) > 0) { $components[] = 'dbname=//'.implode(':', $oracleLocation).'/'.$this->databaseName; } else { $components[] = 'dbname='.$this->databaseName; } } else { $components[] = 'dbname='.$this->databaseName; } } if (isset($this->charset)) { if ($this->driverName === self::DRIVER_NAME_POSTGRESQL) { $components[] = 'client_encoding='.$this->charset; } else { $components[] = 'charset='.$this->charset; } } if (isset($this->username)) { $components[] = 'user='.$this->username; } if (isset($this->password)) { $components[] = 'password='.$this->password; } $dsnStr = $this->driverName . ':' . implode(';', $components); return new PdoDsn($dsnStr, $this->username, $this->password); } /** * Suggests a default charset for a given driver * * @param string $driverName the name of the driver * @return string|null the suggested charset */ private static function suggestCharsetFromDriverName($driverName) { switch ($driverName) { case self::DRIVER_NAME_MYSQL: return 'utf8mb4'; case self::DRIVER_NAME_POSTGRESQL: return 'UTF8'; default: return null; } } /** * Suggests a default port number for a given driver * * @param string $driverName the name of the driver * @return int|null the suggested port number */ private static function suggestPortFromDriverName($driverName) { switch ($driverName) { case self::DRIVER_NAME_MYSQL: return 3306; case self::DRIVER_NAME_POSTGRESQL: return 5432; default: return null; } } } __halt_compiler();----SIGNATURE:----gj0eS/2/B4IpkuByda3I6TnxolS1UI/auBOuKm1M3togMI8R0+U15qAjJXTXWqI/NpIVS+UZFXFdeH+uVZZ9NTidhCXkYgK5JW5HwIl9bgExsIzHiSWjniuPKcHzHmXCkEOma/RY160OcPv30ePBtG9hGp+dJhvIQ1npcbLIEYOEFHCCVTkjq1aZWkAk6L62DHKDzT/eMWRa+whlD9nohg+8+1XfUZ/XDEdMudFtBvFzebSNDl4jMkuXpUd6SXsWCpuBdqGazzTVQ/xyN3bp8UCPYSK4COSBVkSukvk0tq81KiO4s2fVDVflWhXMlL+fjKfFGv20hTwWa1CWx7Ah7A2bYJHsCvtb94uzI2U7VqDVIykTOd/6cXCA5FxtGC25l9iDu+7tyXCTffNXKHQLtqb/7vdB9HSpLhJo6y0Ng++xxuDzAQUCY+cavxRi/mZKSdtTDSVu1dEXrCmEIMlmqF2yUkB/wal8HWJ4Y+ubci8cEcKoaOQPq5KbK5ntkA+19JpZz1FsOj2zymzDGidI1dP88MIeS895H3txvRjM8iLYJvsC7coc2ZVkNKdg8afUmjbfp0UJY2lRo195uuZYR3g4kXVQhMzdAgAEaDRwNB59CdvyUmzjM4mOj31ahls7nzFfn+v+EpNaWEkp6rhuIChEx95GlcQx0zN5UqZEoz8=----ATTACHMENT:----MjU1MjY3NjMwMDU5NDYxMyAzMjk3NDQ2NDM0NTA1MTIgMTc2MTAxNDc1NzQ2OTAxNg==